Skip to content

Commit 76287c1

Browse files
committed
Refactor ROI editor dialog handling and update plot options retrieval
1 parent 88f860b commit 76287c1

File tree

8 files changed

+165
-134
lines changed

8 files changed

+165
-134
lines changed

datalab/gui/panel/base.py

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os.path as osp
1616
import re
1717
import warnings
18-
from typing import TYPE_CHECKING, Generic, Literal, Type
18+
from typing import TYPE_CHECKING, Any, Generic, Literal, Type
1919

2020
import guidata.dataset as gds
2121
import guidata.dataset.qtwidgets as gdq
@@ -289,7 +289,6 @@ class BaseDataPanel(AbstractPanel, Generic[TypeObj, TypeROI, TypeROIEditor]):
289289
SIG_REFRESH_PLOT = QC.Signal(
290290
str, bool, bool, bool, bool
291291
) # Connected to PlotHandler.refresh_plot
292-
ROIDIALOGOPTIONS = {}
293292

294293
@staticmethod
295294
@abc.abstractmethod
@@ -1264,13 +1263,23 @@ def __separate_view_finished(self, result: int) -> None:
12641263
self.__separate_views.pop(dlg)
12651264
dlg.deleteLater()
12661265

1266+
def get_dialog_size(self) -> tuple[int, int]:
1267+
"""Get dialog size (minimum and maximum)"""
1268+
# Resize the dialog so that it's at least MINDIALOGSIZE (absolute values),
1269+
# and at most MAXDIALOGSIZE (% of the main window size):
1270+
minwidth, minheight = self.MINDIALOGSIZE
1271+
maxwidth = int(self.mainwindow.width() * self.MAXDIALOGSIZE)
1272+
maxheight = int(self.mainwindow.height() * self.MAXDIALOGSIZE)
1273+
size = min(minwidth, maxwidth), min(minheight, maxheight)
1274+
return size
1275+
12671276
def create_new_dialog(
12681277
self,
12691278
edit: bool = False,
12701279
toolbar: bool = True,
12711280
title: str | None = None,
12721281
name: str | None = None,
1273-
options: dict | None = None,
1282+
options: dict[str, Any] | None = None,
12741283
) -> PlotDialog | None:
12751284
"""Create new pop-up signal/image plot dialog.
12761285
@@ -1284,27 +1293,20 @@ def create_new_dialog(
12841293
Returns:
12851294
Plot dialog instance
12861295
"""
1287-
plot_options = self.plothandler.get_current_plot_options()
1296+
plot_options = self.plothandler.get_plot_options()
12881297
if options is not None:
12891298
plot_options = plot_options.copy(options)
12901299

1291-
# Resize the dialog so that it's at least MINDIALOGSIZE (absolute values),
1292-
# and at most MAXDIALOGSIZE (% of the main window size):
1293-
minwidth, minheight = self.MINDIALOGSIZE
1294-
maxwidth = int(self.mainwindow.width() * self.MAXDIALOGSIZE)
1295-
maxheight = int(self.mainwindow.height() * self.MAXDIALOGSIZE)
1296-
size = min(minwidth, maxwidth), min(minheight, maxheight)
1297-
12981300
# pylint: disable=not-callable
12991301
dlg = PlotDialog(
13001302
parent=self.parent(),
13011303
title=APP_NAME if title is None else f"{title} - {APP_NAME}",
1302-
edit=edit,
13031304
options=plot_options,
13041305
toolbar=toolbar,
1305-
size=size,
1306+
icon="DataLab.svg",
1307+
edit=edit,
1308+
size=self.get_dialog_size(),
13061309
)
1307-
dlg.setWindowIcon(get_icon("DataLab.svg"))
13081310
dlg.setObjectName(name)
13091311
return dlg
13101312

