PyQt is one of the most popular Python bindings for the Qt cross-platform C++ framework. Let us make a simple GUI to make a signal demodulator.
This is an example of the PyQT designer window. Select and create a MainWindow. There are various widgets on the left, object lists on the top right, various properties of the selected object in the center right, and signal/slot editing windows on the bottom right.
Now imagine the UI you want to create. Suppose you insert the file you want to demodulate, and you create an automatic processing program that generates a demodulated bit file.
Adjust the size of the main window appropriately, and drag and place the necessary widgets from the left widget box. Add line edit where the I/O file name will be entered, push button to be an execution button such as file search, etc.
Various objects would have been added to the upper right object inspector. It is recommended to change the object name so that it is easy to check later. (e.g., buttobOK, inputFileName, etc.)
In the object inspector or center window, you can use the property editor in the center right by clicking on the desired object. In Designer, it is desirable to change only the appearance, such as size, and programmatic processing is handled in the main.py Python code.
The signal/slot editor at the lower right deals with the signal of qt. When a signal (e.g., clicked()) of a specific object is connected to a slot (e.g., closed())), the signal executes an action corresponding to the slot when the signal is detected.
Once you have created the UI shell with Designer, save and exit. After that, turn on the terminal on the path where the saved ui file is located and run the following command:
pyuic4 sample.ui -o ui.py -x
It is a command that makes the UI file an importable Python script. A file is created as the name after -o, and if you insert the -x factor, it is created in a form that allows independent execution. Let’s run the file on Python and check it out.
Now that we’ve created the UI, it’s time to write the main script. Depending on the size of the program, the script structure is written as desired, but the basic framework is as follows:
- Class declaration
If you look at ui.py generated by pyuic4, a class will be created as the name specified in the above designator: classUi_sample(object). It was created under the name UI. Later QtGui.We created a custom class called MainWindowWithEvent, which is a prototype of QMainWindow. This is to use the event. There are various events in Qt. It is a method that uses the most common keyPress Event, although there are various types such as window resize and mouse click. There are various values defined in QtCore.Qt, so refer to documentation.
- Signals and Slots
QtCore.Qobject.connect(UI.quitButton, QtCore.SIGNAL('clicked()'),quit)
It is the most common signal-slot usage. Object called TryButton in UI (QtGui).When QPushButton) is clicked, process() is executed. There are various methods of using a custom slot.
- Property usage
For instance, QPushButton, commonly used in the GUI, has various properties and methods.
UI.buttonA.setDisabled(True)
Disable the corresponding button. It can be enabled with setEnabled.
UI.buttonB.setChecked(True)
The corresponding button becomes clicked. If you insert False, it will not be clicked.
UI.buttonC.isChecked(True)
Returns a boolean value indicating whether it is a clicked state.
UI.buttonD.setText(str)
Show the value in str on the button.
Now let’s make a GUI for signal demodulation in-depth.
When the python code is executed on terminal, the demodulator GUI as follows is executed.
[References]
- https://en.wikipedia.org/wiki/PyQt
- https://wikidocs.net/35478
- Sample image from: http://edadownload.software.keysight.com/eedl/ads/2011_01/pdf/dgblue.pdf