Module Programming: Difference between revisions
No edit summary |
Franz Hempel (talk | contribs) mNo edit summary |
||
(10 intermediate revisions by one other user not shown) | |||
Line 14: | Line 14: | ||
== Basic steps == | == Basic steps == | ||
===Create the GUI === | |||
GUI elements are arranged in a layout which is loaded into the Tab that comes with every Module. You can create such a layout independent from SweepMe! by: | GUI elements are arranged in a layout which is loaded into the Tab that comes with every Module. You can create such a layout independent from SweepMe! by: | ||
# creating a python script | # creating a python script | ||
Line 25: | Line 25: | ||
If everything is nice, you can copy the function "create_MainLayout" to a module. | If everything is nice, you can copy the function "create_MainLayout" to a module. | ||
To automatically save the user configuration of your module to the settings, you can define an ordered dictionary that must be named 'self.GUIwidget'. Connect string-keys with the GUI objects such as QLineEdit, QComboBox, QCheckBox etc. SweepMe! will save the content of each basic GUI object to the setting whenever a user saves a setting. When a setting is loaded, SweepMe! restores the content of each basic GUI object. | |||
Caution: There are some keys that are reserved, e.g. "Label", "Port", "Device" that should not be used to link them to any GUI object that has a different purpose. | |||
=== Define actions === | === Define actions === | ||
Line 36: | Line 39: | ||
You can add these functions to your module and fill them with the code that should be executed. | You can add these functions to your module and fill them with the code that should be executed. | ||
=== Link functions === | === Link functions === | ||
If a measurement is started, SweepMe! will run a well-defined set of functions ([[sequencer procedure | sequencer functions]]). In this step, you have to tell SweepMe! what should be done. | If a measurement is started, SweepMe! will run a well-defined set of functions ([[sequencer procedure |sequencer functions]]). In this step, you have to tell SweepMe! what should be done. | ||
=== Settings === | === Settings === | ||
How the user configures the module must be saved to and loaded from the setting file. One possibility is to link GUI widgets to a dictionary and SweepMe! will automatically save and load information for basic widgets such as QLineEdit, QComboBox, QCheckbex, etc. as described above. | |||
However, it might be that you create complex widgets and functionalities that makes it necessary to additionally save and load your own setting properties. There are two functions to do so: | However, it might be that you create complex widgets and functionalities that makes it necessary to additionally save and load your own setting properties. There are two functions to do so: | ||
Line 53: | Line 54: | ||
Both function have to be used pairwise. What you define in get_CustomSetting, defines what you get from get_CustomSetting. | Both function have to be used pairwise. What you define in get_CustomSetting, defines what you get from get_CustomSetting. | ||
=== Test your module === | === Test your module === | ||
Try to combine it with other modules and see whether it nicely interacts. | Try to combine it with other modules and see whether it nicely interacts. |
Latest revision as of 14:07, 17 January 2024
Almost any functionality can be added to SweepMe! on the Module level.
Requirements
The basic libraries to create a Module are Qt5 in combination with PySide2.
To program own modules, you need a license key. Modules can deeply interact with the entire program so that specific knonwledge is needed. Please contact us (contact@sweep-me.net) to speak about possible approaches.
Philosophy
Modules are modular pieces. They have to be designed in a way to be able to work with all other modules. It is not recommended to put a final end user application into a module, even though it would be possible. It would be better to embed functionalities into a module that are useful for many different things. At the same time, tasks that belong to each other, should be grouped and incorporated to the module. Figuring out where to split functions is something we can help you with.
Basic steps
Create the GUI
GUI elements are arranged in a layout which is loaded into the Tab that comes with every Module. You can create such a layout independent from SweepMe! by:
- creating a python script
- importing PySide2 using "from PySide2 import QtWidgets, QtCore, QtGui". This way you ensure to call each object of PySide2 the way we are doing it.
- creating a Qwidget, QDialog, or QMainwindow as your main widget
- creating a function that return a layout. This function could have the name "create_MainLayout"
- setting your layout to your corresponding main widget
- running everything using QApplication
- testing the look and feel
If everything is nice, you can copy the function "create_MainLayout" to a module.
To automatically save the user configuration of your module to the settings, you can define an ordered dictionary that must be named 'self.GUIwidget'. Connect string-keys with the GUI objects such as QLineEdit, QComboBox, QCheckBox etc. SweepMe! will save the content of each basic GUI object to the setting whenever a user saves a setting. When a setting is loaded, SweepMe! restores the content of each basic GUI object. Caution: There are some keys that are reserved, e.g. "Label", "Port", "Device" that should not be used to link them to any GUI object that has a different purpose.
Define actions
There are some events where SweepMe! calls certain functions of a module:
- onVisibilityChanged(self): The tab of the module toggles visibility.
- onSettingLoaded(self): Loading a setting is completed.
- onStarted(self): SweepMe! has started.
- onLayoutCreated(self): The layout of the module has been loaded after creation of the module.
You can add these functions to your module and fill them with the code that should be executed.
Link functions
If a measurement is started, SweepMe! will run a well-defined set of functions (sequencer functions). In this step, you have to tell SweepMe! what should be done.
Settings
How the user configures the module must be saved to and loaded from the setting file. One possibility is to link GUI widgets to a dictionary and SweepMe! will automatically save and load information for basic widgets such as QLineEdit, QComboBox, QCheckbex, etc. as described above.
However, it might be that you create complex widgets and functionalities that makes it necessary to additionally save and load your own setting properties. There are two functions to do so:
- get_CustomSetting(self): return a list strings. These strings you will get back when the setting is loaded by the function set_CustomSetting
- set_CustomSetting(self, content): This function is called when the setting is loaded and a custom entry is found. The function handsover an object called 'content' which is a list of strings separated by tabs, according to one item you added using get_CustomSetting.
Both function have to be used pairwise. What you define in get_CustomSetting, defines what you get from get_CustomSetting.
Test your module
Try to combine it with other modules and see whether it nicely interacts.