@@ -108,6 +108,12 @@ class NapariMPLWidget(MPLWidget):
108
108
is changed in the napari viewer. To take advantage of this sub-classes
109
109
should implement the ``clear()`` and ``draw()`` methods.
110
110
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
+
111
117
Attributes
112
118
----------
113
119
viewer : `napari.Viewer`
@@ -157,14 +163,16 @@ def _setup_callbacks(self) -> None:
157
163
# z-step changed in viewer
158
164
self .viewer .dims .events .current_step .connect (self ._draw )
159
165
# 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
+ )
161
169
162
- def update_layers (self , event : napari .utils .events .Event ) -> None :
170
+ def _update_layers (self , event : napari .utils .events .Event ) -> None :
163
171
"""
164
172
Update the ``layers`` attribute with currently selected layers and re-draw.
165
173
"""
166
174
self .layers = list (self .viewer .layers .selection )
167
- self ._on_update_layers ()
175
+ self .on_update_layers ()
168
176
self ._draw ()
169
177
170
178
def _draw (self ) -> None :
@@ -193,10 +201,9 @@ def draw(self) -> None:
193
201
This is a no-op, and is intended for derived classes to override.
194
202
"""
195
203
196
- def _on_update_layers (self ) -> None :
204
+ def on_update_layers (self ) -> None :
197
205
"""
198
- Function is called when self.layers is updated via
199
- ``self.update_layers()``.
206
+ Called when the selected layers are updated.
200
207
201
208
This is a no-op, and is intended for derived classes to override.
202
209
"""
0 commit comments