Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/cali/gui/_cali_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ def __init__(
self._fov_table.doubleClicked.connect(self._on_fov_double_click)

self._runs_panel.runSelected.connect(self._on_run_item_selected)
self._runs_panel.segmentationSelected.connect(
self._on_saved_segmentation_selected
)
self._runs_panel.settingsDeleted.connect(self._on_settings_deleted)

# connect the roiSelected signal from the graphs to the image viewer so we can
Expand Down Expand Up @@ -994,7 +997,7 @@ def _update_gui_settings(
self._runs_panel._runs_list.setCurrentRow(0)
# emit runSelected signal for the first run
if (first_item := self._runs_panel._runs_list.item(0)) is not None:
self._runs_panel._on_item_clicked(first_item)
self._runs_panel._on_run_item_clicked(first_item)
# load plate plan data
if experiment is None:
experiment = Experiment.load_from_database(database_path, load_data=False)
Expand Down Expand Up @@ -2420,6 +2423,52 @@ def _on_run_item_selected(self, run_id: int) -> None:
show_error_dialog(self, f"Failed to load run settings: {e}")
cali_logger.error(f"❌ Failed to load run #{run_id}: {e}")

def _on_saved_segmentation_selected(self, detection_settings_id: int) -> None:
"""Handle selection of an orphan (saved) segmentation in the runs panel.

Loads the detection parameters into the detection widget and refreshes
the image viewer so the labels reflect this segmentation.
"""
if self._database_path is None:
return

try:
d_settings = DetectionSettings.load_from_database(
self._database_path, id=detection_settings_id
)
if not isinstance(d_settings, DetectionSettings): # pragma: no cover
raise TypeError(f"Expected DetectionSettings, got {type(d_settings)}")
if d_settings.method == "cellpose":
self._detection_wdg.setValue(
CellposeSettingsData(
model_type=d_settings.model_type,
model_path=d_settings.custom_model,
diameter=d_settings.diameter,
cellprob_threshold=d_settings.cellprob_threshold,
flow_threshold=d_settings.flow_threshold,
min_size=d_settings.min_size,
normalize=d_settings.normalize,
batch_size=d_settings.batch_size,
use_gpu=d_settings.use_gpu,
)
)
elif d_settings.method == "imported_labels": # pragma: no cover
self._detection_wdg.setValue(method="imported_labels")
self._detection_wdg._imported_labels_wdg.set_detection_settings_id(
d_settings.id
)

cali_logger.info(f"✅ Selected saved segmentation #{detection_settings_id}")

# Refresh the image viewer to show the segmentation labels
self._on_fov_table_selection_changed()

except Exception as e:
show_error_dialog(self, f"Failed to load saved segmentation: {e}")
cali_logger.error(
f"❌ Failed to load saved segmentation #{detection_settings_id}: {e}"
)

def _set_splitter_sizes(self) -> None:
"""Set the initial sizes for the splitters."""
splitter_and_sizes = (
Expand Down
Loading
Loading