On this page:
11.19.1 Corvid Py  Qt5 Addon Instructions
11.19.1.1 Linux or mac  OS Instructions
11.19.1.2 Windows Instructions
11.19.2 Porting from Py  Qt4 to Py  Qt5
11.19.3 Future:   Pyside Addon Instructions
8.5

11.19 Using PyQt5 Addons

11.19.1 Corvid PyQt5 Addon Instructions

Cubit ships with PyQt5 and it is available for use in Cubit automatically. To use a PyQt5 addon, you need to edit the Cubit.ini.

11.19.1.1 Linux or macOS Instructions

Note, the libglib2 library needs to be installed on linux systems for PyQt5 to work properly.

Edit Cubit.ini on linuxvi ~/.config/Coreform/Cubit.ini

Listing 6:

In the [clarofw] section add

Add Python addon on Linuxplugin\addons=/home/USER/custom_corvid_component/custom_corvid_component.CorvidComponent

Listing 7:

11.19.1.2 Windows Instructions

Edit Cubit.ini on Windowsvim C:\Users\USER\AppData\Roaming\Coreform\Cubit.ini

Listing 8:

In the [clarofw] section add

Add Python addon on Windowsplugin\addons=C:/Users/USER/custom_corvid_component/custom_corvid_component.CorvidComponent

Listing 9:

/home/USER/custom_corvid_component/custom_corvid_component is the path to the custom_corvid_component.py module. USER is your username on your machine. .CorvidComponent is "dot" followed by the CorvidComponent class name.

In the custom_corvid_component.py file, you’ll need to define a class with the name you specified above (e.g. CorvidComponent). This class will need, at a minimum, the following functions:

Minimum component class methodsstart_up(self, with_gui: int) -> None clean_up(self) -> None interrupt_progress(self) -> None

Listing 10:

The clean_up function will need to call broker.clean_up_complete. This is needed so that, when Cubit shuts down, the resources associated with your component can be properly cleaned up. Otherwise, Cubit will not be able to successfully shut down. At the top of the file, include the line:

Component import brokerimport broker

Listing 11:

Then, in the clean_up function of the CorvidComponent class, include the line:

Component broker clean upbroker.clean_up_complete("custom_corvid_component")

Listing 12:

custom_corvid_component is the name of the Python file, without the .py extension.

11.19.2 Porting from PyQt4 to PyQt5

The following are some differences between PyQt4 and PyQt5. PyQt4 should be replaced with PyQt5

Changing import statements-import PyQt4.QtCore as qtcore -import PyQt4.QtGui as qtgui -from PyQt4 import uic +import PyQt5.QtCore as qtcore +import PyQt5.QtGui as qtgui +import PyQt5.QtWidgets as QtWidgets +from PyQt5 import uic

Listing 13:

QAction and QToolButton are now part of QtWidgets instead of qtgui.

Changing Function Calls- qtgui.QAction.__init__(self, parent) + QtWidgets.QAction.__init__(self, parent) - qtgui.QToolButton.__init__(self, parent) + QtWidgets.QToolButton.__init__(self, parent) - spaceX = self.spacing() + wid.style().layoutSpacing(qtgui.QSizePolicy.PushButton, qtgui.QSizePolicy.PushButton, qtcore.Qt.Horizontal) - spaceY = self.spacing() + wid.style().layoutSpacing(qtgui.QSizePolicy.PushButton, qtgui.QSizePolicy.PushButton, qtcore.Qt.Vertical) + spaceX = self.spacing() + wid.style().layoutSpacing(QtWidgets.QSizePolicy.PushButton, QtWidgets.QSizePolicy.PushButton, qtcore.Qt.Horizontal) + spaceY = self.spacing() + wid.style().layoutSpacing(QtWidgets.QSizePolicy.PushButton, QtWidgets.QSizePolicy.PushButton, qtcore.Qt.Vertical)

Listing 14:

Instead of calling connect on QObject, connect is called on the object being connected (in this case tbolt).

Porting connect() # Set up connections - qtcore.QObject.connect(tbolt.gbox_advanced , qtcore.SIGNAL(’toggled(bool)’) , self.check_hex_round_advanced) - qtcore.QObject.connect(tbolt.radio_hex , qtcore.SIGNAL(’toggled(bool)’) , self.check_hex_round_advanced) - qtcore.QObject.connect(tbolt.but_boltgen , qtcore.SIGNAL(’clicked()’) , self.on_make_bolt ) + #qtcore.QObject.connect(tbolt.gbox_advanced , qtcore.SIGNAL(’toggled(bool)’) , self.check_hex_round_advanced) + tbolt.gbox_advanced.toggled.connect(self.check_hex_round_advanced) + #qtcore.QObject.connect(tbolt.radio_hex , qtcore.SIGNAL(’toggled(bool)’) , self.check_hex_round_advanced) + tbolt.radio_hex.toggled.connect(self.check_hex_round_advanced) + #qtcore.QObject.connect(tbolt.but_boltgen , qtcore.SIGNAL(’clicked()’) , self.on_make_bolt ) + tbolt.but_boltgen.clicked.connect(self.on_make_bolt)

Listing 15:

11.19.3 Future: Pyside Addon Instructions

cd /home/USER/cubit/build/claro/bin/python3/bin ./pip3 install pside2

Listing 16: