File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 1
1
Changelog
2
2
=========
3
3
4
+ 2.0.3
5
+ -----
6
+ Bug fixes
7
+ ~~~~~~~~~
8
+ - Fix an error that happened when the histogram widget was open, but a layer that doesn't support
9
+ histogramming (e.g., a labels layer) was selected.
10
+
4
11
2.0.2
5
12
-----
6
13
Dependencies
Original file line number Diff line number Diff line change @@ -224,14 +224,24 @@ def _setup_callbacks(self) -> None:
224
224
self._update_layers
225
225
)
226
226
227
+ @property
228
+ def _valid_layer_selection(self) -> bool:
229
+ """
230
+ Return `True` if layer selection is valid.
231
+ """
232
+ return self.n_selected_layers in self.n_layers_input and all(
233
+ isinstance(layer, self.input_layer_types) for layer in self.layers
234
+ )
235
+
227
236
def _update_layers(self, event: napari.utils.events.Event) -> None:
228
237
"""
229
238
Update the ``layers`` attribute with currently selected layers and re-draw.
230
239
"""
231
240
self.layers = list(self.viewer.layers.selection)
232
241
self.layers = sorted(self.layers, key=lambda layer: layer.name)
233
242
self.on_update_layers()
234
- self._draw()
243
+ if self._valid_layer_selection:
244
+ self._draw()
235
245
236
246
def _draw(self) -> None:
237
247
"""
@@ -243,10 +253,7 @@ def _draw(self) -> None:
243
253
with mplstyle.context(self.napari_theme_style_sheet):
244
254
# everything should be done in the style context
245
255
self.clear()
246
- if self.n_selected_layers in self.n_layers_input and all(
247
- isinstance(layer, self.input_layer_types)
248
- for layer in self.layers
249
- ):
256
+ if self._valid_layer_selection:
250
257
self.draw()
251
258
self.canvas.draw() # type: ignore[no-untyped-call]
252
259
Original file line number Diff line number Diff line change @@ -55,8 +55,10 @@ def on_update_layers(self) -> None:
55
55
Called when the selected layers are updated.
56
56
"""
57
57
super().on_update_layers()
58
- for layer in self.viewer.layers:
59
- layer.events.contrast_limits.connect(self._update_contrast_lims)
58
+ if self._valid_layer_selection:
59
+ self.layers[0].events.contrast_limits.connect(
60
+ self._update_contrast_lims
61
+ )
60
62
61
63
def _update_contrast_lims(self) -> None:
62
64
for lim, line in zip(
@@ -209,10 +211,12 @@ def draw(self) -> None:
209
211
# get the colormap from the layer depending on its type
210
212
if isinstance(self.layers[0], napari.layers.Points):
211
213
colormap = self.layers[0].face_colormap
212
- self.layers[0].face_color = self.x_axis_key
214
+ if self.x_axis_key:
215
+ self.layers[0].face_color = self.x_axis_key
213
216
elif isinstance(self.layers[0], napari.layers.Vectors):
214
217
colormap = self.layers[0].edge_colormap
215
- self.layers[0].edge_color = self.x_axis_key
218
+ if self.x_axis_key:
219
+ self.layers[0].edge_color = self.x_axis_key
216
220
else:
217
221
colormap = None
218
222
You can’t perform that action at this time.
0 commit comments