From eedf09cd42a021d0e66cf3e2e007e731896f2104 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Thu, 27 Jul 2023 16:16:29 +0100 Subject: [PATCH] Remove labels layer name from segmentation selector when it is deleted in the viewer --- btrack/napari/main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/btrack/napari/main.py b/btrack/napari/main.py index c3702b83..f4285dcc 100644 --- a/btrack/napari/main.py +++ b/btrack/napari/main.py @@ -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), ) @@ -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,