# Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.""".. Signal 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(HCursorTool,HRangeTool,LabelTool,RectangleTool,SegmentTool,VCursorTool,XCursorTool,)fromcdl.configimport_fromcdl.core.guiimportroieditorfromcdl.core.gui.actionhandlerimportSignalActionHandlerfromcdl.core.gui.panel.baseimportBaseDataPanelfromcdl.core.gui.plothandlerimportSignalPlotHandlerfromcdl.core.gui.processor.signalimportSignalProcessorfromcdl.core.io.signalimportSignalIORegistryfromcdl.core.model.signalimport(CURVESTYLES,SignalObj,SignalROI,create_signal_from_param,new_signal_param,)ifTYPE_CHECKING:importguidata.datasetasgdsfromqtpyimportQtWidgetsasQWfromcdl.core.gui.docksimportDockablePlotWidgetfromcdl.core.model.signalimportNewSignalParam
[docs]classSignalPanel(BaseDataPanel[SignalObj,SignalROI,roieditor.SignalROIEditor]):"""Object handling the item list, the selected item properties and plot, specialized for Signal objects"""PANEL_STR=_("Signal Panel")PANEL_STR_ID="signal"PARAMCLASS=SignalObj# The following tools are used to create annotations on signals. The annotation# items are created using PlotPy's default settings. Those appearance settings# may be modified in the configuration (see `cdl.config`).ANNOTATION_TOOLS=(LabelTool,VCursorTool,HCursorTool,XCursorTool,SegmentTool,RectangleTool,HRangeTool,)IO_REGISTRY=SignalIORegistryH5_PREFIX="DataLab_Sig"# pylint: disable=duplicate-code
[docs]@staticmethoddefget_roieditor_class()->Type[roieditor.SignalROIEditor]:"""Return ROI editor class"""returnroieditor.SignalROIEditor
[docs]defget_newparam_from_current(self,newparam:NewSignalParam|None=None,title:str|None=None)->NewSignalParam|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:SignalObj=self.objview.get_current_object()ifnewparamisNone:newparam=new_signal_param(title=title)ifcurobjisnotNone:newparam.size=len(curobj.data)newparam.xmin=curobj.x.min()newparam.xmax=curobj.x.max()returnnewparam
[docs]defnew_object(self,newparam:NewSignalParam|None=None,addparam:gds.DataSet|None=None,edit:bool=True,add_to_panel:bool=True,)->SignalObj|None:"""Create a new object (signal). Args: newparam (guidata.dataset.DataSet): 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 new object to the panel (default: True) Returns: New object """ifnotself.mainwindow.confirm_memory_state():returnNonenewparam=self.get_newparam_from_current(newparam)signal=create_signal_from_param(newparam,addparam=addparam,edit=edit,parent=self.parent())ifsignalisNone:returnNoneifadd_to_panel:self.add_object(signal)returnsignal
[docs]deftoggle_anti_aliasing(self,state:bool)->None:"""Toggle anti-aliasing on/off Args: state: state of the anti-aliasing """self.plothandler.toggle_anti_aliasing(state)