# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.""".. Image panel (see parent package :mod:`cdl.core.gui.panel`)"""# pylint: disable=invalid-name # Allows short reference names like x, y, ...from__future__importannotationsfromtypingimportTYPE_CHECKING,Typefromplotpy.toolsimport(AnnotatedCircleTool,AnnotatedEllipseTool,AnnotatedPointTool,AnnotatedRectangleTool,AnnotatedSegmentTool,LabelTool,)fromcdl.configimportConf,_fromcdl.core.guiimportroieditorfromcdl.core.gui.actionhandlerimportImageActionHandlerfromcdl.core.gui.panel.baseimportBaseDataPanelfromcdl.core.gui.plothandlerimportImagePlotHandlerfromcdl.core.gui.processor.imageimportImageProcessorfromcdl.core.io.imageimportImageIORegistryfromcdl.core.model.imageimport(ImageDatatypes,ImageObj,ImageROI,create_image_from_param,new_image_param,)ifTYPE_CHECKING:importguidata.datasetasgdsfromplotpy.plotimportBasePlotfromqtpyimportQtWidgetsasQWfromcdl.core.gui.docksimportDockablePlotWidgetfromcdl.core.model.imageimportNewImageParam
[docs]classImagePanel(BaseDataPanel[ImageObj,ImageROI,roieditor.ImageROIEditor]):"""Object handling the item list, the selected item properties and plot, specialized for Image objects"""PANEL_STR=_("Image Panel")PANEL_STR_ID="image"PARAMCLASS=ImageObjMINDIALOGSIZE=(800,800)# The following tools are used to create annotations on images. The annotation# items are created using PlotPy's default settings. Those appearance settings# may be modified in the configuration (see `cdl.config`).ANNOTATION_TOOLS=(AnnotatedCircleTool,AnnotatedSegmentTool,AnnotatedRectangleTool,AnnotatedPointTool,AnnotatedEllipseTool,LabelTool,)IO_REGISTRY=ImageIORegistryH5_PREFIX="DataLab_Ima"ROIDIALOGOPTIONS={"show_itemlist":True,"show_contrast":False}# pylint: disable=duplicate-code
[docs]@staticmethoddefget_roieditor_class()->Type[roieditor.ImageROIEditor]:"""Return ROI editor class"""returnroieditor.ImageROIEditor
[docs]defget_newparam_from_current(self,newparam:NewImageParam|None=None,title:str|None=None)->NewImageParam|None:"""Get new object parameters from the current object. Args: newparam (guidata.dataset.DataSet): new object parameters. If None, create a new one. title: new object title. If None, use the current object title, or the default title. Returns: New object parameters """curobj:ImageObj=self.objview.get_current_object()ifnewparamisNone:newparam=new_image_param(title=title)ifcurobjisnotNone:newparam.width,newparam.height=curobj.data.shapenewparam.dtype=ImageDatatypes.from_dtype(curobj.data.dtype)returnnewparam
[docs]defnew_object(self,newparam:NewImageParam|None=None,addparam:gds.DataSet|None=None,edit:bool=True,add_to_panel:bool=True,)->ImageObj|None:"""Create a new object (image). Args: newparam (Daguidata.dataset.datatypes.DataSettaSet): new object parameters addparam (guidata.dataset.DataSet): additional parameters edit (bool): Open a dialog box to edit parameters (default: True) add_to_panel (bool): Add the object to the panel (default: True) Returns: New object """ifnotself.mainwindow.confirm_memory_state():returnNonenewparam=self.get_newparam_from_current(newparam)image=create_image_from_param(newparam,addparam=addparam,edit=edit,parent=self.parent())ifimageisNone:returnNoneifadd_to_panel:self.add_object(image)returnimage
[docs]deftoggle_show_contrast(self,state:bool)->None:"""Toggle show contrast option"""Conf.view.show_contrast.set(state)self.SIG_REFRESH_PLOT.emit("selected",True)