Skip to content

Commit d0b565e

Browse files
committed
Clean up layer selection API
1 parent 51b6b03 commit d0b565e

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Changes
1818
you would be interested in please open an issue at https://github.com/matplotlib/napari-matplotlib.
1919
- Labels plotting with the features scatter widget no longer have underscores
2020
replaced with spaces.
21+
- ``NapariMPLWidget.update_layers()`` has been removed as it is intended to be
22+
private API. Use `NapariMPLWidget.on_update_layers` instead to implement
23+
funcitonality when layer selection is changed.
2124

2225
Bug fixes
2326
~~~~~~~~~

src/napari_matplotlib/base.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class NapariMPLWidget(QWidget):
3434
advantage of this sub-classes should implement the ``clear()`` and
3535
``draw()`` methods.
3636
37+
When both the z-step and layer selection is changed, ``clear()`` is called
38+
and if the number a type of selected layers are valid for the widget
39+
``draw()`` is then called. When layer selection is changed ``on_update_layers()``
40+
is also called, which can be useful e.g. for updating a layer list in a
41+
selection widget.
42+
3743
Attributes
3844
----------
3945
viewer : `napari.Viewer`
@@ -105,12 +111,12 @@ def _setup_callbacks(self) -> None:
105111
# Layer selection changed in viewer
106112
self.viewer.layers.selection.events.changed.connect(self.update_layers)
107113

108-
def update_layers(self, event: napari.utils.events.Event) -> None:
114+
def _update_layers(self, event: napari.utils.events.Event) -> None:
109115
"""
110116
Update the ``layers`` attribute with currently selected layers and re-draw.
111117
"""
112118
self.layers = list(self.viewer.layers.selection)
113-
self._on_update_layers()
119+
self.on_update_layers()
114120
self._draw()
115121

116122
def _draw(self) -> None:
@@ -165,10 +171,9 @@ def apply_napari_colorscheme(ax: Axes) -> None:
165171
ax.tick_params(axis="x", colors="white")
166172
ax.tick_params(axis="y", colors="white")
167173

168-
def _on_update_layers(self) -> None:
174+
def on_update_layers(self) -> None:
169175
"""
170-
Function is called when self.layers is updated via
171-
``self.update_layers()``.
176+
Called when the selected layers are updated.
172177
173178
This is a no-op, and is intended for derived classes to override.
174179
"""

src/napari_matplotlib/histogram.py

Lines 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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy