Skip to content

Commit 4e45807

Browse files
committed
Fix: initialize singleobj in BaseROIEditor and BaseROI classes
(remove one `cdl.config.Conf` usage in `sigima_`)
1 parent d59f7ea commit 4e45807

3 files changed

Lines changed: 45 additions & 8 deletions

File tree

cdl/gui/processor/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,9 @@ def edit_regions_of_interest(self, extract: bool = False) -> TypeROI | None:
13611361
for obj_i in objs:
13621362
obj_i.roi = None
13631363
else:
1364-
edited_roi = edited_roi.from_params(obj, params)
1364+
edited_roi = edited_roi.__class__.from_params(
1365+
obj, params, singleobj=edited_roi.singleobj
1366+
)
13651367
if not extract:
13661368
for obj_i in objs:
13671369
obj_i.roi = edited_roi

cdl/gui/roieditor.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,16 @@ class BaseROIEditor(
221221
Generic[TypeObj, TypeROI, TypePlotItem, TypeROIItem], # type: ignore
222222
metaclass=BaseROIEditorMeta,
223223
):
224-
"""ROI Editor"""
224+
"""ROI Editor
225+
226+
Args:
227+
parent: Parent plot dialog
228+
obj: Object to edit (:class:`sigima_.obj.SignalObj` or
229+
:class:`sigima_.obj.ImageObj`)
230+
extract: If True, the dialog is in "extract mode" (extracting ROIs)
231+
item: Optional plot item to add to the plot (if None, a new item is created
232+
from the object)
233+
"""
225234

226235
ICON_NAME = None
227236
OBJ_NAME = None
@@ -247,6 +256,8 @@ def __init__(
247256
roi = obj.roi
248257
if roi is None:
249258
roi = self.get_obj_roi_class()()
259+
if roi.singleobj is None:
260+
roi.singleobj = Conf.proc.extract_roi_singleobj.get()
250261
self.__roi: TypeROI = roi
251262

252263
fmt = create_adapter_from_object(obj).get_obj_option("format")
@@ -448,7 +459,16 @@ def get_text(self) -> str:
448459

449460

450461
class SignalROIEditor(BaseROIEditor[SignalObj, SignalROI, CurveItem, XRangeSelection]):
451-
"""Signal ROI Editor"""
462+
"""Signal ROI Editor
463+
464+
Args:
465+
parent: Parent plot dialog
466+
obj: Object to edit (:class:`sigima_.obj.SignalObj` or
467+
:class:`sigima_.obj.ImageObj`)
468+
extract: If True, the dialog is in "extract mode" (extracting ROIs)
469+
item: Optional plot item to add to the plot (if None, a new item is created
470+
from the object)
471+
"""
452472

453473
ICON_NAME = "signal_roi.svg"
454474
OBJ_NAME = _("signal")
@@ -508,7 +528,16 @@ class ImageROIEditor(
508528
Union[AnnotatedPolygon, AnnotatedRectangle, AnnotatedCircle],
509529
]
510530
):
511-
"""Image ROI Editor"""
531+
"""Image ROI Editor
532+
533+
Args:
534+
parent: Parent plot dialog
535+
obj: Object to edit (:class:`sigima_.obj.SignalObj` or
536+
:class:`sigima_.obj.ImageObj`)
537+
extract: If True, the dialog is in "extract mode" (extracting ROIs)
538+
item: Optional plot item to add to the plot (if None, a new item is created
539+
from the object)
540+
"""
512541

513542
ICON_NAME = "image_roi.svg"
514543
OBJ_NAME = _("image")

sigima_/obj/base.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import pandas as pd
2828
from numpy import ma
2929

30-
from cdl.config import Conf, _
30+
from cdl.config import _
3131
from sigima_.algorithms import coordinates
3232
from sigima_.algorithms.datatypes import is_integer_dtype
3333

@@ -1229,8 +1229,6 @@ class BaseROI(Generic[TypeObj, TypeSingleROI, TypeROIParam], abc.ABC): # type:
12291229

12301230
def __init__(self, singleobj: bool | None = None, inverse: bool = False) -> None:
12311231
self.single_rois: list[TypeSingleROI] = []
1232-
if singleobj is None:
1233-
singleobj = Conf.proc.extract_roi_singleobj.get()
12341232
self.singleobj = singleobj
12351233
self.inverse = inverse
12361234

@@ -1330,13 +1328,19 @@ def to_params(self, obj: TypeObj) -> list[TypeROIParam]:
13301328

13311329
@classmethod
13321330
def from_params(
1333-
cls: Type[BaseROI], obj: TypeObj, params: list[TypeROIParam]
1331+
cls: Type[BaseROI],
1332+
obj: TypeObj,
1333+
params: list[TypeROIParam],
1334+
singleobj: bool | None = None,
1335+
inverse: bool = False,
13341336
) -> BaseROI[TypeObj, TypeSingleROI, TypeROIParam]:
13351337
"""Create ROIs from parameters
13361338
13371339
Args:
13381340
obj: object (signal/image)
13391341
params: ROI parameters
1342+
singleobj: If True, extract all ROIs into a single object
1343+
inverse: If True, extract the inverse of the ROIs
13401344
13411345
Returns:
13421346
ROIs
@@ -1345,6 +1349,8 @@ def from_params(
13451349
for param in params:
13461350
assert isinstance(param, BaseROIParam), "Invalid ROI parameter type"
13471351
roi.add_roi(param.to_single_roi(obj))
1352+
roi.singleobj = singleobj
1353+
roi.inverse = inverse
13481354
return roi
13491355

13501356
def to_dict(self) -> dict:

0 commit comments

Comments
 (0)