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
2022.4+26187-e1209cf7 Apr 14, 2022

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.

vi ~/.config/Coreform/Cubit.ini

Figure 548: Edit Cubit.ini on linux

In the [clarofw] section add

plugin\addons=/home/USER/custom_corvid_component/custom_corvid_component.CorvidComponent

Figure 549: Add Python addon on Linux

11.19.1.2 Windows Instructions

vim C:\Users\USER\AppData\Roaming\Coreform\Cubit.ini

Figure 550: Edit Cubit.ini on Windows

In the [clarofw] section add

plugin\addons=C:/Users/USER/custom_corvid_component/custom_corvid_component.CorvidComponent

Figure 551: Add Python addon on Windows

/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:

start_up(self, with_gui: int) -> None clean_up(self) -> None interrupt_progress(self) -> None

Figure 552: Minimum component class methods

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:

import broker

Figure 553: Component import broker

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

broker.clean_up_complete("custom_corvid_component")

Figure 554: Component broker clean up

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

-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

Figure 555: Changing import statements

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

- 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)

Figure 556: Changing Function Calls

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

# 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)

Figure 557: Porting connect()

11.19.3 Future: Pyside Addon Instructions

./pip3 install pside2

Figure 558: