Module Programming
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.
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
The setting a user does 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.