Skip to content

Commit 3773532

Browse files
committed
create dedicated templates for custom apps and extensions
introduced functionnalities require pymodaq >= 4.3.0 for this template to fully work (at least for apps and extensiosn)
1 parent 9639a59 commit 3773532

File tree

4 files changed

+133
-196
lines changed

4 files changed

+133
-196
lines changed

plugin_info.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = 'MIT'
1313

1414
[plugin-install]
1515
#packages required for your plugin:
16-
packages-required = ['pymodaq>=4.1.0']
16+
packages-required = ['pymodaq>=4.3.0']
1717

1818
[features] # defines the plugin features contained into this plugin
1919
instruments = true # true if plugin contains instrument classes (else false, notice the lowercase for toml files)

src/pymodaq_plugins_template/app/custom_app_template.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from qtpy import QtWidgets
22

33
from pymodaq.utils import gui_utils as gutils
4+
from pymodaq.utils.config import Config
5+
from pymodaq.utils.logger import set_logger, get_module_name
46

57
# todo: replace here *pymodaq_plugins_template* by your plugin package name
68
from pymodaq_plugins_template.utils import Config as PluginConfig
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
from qtpy import QtWidgets
2+
3+
from pymodaq.utils import gui_utils as gutils
4+
from pymodaq.utils.config import Config, get_set_preset_path
5+
from pymodaq.utils.logger import set_logger, get_module_name
6+
7+
# todo: replace here *pymodaq_plugins_template* by your plugin package name
8+
from pymodaq_plugins_template.utils import Config as PluginConfig
9+
10+
logger = set_logger(get_module_name(__file__))
11+
12+
main_config = Config()
13+
plugin_config = PluginConfig()
14+
15+
# todo: modify this as you wish
16+
EXTENSION_NAME = 'MY_EXTENSION_NAME' # the name that will be displayed in the extension list in the
17+
# dashboard
18+
CLASS_NAME = 'CustomExtensionTemplate' # this should be the name of your class defined below
19+
20+
21+
# todo: modify the name of this class to reflect its application and change the name in the main
22+
# method at the end of the script
23+
class CustomExtensionTemplate(gutils.CustomApp):
24+
25+
# todo: if you wish to create custom Parameter and corresponding widgets. These will be
26+
# automatically added as children of self.settings. Morevover, the self.settings_tree will
27+
# render the widgets in a Qtree. If you wish to see it in your app, add is into a Dock
28+
params = []
29+
30+
def __init__(self, parent: gutils.DockArea, dashboard):
31+
super().__init__(parent, dashboard)
32+
33+
# info: in an extension, if you want to interact with ControlModules you have to use the
34+
# object: self.modules_manager which is a ModulesManager instance from the dashboard
35+
36+
self.setup_ui()
37+
38+
def setup_docks(self):
39+
"""Mandatory method to be subclassed to setup the docks layout
40+
41+
Examples
42+
--------
43+
>>>self.docks['ADock'] = gutils.Dock('ADock name')
44+
>>>self.dockarea.addDock(self.docks['ADock'])
45+
>>>self.docks['AnotherDock'] = gutils.Dock('AnotherDock name')
46+
>>>self.dockarea.addDock(self.docks['AnotherDock'''], 'bottom', self.docks['ADock'])
47+
48+
See Also
49+
--------
50+
pyqtgraph.dockarea.Dock
51+
"""
52+
# todo: create docks and add them here to hold your widgets
53+
# reminder, the attribute self.settings_tree will render the widgets in a Qtree.
54+
# If you wish to see it in your app, add is into a Dock
55+
raise NotImplementedError
56+
57+
def setup_actions(self):
58+
"""Method where to create actions to be subclassed. Mandatory
59+
60+
Examples
61+
--------
62+
>>> self.add_action('Quit', 'close2', "Quit program")
63+
>>> self.add_action('Grab', 'camera', "Grab from camera", checkable=True)
64+
>>> self.add_action('Load', 'Open', "Load target file (.h5, .png, .jpg) or data from camera"
65+
, checkable=False)
66+
>>> self.add_action('Save', 'SaveAs', "Save current data", checkable=False)
67+
68+
See Also
69+
--------
70+
ActionManager.add_action
71+
"""
72+
raise NotImplementedError(f'You have to define actions here')
73+
74+
def connect_things(self):
75+
"""Connect actions and/or other widgets signal to methods"""
76+
raise NotImplementedError
77+
78+
def setup_menu(self):
79+
"""Non mandatory method to be subclassed in order to create a menubar
80+
81+
create menu for actions contained into the self._actions, for instance:
82+
83+
Examples
84+
--------
85+
>>>file_menu = self.mainwindow.menuBar().addMenu('File')
86+
>>>self.affect_to('load', file_menu)
87+
>>>self.affect_to('save', file_menu)
88+
89+
>>>file_menu.addSeparator()
90+
>>>self.affect_to('quit', file_menu)
91+
92+
See Also
93+
--------
94+
pymodaq.utils.managers.action_manager.ActionManager
95+
"""
96+
# todo create and populate menu using actions defined above in self.setup_actions
97+
pass
98+
99+
def value_changed(self, param):
100+
""" Actions to perform when one of the param's value in self.settings is changed from the
101+
user interface
102+
103+
For instance:
104+
if param.name() == 'do_something':
105+
if param.value():
106+
print('Do something')
107+
self.settings.child('main_settings', 'something_done').setValue(False)
108+
109+
Parameters
110+
----------
111+
param: (Parameter) the parameter whose value just changed
112+
"""
113+
pass
114+
115+
116+
def main():
117+
from pymodaq.utils.gui_utils.utils import mkQApp
118+
from pymodaq.utils.gui_utils.loader_utils import load_dashboard_with_preset
119+
120+
121+
app = mkQApp(EXTENSION_NAME)
122+
preset_file_name = plugin_config('presets', f'preset_for_{EXTENSION_NAME}')
123+
124+
load_dashboard_with_preset(preset_file_name, EXTENSION_NAME)
125+
126+
app.exec()
127+
128+
129+
if __name__ == '__main__':
130+
main()

src/pymodaq_plugins_template/extensions/myextension.py

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)