Skip to content

Commit

Permalink
Add callback to Labels layers to update name in segmentation selctor
Browse files Browse the repository at this point in the history
  • Loading branch information
p-j-smith committed Jul 27, 2023
1 parent 195e743 commit bf81133
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions btrack/napari/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,40 @@ def select_inserted_labels(
combobox.addItem(new_layer.name)
combobox.setCurrentText(new_layer.name)

# Update layer name when it changes
viewer = napari.current_viewer()
new_layer.events.name.connect(
lambda event: update_labels_name(
layer=event.source,
labels_layers=[
layer
for layer in viewer.layers
if isinstance(layer, napari.layers.Labels)
],
combobox=combobox,
),
)


# TODO: automatically update layer name in QComboBox when it is changed in the viewer
def update_image_name(
def update_labels_name(
layer: napari.layers.Layer,
new_name: str,
widget: QtWidgets.QComboBox,
labels_layers: list[napari.layer.Layer],
combobox: QtWidgets.QComboBox,
):
"""Update the name of an Labels layer"""

if not isinstance(layer, napari.layers.Labels):
message = (
f"Not selecting new layer {layer.name} as input for the "
f"Not updating name of layer {layer.name} as input for the "
f"segmentation widget as {layer.name} is {type(layer)} "
"layer not an Image layer."
"layer not a Labels layer."
)
logger.debug(message)
return

layer_index = [layer.name for layer in labels_layers].index(layer.name)
combobox.setItemText(layer_index, layer.name)


def select_config(
btrack_widget: QtWidgets.QWidget,
Expand Down

0 comments on commit bf81133

Please sign in to comment.