Skip to content

Commit

Permalink
Use QElidingLabel instead of QLabel
Browse files Browse the repository at this point in the history
napari depends on superqt, so we are only adding a new dependency in
writing
  • Loading branch information
gselzer committed Dec 17, 2024
1 parent bb8e4f1 commit 3cace08
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- pandas
- pyimagej >= 1.4.1
- scyjava >= 1.8.1
- superqt >= 0.7.0
- xarray < 2024.10.0
# Version rules to avoid problems
- qtconsole != 5.4.2
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- pandas
- pyimagej >= 1.4.1
- scyjava >= 1.8.1
- superqt >= 0.7.0
- xarray < 2024.10.0
# Version rules to avoid problems
- qtconsole != 5.4.2
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = [
"pandas",
"pyimagej >= 1.4.1",
"scyjava >= 1.9.1",
"superqt >= 0.7.0",
"xarray < 2024.10.0",
# Version rules to avoid problems
"qtconsole != 5.4.2", # https://github.com/napari/napari/issues/5700
Expand Down
5 changes: 3 additions & 2 deletions src/napari_imagej/widgets/result_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from napari import Viewer
from qtpy.QtCore import Qt, Signal
from qtpy.QtWidgets import QApplication, QLabel, QPushButton, QVBoxLayout, QWidget
from qtpy.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget
from superqt import QElidingLabel

from napari_imagej.java import jc
from napari_imagej.widgets.layouts import QFlowLayout
Expand Down Expand Up @@ -46,7 +47,7 @@ def __init__(self, viewer: Viewer, output_signal: Signal):

self.setLayout(QVBoxLayout())

self.selected_module_label = QLabel()
self.selected_module_label = QElidingLabel()
self.layout().addWidget(self.selected_module_label)
self.button_pane = QWidget()
self.button_pane.setLayout(QFlowLayout())
Expand Down
24 changes: 22 additions & 2 deletions tests/widgets/test_result_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
A module testing napari_imagej.widgets.result_runner
"""

from __future__ import annotations

import pytest
from qtpy.QtWidgets import QLabel, QVBoxLayout, QWidget
from qtpy.QtWidgets import QVBoxLayout, QWidget
from scyjava import JavaClasses
from superqt import QElidingLabel

from napari_imagej.widgets.layouts import QFlowLayout
from napari_imagej.widgets.result_runner import ResultRunner
Expand Down Expand Up @@ -32,12 +35,29 @@ def test_result_runner(result_runner):
# The layout
assert isinstance(subwidgets[0], QVBoxLayout)
# The label describing the selected module
assert isinstance(subwidgets[1], QLabel)
assert isinstance(subwidgets[1], QElidingLabel)
# The button Container
assert isinstance(subwidgets[2], QWidget)
assert isinstance(subwidgets[2].layout(), QFlowLayout)


def test_result_runner_size_hints(result_runner: ResultRunner):
"""Ensuring the widget doesn't grow when text is set."""
# The problem we want to safeguard against here is ensuring the minimum
# size hint doesn't change - this is what causes issues like
# https://github.com/imagej/napari-imagej/issues/273

# Capture size hint
hint = result_runner.minimumSizeHint()
width_hint, height_hint = hint.width(), hint.height()
# Resize result_runner
result_runner._setText("o" * 50)
# Assert size hint did not change
hint = result_runner.minimumSizeHint()
assert width_hint == hint.width()
assert height_hint == hint.height()


@pytest.fixture
def example_info(ij):
return ij.module().getModuleById(
Expand Down

0 comments on commit 3cace08

Please sign in to comment.