@@ -34,6 +34,12 @@ class NapariMPLWidget(QWidget):
34
34
advantage of this sub-classes should implement the ``clear()`` and
35
35
``draw()`` methods.
36
36
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
+
37
43
Attributes
38
44
----------
39
45
viewer : `napari.Viewer`
@@ -103,14 +109,16 @@ def _setup_callbacks(self) -> None:
103
109
# z-step changed in viewer
104
110
self .viewer .dims .events .current_step .connect (self ._draw )
105
111
# Layer selection changed in viewer
106
- self .viewer .layers .selection .events .changed .connect (self .update_layers )
112
+ self .viewer .layers .selection .events .changed .connect (
113
+ self ._update_layers
114
+ )
107
115
108
- def update_layers (self , event : napari .utils .events .Event ) -> None :
116
+ def _update_layers (self , event : napari .utils .events .Event ) -> None :
109
117
"""
110
118
Update the ``layers`` attribute with currently selected layers and re-draw.
111
119
"""
112
120
self .layers = list (self .viewer .layers .selection )
113
- self ._on_update_layers ()
121
+ self .on_update_layers ()
114
122
self ._draw ()
115
123
116
124
def _draw (self ) -> None :
@@ -165,10 +173,9 @@ def apply_napari_colorscheme(ax: Axes) -> None:
165
173
ax .tick_params (axis = "x" , colors = "white" )
166
174
ax .tick_params (axis = "y" , colors = "white" )
167
175
168
- def _on_update_layers (self ) -> None :
176
+ def on_update_layers (self ) -> None :
169
177
"""
170
- Function is called when self.layers is updated via
171
- ``self.update_layers()``.
178
+ Called when the selected layers are updated.
172
179
173
180
This is a no-op, and is intended for derived classes to override.
174
181
"""
0 commit comments