diff --git a/pyproject.toml b/pyproject.toml index 30c314e..e6e5440 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,26 +6,24 @@ h5exporters = false # true if plugin contains custom h5 file exporters scanners = false # true if plugin contains custom scan layout (daq_scan extensions) [urls] -package-url = 'https://github.com/PyMoDAQ/pymodaq_plugins_template' #todo modify url by your plugin url +package-url = 'https://github.com/jerlfan/pymodaq_plugins_owis' [project] -name = "pymodaq_plugins_template" #todo modify template by your plugin short name -description = 'some word about your plugin' +name = "pymodaq_plugins_owis" +description = 'PyMoDAQ plugin for OWIS positioning units driven by PS 10 control units' dependencies = [ "pymodaq>=5.3.7", "pymodaq_utils>=5.3.1", "pymodaq_gui>=5.3.0", "pymodaq_data>=5.3.0", - #todo: list here all dependencies your package may have + "pyserial", ] authors = [ - {name = "Name Surname", email = "myname@test.fr"}, - #todo: list here all authors of your plugin + {name = "Jérémie Margueritat", email = "jeremie.margueritat@univ-lyon1.fr"}, ] maintainers = [ - {name = "Name Surname", email = "myname@test.fr"}, - #todo: list here all maintainers of your plugin + {name = "Jérémie Margueritat", email = "jeremie.margueritat@univ-lyon1.fr"}, ] # nottodo: leave everything below as is! diff --git a/src/pymodaq_plugins_template/__init__.py b/src/pymodaq_plugins_owis/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/__init__.py rename to src/pymodaq_plugins_owis/__init__.py diff --git a/src/pymodaq_plugins_template/app/__init__.py b/src/pymodaq_plugins_owis/app/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/app/__init__.py rename to src/pymodaq_plugins_owis/app/__init__.py diff --git a/src/pymodaq_plugins_template/daq_move_plugins/__init__.py b/src/pymodaq_plugins_owis/daq_move_plugins/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_move_plugins/__init__.py rename to src/pymodaq_plugins_owis/daq_move_plugins/__init__.py diff --git a/src/pymodaq_plugins_template/daq_move_plugins/daq_move_Template.py b/src/pymodaq_plugins_owis/daq_move_plugins/daq_move_Template.py similarity index 100% rename from src/pymodaq_plugins_template/daq_move_plugins/daq_move_Template.py rename to src/pymodaq_plugins_owis/daq_move_plugins/daq_move_Template.py diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/__init__.py b/src/pymodaq_plugins_owis/daq_viewer_plugins/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_viewer_plugins/__init__.py rename to src/pymodaq_plugins_owis/daq_viewer_plugins/__init__.py diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_0D/__init__.py b/src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_0D/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_viewer_plugins/plugins_0D/__init__.py rename to src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_0D/__init__.py diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_1D/__init__.py b/src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_1D/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_viewer_plugins/plugins_1D/__init__.py rename to src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_1D/__init__.py diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_2D/__init__.py b/src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_2D/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_viewer_plugins/plugins_2D/__init__.py rename to src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_2D/__init__.py diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_ND/__init__.py b/src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_ND/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/daq_viewer_plugins/plugins_ND/__init__.py rename to src/pymodaq_plugins_owis/daq_viewer_plugins/plugins_ND/__init__.py diff --git a/src/pymodaq_plugins_template/exporters/__init__.py b/src/pymodaq_plugins_owis/exporters/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/exporters/__init__.py rename to src/pymodaq_plugins_owis/exporters/__init__.py diff --git a/src/pymodaq_plugins_template/extensions/__init__.py b/src/pymodaq_plugins_owis/extensions/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/extensions/__init__.py rename to src/pymodaq_plugins_owis/extensions/__init__.py diff --git a/src/pymodaq_plugins_template/hardware/__init__.py b/src/pymodaq_plugins_owis/hardware/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/hardware/__init__.py rename to src/pymodaq_plugins_owis/hardware/__init__.py diff --git a/src/pymodaq_plugins_template/models/__init__.py b/src/pymodaq_plugins_owis/models/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/models/__init__.py rename to src/pymodaq_plugins_owis/models/__init__.py diff --git a/src/pymodaq_plugins_template/resources/__init__.py b/src/pymodaq_plugins_owis/resources/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/resources/__init__.py rename to src/pymodaq_plugins_owis/resources/__init__.py diff --git a/src/pymodaq_plugins_template/resources/config_template.toml b/src/pymodaq_plugins_owis/resources/config_template.toml similarity index 100% rename from src/pymodaq_plugins_template/resources/config_template.toml rename to src/pymodaq_plugins_owis/resources/config_template.toml diff --git a/src/pymodaq_plugins_template/scanners/__init__.py b/src/pymodaq_plugins_owis/scanners/__init__.py similarity index 100% rename from src/pymodaq_plugins_template/scanners/__init__.py rename to src/pymodaq_plugins_owis/scanners/__init__.py diff --git a/src/pymodaq_plugins_template/utils.py b/src/pymodaq_plugins_owis/utils.py similarity index 100% rename from src/pymodaq_plugins_template/utils.py rename to src/pymodaq_plugins_owis/utils.py diff --git a/src/pymodaq_plugins_template/app/custom_app_template.py b/src/pymodaq_plugins_template/app/custom_app_template.py deleted file mode 100644 index e29b851..0000000 --- a/src/pymodaq_plugins_template/app/custom_app_template.py +++ /dev/null @@ -1,130 +0,0 @@ -"""Template of a standalone application, for applications that need NO instruments. - -If your application drives instruments (actuators, detectors), write a Dashboard extension (CustomExt, see the -extensions folder) instead: it relies on the Dashboard's stable mechanisms to handle instruments (experiment and -state managers, modules manager...). -""" -from qtpy import QtWidgets - -from pymodaq_gui import utils as gutils -from pymodaq_utils.config import GlobalConfig -from pymodaq_utils.logger import set_logger, get_module_name - -logger = set_logger(get_module_name(__file__)) - -# all the configurations (PyMoDAQ's packages and the one of your plugin package) are read from GlobalConfig, for -# instance: config('gui', 'style', 'theme') -config = GlobalConfig() - - -# todo: modify the name of this class to reflect its application and change the name in the main -# method at the end of the script -class CustomAppTemplate(gutils.CustomApp): - - # todo: if you wish to create custom Parameter and corresponding widgets. These will be - # automatically added as children of self.settings. Morevover, the self.settings_tree will - # render the widgets in a Qtree. If you wish to see it in your app, add is into a Dock - params = [] - - def __init__(self, parent: gutils.DockArea): - super().__init__(parent) - - self.setup_ui() # calls, in this order: setup_docks_and_widgets, setup_menus_and_toolbars, - # setup_actions, connect_things and do_things_after_ui_setup - - def setup_docks_and_widgets(self): - """Method to be subclassed to setup the docks layout - - Examples - -------- - >>>self.docks['ADock'] = gutils.Dock('ADock name') - >>>self.dockarea.addDock(self.docks['ADock']) - >>>self.docks['AnotherDock'] = gutils.Dock('AnotherDock name') - >>>self.dockarea.addDock(self.docks['AnotherDock'''], 'bottom', self.docks['ADock']) - - See Also - -------- - pyqtgraph.dockarea.Dock - """ - # todo: create docks and add them here to hold your widgets. Here the settings tree in a dock - self.docks['settings'] = gutils.Dock('Settings') - self.dockarea.addDock(self.docks['settings']) - self.docks['settings'].addWidget(self.settings_tree) - - def setup_menus_and_toolbars(self, menubar: QtWidgets.QMenuBar = None): - """Non mandatory method to be subclassed in order to create menus and toolbars - - It is called before setup_actions: only create the (empty) menus and toolbars here, the actions are created - afterwards in setup_actions where they can be put in them, for instance: - - Examples - -------- - >>> self.add_menu('file', 'File', parent_menu=menubar) # here - >>> self.add_toolbar('main', 'Main toolbar', self.mainwindow) # here - >>> self.add_action('save', 'Save', 'SaveAs', "Save current data", menu='file', toolbar='main') # in setup_actions - - See Also - -------- - pymodaq_gui.managers.action_manager.ActionManager - """ - # todo create the menus and toolbars of your app here (they will be populated by the actions of setup_actions) - pass - - def setup_actions(self): - """Method where to create actions to be subclassed - - Examples - -------- - >>> self.add_action('quit', 'Quit', 'close2', "Quit program") - >>> self.add_action('grab', 'Grab', 'camera', "Grab from camera", checkable=True) - >>> self.add_action('load', 'Load', 'Open', "Load target file (.h5, .png, .jpg) or data from camera" - , checkable=False) - >>> self.add_action('save', 'Save', 'SaveAs', "Save current data", checkable=False) - - See Also - -------- - ActionManager.add_action - """ - # todo: replace this example action by yours - self.add_action('say_hello', 'Say hello', 'add_circle', tip='Show a message in the status bar') - - def connect_things(self): - """Connect actions and/or other widgets signal to methods""" - # todo: replace this example by your connections - self.connect_action('say_hello', lambda: self.update_status('Hello')) - - def value_changed(self, param): - """ Actions to perform when one of the param's value in self.settings is changed from the - user interface - - For instance: - if param.name() == 'do_something': - if param.value(): - print('Do something') - self.settings.child('main_settings', 'something_done').setValue(False) - - Parameters - ---------- - param: (Parameter) the parameter whose value just changed - """ - pass - - -def main(): - from pymodaq_gui.qt_utils import mkQApp - app = mkQApp('CustomApp') - - mainwindow = QtWidgets.QMainWindow() - dockarea = gutils.DockArea() - mainwindow.setCentralWidget(dockarea) - - # todo: change the name here to be the same as your app class - prog = CustomAppTemplate(dockarea) - - mainwindow.show() - - app.exec() - - -if __name__ == '__main__': - main() diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_0D/daq_0Dviewer_Template.py b/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_0D/daq_0Dviewer_Template.py deleted file mode 100644 index 3a75b1f..0000000 --- a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_0D/daq_0Dviewer_Template.py +++ /dev/null @@ -1,160 +0,0 @@ -import numpy as np - -from pymodaq_utils.utils import ThreadCommand -from pymodaq_data.data import DataToExport -from pymodaq_gui.parameter import Parameter - -from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main -from pymodaq.utils.data import DataFromPlugins - -# TODO: -# Replace the following fake import with the import of the real Python wrapper of your instrument. Here we suppose that -# the wrapper is in the hardware directory, but it could come from an external librairy like pylablib or pymeasure. -from pymodaq_plugins_template.hardware.python_wrapper_file_of_your_instrument import PythonWrapperObjectOfYourInstrument - -# TODO: -# (1) change the name of the following class to DAQ_0DViewer_TheNameOfYourChoice -# (2) change the name of this file to daq_0Dviewer_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME -# for the class name and the file name.) -# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: -# pymodaq_plugins_my_plugin/daq_viewer_plugins/plugins_0D - - -class DAQ_0DViewer_Template(DAQ_Viewer_base): - """ Instrument plugin class for a OD viewer. - - This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via - DAQ_Viewer_base. It makes a bridge between the DAQ_Viewer module and the Python wrapper of a particular instrument. - - TODO Complete the docstring of your plugin with: - * The set of instruments that should be compatible with this instrument plugin. - * With which instrument it has actually been tested. - * The version of PyMoDAQ during the test. - * The version of the operating system. - * Installation instructions: what manufacturer’s drivers should be installed to make it run? - - Attributes: - ----------- - controller: object - The particular object that allow the communication with the hardware, in general a python wrapper around the - hardware library. - - # TODO add your particular attributes here if any - - """ - params = comon_parameters+[ - ## TODO for your custom plugin: elements to be added here as dicts in order to control your custom stage - ] - - def ini_attributes(self): - # TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy - # autocompletion - self.controller: PythonWrapperObjectOfYourInstrument = None - - #TODO declare here attributes you want/need to init with a default value - pass - - def ini_detector(self, controller=None): - """Detector communication initialization - - Parameters - ---------- - controller: (object) - custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller - (Master case) - - Returns - ------- - info: str - initialized: bool - False if initialization failed otherwise True - """ - - raise NotImplementedError # TODO when writing your own plugin remove this line and modify the one below - if self.is_master: - self.controller = PythonWrapperObjectOfYourInstrument() #instantiate you driver with whatever arguments are needed - self.controller.open_communication() # call eventual methods - initialized = self.controller.a_method_or_atttribute_to_check_if_init() # TODO - else: - self.controller = controller - initialized = True - - # TODO for your custom plugin (optional) initialize viewers panel with the future type of data - self.dte_signal_temp.emit(DataToExport(name='myplugin', - data=[DataFromPlugins(name='Mock1', - data=[np.array([0]), np.array([0])], - dim='Data0D', - labels=['Mock1', 'label2'])])) - - info = "Whatever info you want to log" - return info, initialized - - def close(self): - """Terminate the communication protocol""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - # only the master owns the controller (a slave must not close the shared one) and ini_stage/ini_detector may - # have failed before creating it, so close can be called while self.controller is still None - if self.is_master and self.controller is not None: - # self.controller.your_method_to_terminate_the_communication() # when writing your own plugin replace this line - ... - - def grab_data(self, Naverage=1, **kwargs): - """Start a grab from the detector - - Parameters - ---------- - Naverage: int - Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to - True in class preamble and you should code this implementation) - kwargs: dict - others optionals arguments - """ - ## TODO for your custom plugin: you should choose EITHER the synchrone or the asynchrone version following - - # synchrone version (blocking function) - raise NotImplementedError # when writing your own plugin remove this line - data_tot = self.controller.your_method_to_start_a_grab_snap() - self.dte_signal.emit(DataToExport(name='myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data0D', labels=['dat0', 'data1'])])) - ######################################################### - - # asynchrone version (non-blocking function with callback) - raise NotImplementedError # when writing your own plugin remove this line - self.controller.your_method_to_start_a_grab_snap(self.callback) # when writing your own plugin replace this line - ######################################################### - - def callback(self): - """optional asynchrone method called when the detector has finished its acquisition of data""" - data_tot = self.controller.your_method_to_get_data_from_buffer() - self.dte_signal.emit(DataToExport(name='myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data0D', labels=['dat0', 'data1'])])) - - def stop(self): - """Stop the current grab hardware wise if necessary""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - self.controller.your_method_to_stop_acquisition() # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - ############################## - return '' - - def commit_settings(self, param: Parameter): - """Apply the consequences of a change of value in the detector settings - - Parameters - ---------- - param: Parameter - A given parameter (within detector_settings) whose value has been changed by the user - """ - ## TODO for your custom plugin - if param.name() == "a_parameter_you've_added_in_self.params": - self.controller.your_method_to_apply_this_param_change() # when writing your own plugin replace this line -# elif ... - ## - - -if __name__ == '__main__': - main(__file__) diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_1D/daq_1Dviewer_Template.py b/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_1D/daq_1Dviewer_Template.py deleted file mode 100644 index 0f874f3..0000000 --- a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_1D/daq_1Dviewer_Template.py +++ /dev/null @@ -1,167 +0,0 @@ -import numpy as np - -from pymodaq_utils.utils import ThreadCommand -from pymodaq_data.data import DataToExport, Axis -from pymodaq_gui.parameter import Parameter - -from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main -from pymodaq.utils.data import DataFromPlugins - -# TODO: -# Replace the following fake import with the import of the real Python wrapper of your instrument. Here we suppose that -# the wrapper is in the hardware directory, but it could come from an external librairy like pylablib or pymeasure. -from pymodaq_plugins_template.hardware.python_wrapper_file_of_your_instrument import PythonWrapperObjectOfYourInstrument - -# TODO: -# (1) change the name of the following class to DAQ_1DViewer_TheNameOfYourChoice -# (2) change the name of this file to daq_1Dviewer_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME -# for the class name and the file name.) -# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: -# pymodaq_plugins_my_plugin/daq_viewer_plugins/plugins_1D - - -class DAQ_1DViewer_Template(DAQ_Viewer_base): - """ Instrument plugin class for a 1D viewer. - - This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via - DAQ_Viewer_base. It makes a bridge between the DAQ_Viewer module and the Python wrapper of a particular instrument. - - TODO Complete the docstring of your plugin with: - * The set of instruments that should be compatible with this instrument plugin. - * With which instrument it has actually been tested. - * The version of PyMoDAQ during the test. - * The version of the operating system. - * Installation instructions: what manufacturer’s drivers should be installed to make it run? - - Attributes: - ----------- - controller: object - The particular object that allow the communication with the hardware, in general a python wrapper around the - hardware library. - - # TODO add your particular attributes here if any - - """ - params = comon_parameters+[ - ## TODO for your custom plugin - # elements to be added here as dicts in order to control your custom stage - ############ - ] - - def ini_attributes(self): - # TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy - # autocompletion - self.controller: PythonWrapperObjectOfYourInstrument = None - - # TODO declare here attributes you want/need to init with a default value - - self.x_axis = None - - def ini_detector(self, controller=None): - """Detector communication initialization - - Parameters - ---------- - controller: (object) - custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller - (Master case) - - Returns - ------- - info: str - initialized: bool - False if initialization failed otherwise True - """ - - raise NotImplementedError # TODO when writing your own plugin remove this line and modify the one below - if self.is_master: - self.controller = PythonWrapperObjectOfYourInstrument() #instantiate you driver with whatever arguments are needed - self.controller.open_communication() # call eventual methods - initialized = self.controller.a_method_or_atttribute_to_check_if_init() # TODO - else: - self.controller = controller - initialized = True - - ## TODO for your custom plugin - # get the x_axis (you may want to to this also in the commit settings if x_axis may have changed - data_x_axis = self.controller.your_method_to_get_the_x_axis() # if possible - self.x_axis = Axis(data=data_x_axis, label='', units='', index=0) - - # TODO for your custom plugin. Initialize viewers pannel with the future type of data - self.dte_signal_temp.emit(DataToExport(name='myplugin', - data=[DataFromPlugins(name='Mock1', - data=[np.array([0., 0., ...]), - np.array([0., 0., ...])], - dim='Data1D', labels=['Mock1', 'label2'], - axes=[self.x_axis])])) - - info = "Whatever info you want to log" - return info, initialized - - def close(self): - """Terminate the communication protocol""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - # only the master owns the controller (a slave must not close the shared one) and ini_stage/ini_detector may - # have failed before creating it, so close can be called while self.controller is still None - if self.is_master and self.controller is not None: - # self.controller.your_method_to_terminate_the_communication() # when writing your own plugin replace this line - ... - - def grab_data(self, Naverage=1, **kwargs): - """Start a grab from the detector - - Parameters - ---------- - Naverage: int - Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to - True in class preamble and you should code this implementation) - kwargs: dict - others optionals arguments - """ - ## TODO for your custom plugin: you should choose EITHER the synchrone or the asynchrone version following - - ##synchrone version (blocking function) - data_tot = self.controller.your_method_to_start_a_grab_snap() - self.dte_signal.emit(DataToExport('myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data1D', labels=['dat0', 'data1'], - axes=[self.x_axis])])) - - ##asynchrone version (non-blocking function with callback) - self.controller.your_method_to_start_a_grab_snap(self.callback) - ######################################################### - - def callback(self): - """optional asynchrone method called when the detector has finished its acquisition of data""" - data_tot = self.controller.your_method_to_get_data_from_buffer() - self.dte_signal.emit(DataToExport('myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data1D', labels=['dat0', 'data1'])])) - - def stop(self): - """Stop the current grab hardware wise if necessary""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - self.controller.your_method_to_stop_acquisition() # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - ############################## - return '' - - def commit_settings(self, param: Parameter): - """Apply the consequences of a change of value in the detector settings - - Parameters - ---------- - param: Parameter - A given parameter (within detector_settings) whose value has been changed by the user - """ - ## TODO for your custom plugin - if param.name() == "a_parameter_you've_added_in_self.params": - self.controller.your_method_to_apply_this_param_change() -# elif ... - ## - - -if __name__ == '__main__': - main(__file__) diff --git a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_2D/daq_2Dviewer_Template.py b/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_2D/daq_2Dviewer_Template.py deleted file mode 100644 index 23e4f7f..0000000 --- a/src/pymodaq_plugins_template/daq_viewer_plugins/plugins_2D/daq_2Dviewer_Template.py +++ /dev/null @@ -1,170 +0,0 @@ -import numpy as np - -from pymodaq_utils.utils import ThreadCommand -from pymodaq_data.data import DataToExport, Axis -from pymodaq_gui.parameter import Parameter - -from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main -from pymodaq.utils.data import DataFromPlugins - -# TODO: -# Replace the following fake import with the import of the real Python wrapper of your instrument. Here we suppose that -# the wrapper is in the hardware directory, but it could come from an external librairy like pylablib or pymeasure. -from pymodaq_plugins_template.hardware.python_wrapper_file_of_your_instrument import PythonWrapperObjectOfYourInstrument - -# TODO: -# (1) change the name of the following class to DAQ_2DViewer_TheNameOfYourChoice -# (2) change the name of this file to daq_2Dviewer_TheNameOfYourChoice ("TheNameOfYourChoice" should be the SAME -# for the class name and the file name.) -# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING: -# pymodaq_plugins_my_plugin/daq_viewer_plugins/plugins_2D - - -class DAQ_2DViewer_Template(DAQ_Viewer_base): - """ Instrument plugin class for a 2D viewer. - - This object inherits all functionalities to communicate with PyMoDAQ’s DAQ_Viewer module through inheritance via - DAQ_Viewer_base. It makes a bridge between the DAQ_Viewer module and the Python wrapper of a particular instrument. - - TODO Complete the docstring of your plugin with: - * The set of instruments that should be compatible with this instrument plugin. - * With which instrument it has actually been tested. - * The version of PyMoDAQ during the test. - * The version of the operating system. - * Installation instructions: what manufacturer’s drivers should be installed to make it run? - - Attributes: - ----------- - controller: object - The particular object that allow the communication with the hardware, in general a python wrapper around the - hardware library. - - # TODO add your particular attributes here if any - - """ - params = comon_parameters + [ - ## TODO for your custom plugin - # elements to be added here as dicts in order to control your custom stage - ############ - ] - - def ini_attributes(self): - # TODO declare the type of the wrapper (and assign it to self.controller) you're going to use for easy - # autocompletion - self.controller: PythonWrapperObjectOfYourInstrument = None - - # TODO declare here attributes you want/need to init with a default value - - self.x_axis = None - self.y_axis = None - - def ini_detector(self, controller=None): - """Detector communication initialization - - Parameters - ---------- - controller: (object) - custom object of a PyMoDAQ plugin (Slave case). None if only one actuator/detector by controller - (Master case) - - Returns - ------- - info: str - initialized: bool - False if initialization failed otherwise True - """ - raise NotImplementedError # TODO when writing your own plugin remove this line and modify the one below - if self.is_master: - self.controller = PythonWrapperObjectOfYourInstrument() #instantiate you driver with whatever arguments are needed - self.controller.open_communication() # call eventual methods - initialized = self.controller.a_method_or_atttribute_to_check_if_init() # TODO - else: - self.controller = controller - initialized = True - - ## TODO for your custom plugin - # get the x_axis (you may want to to this also in the commit settings if x_axis may have changed - data_x_axis = self.controller.your_method_to_get_the_x_axis() # if possible - self.x_axis = Axis(data=data_x_axis, label='', units='', index=1) - - # get the y_axis (you may want to to this also in the commit settings if y_axis may have changed - data_y_axis = self.controller.your_method_to_get_the_y_axis() # if possible - self.y_axis = Axis(data=data_y_axis, label='', units='', index=0) - - ## TODO for your custom plugin. Initialize viewers pannel with the future type of data - self.dte_signal_temp.emit(DataToExport('myplugin', - data=[DataFromPlugins(name='Mock1', data=["2D numpy array"], - dim='Data2D', labels=['dat0'], - axes=[self.x_axis, self.y_axis]), ])) - - info = "Whatever info you want to log" - return info, initialized - - def close(self): - """Terminate the communication protocol""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - # only the master owns the controller (a slave must not close the shared one) and ini_stage/ini_detector may - # have failed before creating it, so close can be called while self.controller is still None - if self.is_master and self.controller is not None: - # self.controller.your_method_to_terminate_the_communication() # when writing your own plugin replace this line - ... - - def grab_data(self, Naverage=1, **kwargs): - """Start a grab from the detector - - Parameters - ---------- - Naverage: int - Number of hardware averaging (if hardware averaging is possible, self.hardware_averaging should be set to - True in class preamble and you should code this implementation) - kwargs: dict - others optionals arguments - """ - ## TODO for your custom plugin: you should choose EITHER the synchrone or the asynchrone version following - - ##synchrone version (blocking function) - data_tot = self.controller.your_method_to_start_a_grab_snap() - self.dte_signal.emit(DataToExport('myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data2D', labels=['label1'], - axes=[self.x_axis, self.y_axis]), ])) - - ##asynchrone version (non-blocking function with callback) - self.controller.your_method_to_start_a_grab_snap(self.callback) - ######################################################### - - def callback(self): - """optional asynchrone method called when the detector has finished its acquisition of data""" - data_tot = self.controller.your_method_to_get_data_from_buffer() - self.dte_signal.emit(DataToExport('myplugin', - data=[DataFromPlugins(name='Mock1', data=data_tot, - dim='Data2D', labels=['label1'], - x_axis=self.x_axis, - y_axis=self.y_axis), ])) - - def stop(self): - """Stop the current grab hardware wise if necessary""" - ## TODO for your custom plugin - raise NotImplementedError # when writing your own plugin remove this line - self.controller.your_method_to_stop_acquisition() # when writing your own plugin replace this line - self.emit_status(ThreadCommand('Update_Status', ['Some info you want to log'])) - ############################## - return '' - - def commit_settings(self, param: Parameter): - """Apply the consequences of a change of value in the detector settings - - Parameters - ---------- - param: Parameter - A given parameter (within detector_settings) whose value has been changed by the user - """ - # TODO for your custom plugin - if param.name() == "a_parameter_you've_added_in_self.params": - self.controller.your_method_to_apply_this_param_change() - #elif ... - - -if __name__ == '__main__': - main(__file__) diff --git a/src/pymodaq_plugins_template/extensions/custom_extension_template.py b/src/pymodaq_plugins_template/extensions/custom_extension_template.py deleted file mode 100644 index bd16dea..0000000 --- a/src/pymodaq_plugins_template/extensions/custom_extension_template.py +++ /dev/null @@ -1,163 +0,0 @@ -"""Template of a Dashboard extension. - -An extension is a ``CustomExt``: a small application living inside the Dashboard. Everything related to the -instruments (the experiment, i.e. the list of actuators and detectors, and its state) is handled by the Dashboard, -the extension only uses it through its ``dashboard`` argument: - -* ``self.modules_manager``: a ModulesManager created for this extension, giving access to the actuators and - detectors of the Dashboard's experiment (never create control modules yourself) -* ``self.experiment_manager`` and ``self.state_manager``: the Dashboard's managers, never create your own - -The only difference with the extensions of the PyMoDAQ core is the presence of the ``EXTENSION_NAME`` and -``CLASS_NAME`` variables below, needed by the Dashboard to recognize your extension (plus the -``pymodaq.extensions`` entry point in pyproject.toml). -""" -from qtpy import QtWidgets - -from pymodaq_gui import utils as gutils -from pymodaq_utils.config import GlobalConfig -from pymodaq_utils.logger import set_logger, get_module_name - -from pymodaq.utils.custom_ext import CustomExt - -logger = set_logger(get_module_name(__file__)) - -# all the configurations (PyMoDAQ's packages and the one of your plugin package) are read from GlobalConfig, for -# instance: config('gui', 'style', 'theme') -config = GlobalConfig() - -# todo: modify this as you wish -EXTENSION_NAME = 'MY_EXTENSION_NAME' # the name that will be displayed in the extension list in the -# dashboard -CLASS_NAME = 'CustomExtensionTemplate' # this should be the name of your class defined below - - -# todo: modify the name of this class to reflect its application and change the name in the main -# method at the end of the script -class CustomExtensionTemplate(CustomExt): - - # todo: if you wish to create custom Parameter and corresponding widgets. These will be - # automatically added as children of self.settings. Morevover, the self.settings_tree will - # render the widgets in a Qtree. If you wish to see it in your app, add is into a Dock - params = [] - - def __init__(self, parent: gutils.DockArea, dashboard): - # also creates self.modules_manager for this extension, and the extension's own toolbar (named after the - # class). Like the PyMoDAQ extensions (scan, sequencer...), no break is added before it - super().__init__(parent, dashboard, add_toolbar_break=False) - - self.setup_ui() # calls, in this order: setup_docks_and_widgets, setup_menus_and_toolbars, - # setup_actions, connect_things and do_things_after_ui_setup - - def setup_docks_and_widgets(self): - """Method to be subclassed to setup the docks layout - - Examples - -------- - >>>self.docks['ADock'] = gutils.Dock('ADock name') - >>>self.dockarea.addDock(self.docks['ADock']) - >>>self.docks['AnotherDock'] = gutils.Dock('AnotherDock name') - >>>self.dockarea.addDock(self.docks['AnotherDock'''], 'bottom', self.docks['ADock']) - - See Also - -------- - pyqtgraph.dockarea.Dock - """ - # todo: create docks and add them here to hold your widgets. Here the settings tree in a dock - self.docks['settings'] = gutils.Dock('Settings') - self.dockarea.addDock(self.docks['settings']) - self.docks['settings'].addWidget(self.settings_tree) - - def setup_menus_and_toolbars(self, menubar: QtWidgets.QMenuBar = None): - """Non mandatory method to be subclassed in order to create menus and toolbars - - Examples - -------- - >>>file_menu = self.add_menu('file', 'File', parent_menu=menubar) - - See Also - -------- - pymodaq.utils.managers.action_manager.ActionManager - """ - # adds a second toolbar, the Dashboard one: show/hide the Dashboard, load an experiment and a state - self.create_dashboard_toolbar(add_break=False) - - def setup_actions(self): - """Method where to create actions to be subclassed - - Examples - -------- - >>> self.add_action('grab', 'Grab', 'camera', "Grab from camera", checkable=True) - - See Also - -------- - ActionManager.add_action - """ - # todo: replace this example action by yours - self.add_action('list_modules', 'List modules', 'add_circle', - tip='Show the actuators and detectors of the current experiment') - - def connect_things(self): - """Connect actions and/or other widgets signal to methods""" - # todo: replace this example by your connections - self.connect_action('list_modules', self.list_modules) - - def list_modules(self): - """Example: use the modules_manager to access the instruments of the Dashboard's experiment""" - self.update_status(f'Actuators: {self.modules_manager.actuators_name}, ' - f'detectors: {self.modules_manager.detectors_name}') - - def do_things_after_experiment_set(self, experiment_name: str, show_dashboard: bool = None): - """Called each time an experiment (the list of instruments) has been set in the Dashboard - - The base class updates self.modules_manager with the new instruments. - """ - super().do_things_after_experiment_set(experiment_name, show_dashboard) - # todo: update your widgets with the new instruments if needed - - def value_changed(self, param): - """ Actions to perform when one of the param's value in self.settings is changed from the - user interface - - For instance: - if param.name() == 'do_something': - if param.value(): - print('Do something') - self.settings.child('main_settings', 'something_done').setValue(False) - - Parameters - ---------- - param: (Parameter) the parameter whose value just changed - """ - pass - - def _quit_fun(self) -> bool: - """Called when the extension is closed. Return True to let it quit, False to refuse (for instance while - running). The base class returns None, which would prevent the extension from closing. - """ - return True - - -def main(): - """Run the extension on its own: loads a Dashboard (hidden), then the extension - - The Dashboard command line options apply, for instance ``-x EXPERIMENT_NAME -s STATE_NAME`` - """ - import sys - from pymodaq_gui.qt_utils import mkQApp - from pymodaq.dashboard import load_dashboard_with_arguments - from pymodaq.utils.gui_utils.loader_utils import create_extension - - app = mkQApp('Custom Ext') - - win, dashboard, _ = load_dashboard_with_arguments(show_dashboard=False, - load_extension=False, - ) - win.mainwindow.setVisible(False) - - win_ext, ext = create_extension(dashboard, CustomExtensionTemplate, show_extension=True) - sys.exit(app.exec()) - - -if __name__ == '__main__': - main() diff --git a/tests/test_plugin_extensions.py b/tests/test_plugin_extensions.py deleted file mode 100644 index 706ba61..0000000 --- a/tests/test_plugin_extensions.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Tests of the Dashboard extensions of the plugin, provided by PyMoDAQ (from version 5.3.7). - -Each extension of the ``extensions`` folder is loaded in an empty Dashboard and closed. Add the tests of the behaviour of -your extensions in this file, with ``loaded_extension`` (from ``pymodaq.utils.plugin_testing``). Delete this file if your -plugin has no extension. -""" -import importlib.util - -import pytest - -try: - available = importlib.util.find_spec('pymodaq.utils.plugin_testing.extension_testing') is not None -except ModuleNotFoundError: # pymodaq is not installed - available = False -if not available: - pytest.skip('The extension checks need PyMoDAQ >= 5.3.7', allow_module_level=True) - -from pymodaq.utils.plugin_testing.extension_testing import PluginExtensionChecks - - -class TestExtensions(PluginExtensionChecks): - # package_name = 'pymodaq_plugins_xxxx' # only if it cannot be found from the pyproject.toml and the package folder - strict_imports = False # True: an extension that cannot be imported (missing dependency) fails instead of being skipped