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 edef35c

Browse filesBrowse files
committed
Clean up layer selection API
1 parent 20bc846 commit edef35c
Copy full SHA for edef35c

File tree

5 files changed

+20
-10
lines changed
Filter options

5 files changed

+20
-10
lines changed

‎docs/changelog.rst

Copy file name to clipboardExpand all lines: docs/changelog.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Changes
2323
you would be interested in please open an issue at https://github.com/matplotlib/napari-matplotlib.
2424
- Labels plotting with the features scatter widget no longer have underscores
2525
replaced with spaces.
26+
- ``NapariMPLWidget.update_layers()`` has been removed as it is intended to be
27+
private API. Use `NapariMPLWidget.on_update_layers` instead to implement
28+
funcitonality when layer selection is changed.
2629

2730
Bug fixes
2831
~~~~~~~~~

‎src/napari_matplotlib/base.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/base.py
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class NapariMPLWidget(MPLWidget):
108108
is changed in the napari viewer. To take advantage of this sub-classes
109109
should implement the ``clear()`` and ``draw()`` methods.
110110
111+
When both the z-step and layer selection is changed, ``clear()`` is called
112+
and if the number a type of selected layers are valid for the widget
113+
``draw()`` is then called. When layer selection is changed ``on_update_layers()``
114+
is also called, which can be useful e.g. for updating a layer list in a
115+
selection widget.
116+
111117
Attributes
112118
----------
113119
viewer : `napari.Viewer`
@@ -157,14 +163,16 @@ def _setup_callbacks(self) -> None:
157163
# z-step changed in viewer
158164
self.viewer.dims.events.current_step.connect(self._draw)
159165
# Layer selection changed in viewer
160-
self.viewer.layers.selection.events.changed.connect(self.update_layers)
166+
self.viewer.layers.selection.events.changed.connect(
167+
self._update_layers
168+
)
161169

162-
def update_layers(self, event: napari.utils.events.Event) -> None:
170+
def _update_layers(self, event: napari.utils.events.Event) -> None:
163171
"""
164172
Update the ``layers`` attribute with currently selected layers and re-draw.
165173
"""
166174
self.layers = list(self.viewer.layers.selection)
167-
self._on_update_layers()
175+
self.on_update_layers()
168176
self._draw()
169177

170178
def _draw(self) -> None:
@@ -193,10 +201,9 @@ def draw(self) -> None:
193201
This is a no-op, and is intended for derived classes to override.
194202
"""
195203

196-
def _on_update_layers(self) -> None:
204+
def on_update_layers(self) -> None:
197205
"""
198-
Function is called when self.layers is updated via
199-
``self.update_layers()``.
206+
Called when the selected layers are updated.
200207
201208
This is a no-op, and is intended for derived classes to override.
202209
"""

‎src/napari_matplotlib/histogram.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/histogram.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
):
2828
super().__init__(napari_viewer, parent=parent)
2929
self.add_single_axes()
30-
self.update_layers(None)
30+
self._update_layers(None)
3131

3232
def clear(self) -> None:
3333
"""

‎src/napari_matplotlib/scatter.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/scatter.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(
132132
self.layout().addWidget(QLabel(f"{dim}-axis:"))
133133
self.layout().addWidget(self._selectors[dim])
134134

135-
self.update_layers(None)
135+
self._update_layers(None)
136136

137137
@property
138138
def x_axis_key(self) -> Union[str, None]:
@@ -230,7 +230,7 @@ def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]:
230230

231231
return x, y, x_axis_name, y_axis_name
232232

233-
def _on_update_layers(self) -> None:
233+
def on_update_layers(self) -> None:
234234
"""
235235
Called when the layer selection changes by ``self.update_layers()``.
236236
"""

‎src/napari_matplotlib/slice.py

Copy file name to clipboardExpand all lines: src/napari_matplotlib/slice.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
for d in _dims_sel:
5252
self.slice_selectors[d].textChanged.connect(self._draw)
5353

54-
self.update_layers(None)
54+
self._update_layers(None)
5555

5656
@property
5757
def _layer(self) -> napari.layers.Layer:

0 commit comments

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