Module Programming: Difference between revisions

From SweepMe! Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Almost any functionality can be added to SweepMe! on the Module level.
Almost any functionality can be added to SweepMe! on the Module level.
=== Requirements ===
The basic libraries to create a Module are [https://doc.qt.io/qt-5/qt5-intro.html Qt5] in combination with [https://wiki.qt.io/Qt_for_Python 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 ===
=== Basic steps ===


The basic libraries to create a Module are [https://doc.qt.io/qt-5/qt5-intro.html Qt5] in combination with [https://wiki.qt.io/Qt_for_Python PySide2].  
==== 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 procedure | 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.  


To program own modules, you need a license key. Please contact us here: contact@sweep-me.net
Both function have to be used pairwise. What you define in get_CustomSetting, defines what you get from get_CustomSetting.
       


# 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 script with a function that returns a layout.
==== Test your module ====
# Define actions: Whenever the Module changes visibility, is loaded by a setting or after the start of the program, you need to define functions if needed.
Try to combine it with other modules and see whether it nicely interacts.
# Link to [[sequencer procedure | sequencer functions]]: If a measurement is started, SweepMe! will run a well-defined set of functions. In this step, you have to tell SweepMe! what should be done.
# Test your Module: Try to combine it with other modules and see whether it can interact.

Revision as of 07:07, 26 October 2019

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.

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

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:

  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.