Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit1518fd0

Browse files
committed
Only update layers when selection is valid
1 parentdc326e7 commit1518fd0

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎docs/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
Changelog
22
=========
3+
4+
2.0.2
5+
-----
6+
Bug fixes
7+
~~~~~~~~~
8+
- Only trigger layer update code paths if the layer selection is valid for the current
9+
widget. This prevents errors when e.g., a labels layer is selected when a widget
10+
that does not support a labels layer is open.
11+
312
2.0.1
413
-----
514
Bug fixes

‎src/napari_matplotlib/base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,23 @@ def _setup_callbacks(self) -> None:
225225
self._update_layers
226226
)
227227

228+
@property
229+
def_valid_layer_selection(self)->bool:
230+
"""
231+
Return `True` if layer selection is valid.
232+
"""
233+
returnself.n_selected_layersinself.n_layers_inputandall(
234+
isinstance(layer,self.input_layer_types)forlayerinself.layers
235+
)
236+
228237
def_update_layers(self,event:napari.utils.events.Event)->None:
229238
"""
230239
Update the ``layers`` attribute with currently selected layers and re-draw.
231240
"""
232241
self.layers=list(self.viewer.layers.selection)
233242
self.layers=sorted(self.layers,key=lambdalayer:layer.name)
234-
self.on_update_layers()
243+
ifself._valid_layer_selection:
244+
self.on_update_layers()
235245
self._draw()
236246

237247
def_draw(self)->None:
@@ -244,10 +254,7 @@ def _draw(self) -> None:
244254
withmplstyle.context(self.napari_theme_style_sheet):
245255
# everything should be done in the style context
246256
self.clear()
247-
ifself.n_selected_layersinself.n_layers_inputandall(
248-
isinstance(layer,self.input_layer_types)
249-
forlayerinself.layers
250-
):
257+
ifself._valid_layer_selection:
251258
self.draw()
252259
self.canvas.draw()# type: ignore[no-untyped-call]
253260

@@ -270,6 +277,7 @@ def on_update_layers(self) -> None:
270277
Called when the selected layers are updated.
271278
272279
This is a no-op, and is intended for derived classes to override.
280+
It is only called if a selected layer is one of the input layer types.
273281
"""
274282

275283

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp