Graphical User Interface (gui package)

Module contents

The scripts in this directory are designed to work separately from the main program. Therefore, it is possible to run them without relying on interaction between all other GUI elements which are necessary for the finished software.

We tried to design the software in the most modular way we could think of while keeping it as simple and easy to use for freshly baked python programmers in the field of science.

The general idea is to use the Qt designer, generate one feature of the GUI, breathe life into it and later implement it together with other individually running GUI features.

General procedure to generate a GUI feature:

Note

This small guide assumes that general knowledge about Qt and the designer tool are already present (e.g. build your own small GUI with it and connect it to a program). See references if additional knowledge or a small starting point are needed.

  1. Open the anaconda3 console and type designer (given that the designer and Qt are installed properly)

  2. Start by creating a groupBox widget (i.e. see pi_control.ui in designer)

  3. Place the GUI elements that you want to have into the groupBox and name the elements properly since this will be important when connecting the logic to your widget. Important: Add good tooltips to the widget elements. These can be used by the user for information purposes.

  4. When the design is done and you checked that the design fits the already existing one, you can transform the .ui file into a ui.py file. For that you need to do the following:

    • E.g. pi_control.ui:

    • Open anaconda terminal (or one that you use)

    • Navigate to the correct directory and type “pyuic5 pi_control.ui -o ui_pi_control.py”

  5. Now a python file exists which represents the design of your GUI feature/element. This python file can be imported and used to program the necessary features into it

  6. For that purpose create a new script called e.g. widget_pi_controll.py

The actual hard part is to provide the functionality to the GUI feature/element because it requires some practice and knowledge about certain aspects of pyqt. A good orientation is provided with the widget_analog_digital_converter.py and the widget_pi_control.py scripts. The ideas behind the features can be taken from there.

Note

Note that the ADC is easier to understand and that any widget_xx.py script can and should be looked at when implementing something new, just to be sure.

  1. When the GUI feature/element runs, it may be necessary to implement it into a bigger GUI/a main GUI

  2. For that a main window should be created in the designer. Depending on what type of widgets were build for the standalone elements (here groupBoxes were used) it is necessary to place (in this example) empty groupBoxes onto the main window

  3. When the groupBox is placed it needs to be promoted by right clicking onto it. The class name should be e.g. WidgetPiControl and the include file should be e.g. widget_pi_control.h

  4. The procedure of compiling the main window is the same as described above. The logic has to be implemented as well to provide interaction or similar (For that an additional explanation is given in widget_main_window. This should be carefully studied)

Adding a sub feature into a specific GUI element works the same way as for a completely new one. E.g. if an additional lineEdit is needed in widget_pi_control.py it is necessary to use the designer to put the lineEdit into the desired .ui file. Compile the ui.py file. Add the logic in the widget.py file. Add the function in the widget_main_window.py file.

General structure of a widget.py file:

Import necessary modules:

  1. PyQt specific modules (i.e. QtWidgets).

  2. Threading modules (depends if only qt threading or also python threading is required).

  3. regex_validators which are needed to limit the input which a use can give.

  4. qt_multithreading_wrapper to have the functionality of requesting attributes for updating values.

  5. The ui.py design file.

  6. The necessary classes for the given GUI feature (i.e. pi_control)

Class with the same name that was provided in the promotion via the designer (i.e. WidgetPiControl). The class should inherit the features of the QGroupBox (in this example) and the Ui file (to have the designed GUI itself):

  1. Note that some GUI features need hardware classes to work. The hardware classes need to be passed as an argument in the init (please see widget_pi_control.py and widget_analog_digital_converter.py for further comments and how to apply this because it is not trivial)

  2. Setting input validators with regex

  3. Setting signals for buttons etc.

  4. Have methods which provide enable/ disable functions to limit user interactions while something is happening

  5. Have update methods which update the GUI elements after certain actions

  6. Have a work method which is needed to compare the attributes from the hardware class and the currently set lineEdit values

References

See also

  • widget_pi_control.py

  • widget_analog_digital_converter.py

  • widget_main_window.py