Skip to content

Commit

Permalink
Add layer inserted event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallory Wittwer committed Aug 23, 2024
1 parent 85210a1 commit abe092d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/napari_label_focus/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,28 @@ def __init__(self, napari_viewer):
self.viewer.layers.selection.events.changed.connect(
self._on_layer_selection_changed
)
self.viewer.layers.events.inserted.connect(
lambda e: self._on_layer_selection_changed(None)
)
self._on_layer_selection_changed(None)

def _on_layer_selection_changed(self, event):
selected_layer = event.source.active
if not isinstance(selected_layer, napari.layers.Labels):
return
if event is None:
selected_layer = self.viewer.layers.selection.active
else:
selected_layer = event.source.active

if self.selected_labels_layer is not None:
self.selected_labels_layer.events.paint.disconnect(self.update_table_content)
self.selected_labels_layer.events.data.disconnect(self.update_table_content)
if selected_layer.data.ndim == 4:
if self.selected_labels_layer.data.ndim == 4:
self.viewer.dims.events.current_step.disconnect(self.handle_time_axis_changed)

selected_layer.events.data.connect(self.update_table_content)
selected_layer.events.paint.connect(self.update_table_content)
if selected_layer.data.ndim == 4:
self.viewer.dims.events.current_step.connect(self.handle_time_axis_changed)
if isinstance(selected_layer, napari.layers.Labels):
selected_layer.events.data.connect(self.update_table_content)
selected_layer.events.paint.connect(self.update_table_content)
if selected_layer.data.ndim == 4:
self.viewer.dims.events.current_step.connect(self.handle_time_axis_changed)

self.selected_labels_layer = selected_layer

Expand Down

0 comments on commit abe092d

Please sign in to comment.