Module Programming

From SweepMe! Wiki
Jump to navigation Jump to search

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:

  1. creating a python script
  2. 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.
  3. creating a Qwidget, QDialog, or QMainwindow as your main widget
  4. creating a function that return a layout. This function could have the name "create_MainLayout"
  5. setting your layout to your corresponding main widget
  6. running everything using QApplication
  7. 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:

  1. onVisibilityChanged(self): The tab of the module toggles visibility.
  2. onSettingLoaded(self): Loading a setting is completed.
  3. onStarted(self): SweepMe! has started.
  4. 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:

  1. get_CustomSetting(self): return a list strings. These strings you will get back when the setting is loaded by the function set_CustomSetting
  1. 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.