Skip to content

Commit b4abec3

Browse files
committed
Merge remote-tracking branch 'origin/feature/337-command-palette-quick-command-launcher' into feature/337-command-palette-quick-command-launcher
# Conflicts: # datalab/locale/fr/LC_MESSAGES/datalab.po
2 parents b6a4f3d + 9290413 commit b4abec3

5 files changed

Lines changed: 416 additions & 1 deletion

File tree

datalab/adapters_metadata/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def append(self, adapter: BaseResultAdapter, obj: SignalObj | ImageObj) -> None:
109109
if "roi_index" in df.columns:
110110
i_roi = int(df.iloc[i_row_res]["roi_index"])
111111
roititle = ""
112-
if i_roi >= 0 and obj.roi is not None:
112+
if i_roi >= 0 and obj.roi is not None and i_roi < len(obj.roi):
113113
roititle = obj.roi.get_single_roi_title(i_roi)
114114
ylabel += f"|{roititle}"
115115
self.ylabels.append(ylabel)

datalab/gui/processor/base.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,30 @@ def register_computations(self) -> None:
792792
self.register_processing()
793793
self.register_analysis()
794794

795+
# pylint: disable=unused-argument
796+
def preprocess_1_to_0(
797+
self,
798+
func: Callable,
799+
param: gds.DataSet | None,
800+
objs: list[SignalObj | ImageObj],
801+
) -> bool:
802+
"""Pre-check hook for 1-to-0 operations (hook method).
803+
804+
This method is called before a 1-to-0 computation starts, before the
805+
progress dialog is opened. Subclasses can override this method to perform
806+
pre-checks or ask for user confirmation. Return ``False`` to abort the
807+
computation.
808+
809+
Args:
810+
func: The computation function that will be called
811+
param: Optional parameter set
812+
objs: List of objects that will be processed
813+
814+
Returns:
815+
True to proceed with the computation, False to abort
816+
"""
817+
return True
818+
795819
# pylint: disable=unused-argument
796820
def postprocess_1_to_0_result(
797821
self, obj: SignalObj | ImageObj, result: GeometryResult | TableResult
@@ -989,6 +1013,13 @@ def auto_recompute_analysis(
9891013
# Get the parameter from processing parameters
9901014
param = proc_params.param
9911015

1016+
# Disable ROI creation during auto-recompute: detection functions store
1017+
# create_rois=True in their parameters, but auto-recompute should only
1018+
# update analysis results, not recreate ROIs (which would make them
1019+
# impossible to delete or modify).
1020+
if hasattr(param, "create_rois"):
1021+
param.create_rois = False
1022+
9921023
# Get the actual function from the function name
9931024
feature = self.get_feature(proc_params.func_name)
9941025

@@ -1394,6 +1425,8 @@ def compute_1_to_0(
13941425
if target_objs is not None
13951426
else self.panel.objview.get_sel_objects(include_groups=True)
13961427
)
1428+
if not self.preprocess_1_to_0(func, param, objs):
1429+
return None
13971430
current_obj = self.panel.objview.get_current_object()
13981431
title = func.__name__ if title is None else title
13991432
refresh_needed = False

datalab/gui/processor/image.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import guidata.dataset as gds
1112
import numpy as np
1213
import sigima.params
1314
import sigima.proc.base as sipb
@@ -25,6 +26,7 @@
2526
)
2627
from sigima.objects.scalar import GeometryResult, TableResult
2728

29+
from datalab import env
2830
from datalab.config import APP_NAME, _
2931
from datalab.gui.processor.base import BaseProcessor
3032
from datalab.gui.processor.geometry_postprocess import (
@@ -58,6 +60,50 @@ def _wrap_geometric_transform(self, func, operation: str):
5860
"""
5961
return GeometricTransformWrapper(func, operation)
6062

63+
def preprocess_1_to_0(
64+
self,
65+
func,
66+
param: gds.DataSet | None,
67+
objs: list[ImageObj],
68+
) -> bool:
69+
"""Override to confirm ROI replacement before the progress bar opens.
70+
71+
When the parameter has ``create_rois=True`` and at least one selected
72+
image already has ROIs, the user is warned that the existing ROIs will
73+
be replaced.
74+
75+
Args:
76+
func: The computation function that will be called
77+
param: Optional parameter set
78+
objs: List of image objects that will be processed
79+
80+
Returns:
81+
True to proceed with the computation, False to abort
82+
"""
83+
if (
84+
param is not None
85+
and getattr(param, "create_rois", False)
86+
and not env.execenv.unattended
87+
and any(obj.roi is not None and not obj.roi.is_empty() for obj in objs)
88+
):
89+
return (
90+
QW.QMessageBox.question(
91+
self.mainwindow,
92+
_("Warning"),
93+
_(
94+
"Regions of interest are already defined for this "
95+
"image.<br><br>"
96+
"Creating new ROIs from detection will replace the "
97+
"existing ones, which will be lost.<br><br>"
98+
"Do you want to continue?"
99+
),
100+
QW.QMessageBox.Yes | QW.QMessageBox.No,
101+
QW.QMessageBox.No,
102+
)
103+
== QW.QMessageBox.Yes
104+
)
105+
return True
106+
61107
def postprocess_1_to_0_result(
62108
self, obj: ImageObj, result: GeometryResult | TableResult
63109
) -> bool:

datalab/locale/fr/LC_MESSAGES/datalab.po

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,9 @@ msgstr "En mode 'pairwise', vous devez sélectionner des objets dans au moins de
20502050
msgid "In pairwise mode, you need to select the same number of objects in each group."
20512051
msgstr "En mode 'pairwise', vous devez sélectionner le même nombre d'objets dans chaque groupe."
20522052

2053+
msgid "Parameters"
2054+
msgstr "Paramètres"
2055+
20532056
#, python-format
20542057
msgid "Calculating: %s"
20552058
msgstr "Calcul : %s"
@@ -2081,6 +2084,9 @@ msgstr "Supprimer la ROI"
20812084
msgid "Are you sure you want to remove ROI '%s'?"
20822085
msgstr "Êtes-vous sûr de vouloir supprimer la ROI '%s' ?"
20832086

2087+
msgid "Regions of interest are already defined for this image.<br><br>Creating new ROIs from detection will replace the existing ones, which will be lost.<br><br>Do you want to continue?"
2088+
msgstr "Des régions d'intérêt sont déjà définies pour cette image.<br><br>La création de nouvelles ROI par détection remplacera les existantes, qui seront perdues.<br><br>Voulez-vous continuer ?"
2089+
20842090
msgid "Sum"
20852091
msgstr "Addition"
20862092

@@ -4089,6 +4095,9 @@ msgstr "Tout sélectionner"
40894095
msgid "Adding data to the plot"
40904096
msgstr "Ajout des données au graphique"
40914097

4098+
msgid "Title"
4099+
msgstr "Titre"
4100+
40924101
msgid "X label"
40934102
msgstr "Titre X"
40944103

@@ -4241,3 +4250,4 @@ msgstr "Aucun contour n'a été trouvé pour la plage de niveaux sélectionnée.
42414250

42424251
msgid "Show contour plot..."
42434252
msgstr "Afficher le tracé de contours..."
4253+

0 commit comments

Comments
 (0)