@@ -1322,34 +1324,20 @@ def get_roi_editor_output(
13221324
A tuple containing the ROI object and a boolean indicating whether the
13231325
dialog was accepted or not.
13241326
"""
1325-
roi_s = _("Regions of interest")
1326-
options = self.ROIDIALOGOPTIONS
13271327
obj = self.objview.get_sel_objects(include_groups=True)[-1]
1328-
1329-
# Create a new dialog
1330-
1331-
dlg = self.create_new_dialog(
1332-
edit=True,
1333-
toolbar=mode != "define",
1334-
title=f"{roi_s} - {obj.title}",
1335-
name=f"{obj.PREFIX}_roi_dialog",
1336-
options=options,
1337-
)
1338-
if dlg is None:
1339-
return None
1340-
1341-
# Create ROI editor (and add it to the dialog)
1342-
13431328
item = create_adapter_from_object(obj).make_item(
13441329
update_from=self.plothandler[get_uuid(obj)]
13451330
)
1346-
1347-
# pylint: disable=not-callable
1348-
roi_editor = self.get_roieditor_class()(dlg, obj, mode, item=item)
1349-
1350-
dlg.button_layout.insertWidget(0, roi_editor)
1351-
1352-
if exec_dialog(dlg):
1331+
roi_editor_class = self.get_roieditor_class() # pylint: disable=not-callable
1332+
roi_editor = roi_editor_class(
1333+
parent=self.parent(),
1334+
obj=obj,
1335+
mode=mode,
1336+
item=item,
1337+
options=self.plothandler.get_plot_options(),
1338+
size=self.get_dialog_size(),
1339+
)
1340+
if exec_dialog(roi_editor):
13531341
return roi_editor.get_roieditor_results()
13541342
return None
13551343

datalab/gui/panel/image.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class ImagePanel(BaseDataPanel[ImageObj, ImageROI, roieditor.ImageROIEditor]):
5959

6060
IO_REGISTRY = ImageIORegistry
6161
H5_PREFIX = "DataLab_Ima"
62-
ROIDIALOGOPTIONS = {"show_itemlist": True, "show_contrast": False}
6362

6463
# pylint: disable=duplicate-code
6564

datalab/gui/plothandler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def cleanup_dataview(self) -> None:
471471
]
472472
)
473473

474-
def get_current_plot_options(self) -> PlotOptions:
474+
def get_plot_options(self) -> PlotOptions:
475475
"""Return standard signal/image plot options"""
476476
return PlotOptions(
477477
type=self.PLOT_TYPE,
@@ -496,9 +496,9 @@ def toggle_anti_aliasing(self, state: bool) -> None:
496496
self.plot.set_antialiasing(state)
497497
self.plot.replot()
498498

499-
def get_current_plot_options(self) -> PlotOptions:
499+
def get_plot_options(self) -> PlotOptions:
500500
"""Return standard signal/image plot options"""
501-
options = super().get_current_plot_options()
501+
options = super().get_plot_options()
502502
options.curve_antialiasing = self.plot.antialiased
503503
return options
504504

@@ -628,9 +628,9 @@ def cleanup_dataview(self) -> None:
628628
widget.hide()
629629
super().cleanup_dataview()
630630

631-
def get_current_plot_options(self) -> PlotOptions:
631+
def get_plot_options(self) -> PlotOptions:
632632
"""Return standard signal/image plot options"""
633-
options = super().get_current_plot_options()
633+
options = super().get_plot_options()
634634
options.zlabel = self.plot.get_axis_title("right")
635635
options.zunit = self.plot.get_axis_unit("right")
636636
return options

datalab/gui/processor/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def compute_line_profile(
547547
add_initial_shape = self.has_param_defaults(sigima.params.LineProfileParam)
548548
edit, param = self.init_param(param, sigima_image.LineProfileParam, title)
549549
if edit:
550-
options = self.panel.plothandler.get_current_plot_options()
550+
options = self.panel.plothandler.get_plot_options()
551551
dlg = ProfileExtractionDialog(
552552
"line", param, options, self.panel.parent(), add_initial_shape
553553
)
@@ -567,7 +567,7 @@ def compute_segment_profile(
567567
add_initial_shape = self.has_param_defaults(sigima.params.SegmentProfileParam)
568568
edit, param = self.init_param(param, sigima_image.SegmentProfileParam, title)
569569
if edit:
570-
options = self.panel.plothandler.get_current_plot_options()
570+
options = self.panel.plothandler.get_plot_options()
571571
dlg = ProfileExtractionDialog(
572572
"segment", param, options, self.panel.parent(), add_initial_shape
573573
)
@@ -587,7 +587,7 @@ def compute_average_profile(
587587
add_initial_shape = self.has_param_defaults(sigima.params.AverageProfileParam)
588588
edit, param = self.init_param(param, sigima_image.AverageProfileParam, title)
589589
if edit:
590-
options = self.panel.plothandler.get_current_plot_options()
590+
options = self.panel.plothandler.get_plot_options()
591591
dlg = ProfileExtractionDialog(
592592
"rectangle", param, options, self.panel.parent(), add_initial_shape
593593
)

0 commit comments

Comments
 (0)