Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e742e3b

Browse filesBrowse files
authored
Merge pull request #139 from dstansby/explain-widgets
Add some explanation text to top of widgets
2 parents 7bf5db1 + a01a85d commit e742e3b
Copy full SHA for e742e3b

File tree

4 files changed

+57
-5
lines changed
Filter options

4 files changed

+57
-5
lines changed

‎docs/changelog.rst

Copy file name to clipboardExpand all lines: docs/changelog.rst
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ New features
88
~~~~~~~~~~~~
99
- Added ``MPLWidget`` as a widget containing just a Matplotlib canvas
1010
without any association with a napari viewer.
11+
- Added text to each widget indicating how many layers need to be selected
12+
for the widget to plot something.
1113

1214
Visual improvements
1315
~~~~~~~~~~~~~~~~~~~

‎src/napari_matplotlib/base.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/base.py
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111
from matplotlib.figure import Figure
1212
from qtpy.QtGui import QIcon
13-
from qtpy.QtWidgets import QVBoxLayout, QWidget
13+
from qtpy.QtWidgets import QLabel, QVBoxLayout, QWidget
1414

1515
from .util import Interval, from_napari_css_get_size_of
1616

@@ -178,6 +178,11 @@ class NapariMPLWidget(BaseNapariMPLWidget):
178178
for creating and working with the Matplotlib figure and any axes.
179179
"""
180180

181+
#: Number of layers taken as input
182+
n_layers_input = Interval(None, None)
183+
#: Type of layer taken as input
184+
input_layer_types: Tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
185+
181186
def __init__(
182187
self,
183188
napari_viewer: napari.viewer.Viewer,
@@ -187,10 +192,9 @@ def __init__(
187192
self._setup_callbacks()
188193
self.layers: List[napari.layers.Layer] = []
189194

190-
#: Number of layers taken as input
191-
n_layers_input = Interval(None, None)
192-
#: Type of layer taken as input
193-
input_layer_types: Tuple[napari.layers.Layer, ...] = (napari.layers.Layer,)
195+
helper_text = self.n_layers_input._helper_text
196+
if helper_text is not None:
197+
self.layout().insertWidget(0, QLabel(helper_text))
194198

195199
@property
196200
def n_selected_layers(self) -> int:

‎src/napari_matplotlib/tests/test_util.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/tests/test_util.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ def test_interval():
1616
"string" in interval # type: ignore
1717

1818

19+
@pytest.mark.parametrize(
20+
"lower, upper, text",
21+
[
22+
(None, None, None),
23+
(1, None, "Select at least 1 layer to generate plot"),
24+
(4, None, "Select at least 4 layers to generate plot"),
25+
(None, 1, "Select at most 1 layer to generate plot"),
26+
(None, 5939, "Select at most 5939 layers to generate plot"),
27+
(1, 1, "Select 1 layer to generate plot"),
28+
(2, 2, "Select 2 layers to generate plot"),
29+
(1, 2, "Select between 1 and 2 layers to generate plot"),
30+
],
31+
)
32+
def test_interval_helper_text(lower, upper, text):
33+
assert Interval(lower, upper)._helper_text == text
34+
35+
1936
def test_get_size_from_css(mocker):
2037
"""Test getting the max-width and max-height from something in css"""
2138
test_css = """

‎src/napari_matplotlib/util.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/util.py
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@ def __contains__(self, val: int) -> bool:
4646
return False
4747
return True
4848

49+
@property
50+
def _helper_text(self) -> Optional[str]:
51+
"""
52+
Helper text for widgets.
53+
"""
54+
if self.lower is None and self.upper is None:
55+
helper_text = None
56+
elif self.lower is not None and self.upper is None:
57+
helper_text = (
58+
f"Select at least {self.lower} layers to generate plot"
59+
)
60+
elif self.lower is None and self.upper is not None:
61+
helper_text = (
62+
f"Select at most {self.upper} layers to generate plot"
63+
)
64+
elif self.lower == self.upper:
65+
helper_text = f"Select {self.lower} layers to generate plot"
66+
67+
else:
68+
helper_text = (
69+
f"Select between {self.lower} and "
70+
f"{self.upper} layers to generate plot"
71+
)
72+
73+
if helper_text is not None:
74+
helper_text = helper_text.replace("1 layers", "1 layer")
75+
76+
return helper_text
77+
4978

5079
def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
5180
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.