Skip to content

Commit

Permalink
Remove labels layer name from segmentation selector when it is delete…
Browse files Browse the repository at this point in the history
…d in the viewer
  • Loading branch information
p-j-smith committed Jul 27, 2023
1 parent bf81133 commit eedf09c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions btrack/napari/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def create_btrack_widget() -> QtWidgets.QWidget:
),
)

btrack_widget.viewer.layers.events.removed.connect(
lambda event: remove_deleted_labels(
deleted_layer=event.value,
combobox=btrack_widget.segmentation,
),
)

btrack_widget.config.currentTextChanged.connect(
lambda selected: select_config(btrack_widget, all_configs, selected),
)
Expand Down Expand Up @@ -165,6 +172,25 @@ def update_labels_name(
combobox.setItemText(layer_index, layer.name)


def remove_deleted_labels(
deleted_layer: napari.layers.Layer,
combobox: QtWidgets.QComboBox,
):
"""Remove the deleted Labels layer name from the combobox"""

if not isinstance(deleted_layer, napari.layers.Labels):
message = (
f"Not deleting layer {deleted_layer.name} from the segmentation "
f"widget as {deleted_layer.name} is {type(deleted_layer)} "
"layer not an Labels layer."
)
logger.debug(message)
return

layer_index = combobox.findText(deleted_layer.name)
combobox.removeItem(layer_index)


def select_config(
btrack_widget: QtWidgets.QWidget,
configs: TrackerConfigs,
Expand Down

0 comments on commit eedf09c

Please sign in to comment.