1515import os .path as osp
1616import re
1717import warnings
18- from typing import TYPE_CHECKING , Generic , Literal , Type
18+ from typing import TYPE_CHECKING , Any , Generic , Literal , Type
1919
2020import guidata .dataset as gds
2121import 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
0 commit comments