8.2 Adding Command Panels to the GUI
Users are able to create new command panels using https://www.qt.io/download, then add those panels to the navigation XML. The finished panels will be displayed along with the standard Cubit panels and will launch python scripts when the user clicks ’Apply’ or ’Preview’. This tutorial will show the reader how to add a command panel that creates a "Brick with Hole".
8.2.1 Create a directory to store command panels
Create a directory to store command panels
Each panel requires a subdirectory in this main directory
Navigate to Tools/Options/Command Panels and point Cubit to his new directory.
8.2.2 Create a directory for the new command panel
Within the CustomPanels directory create a subdirectory for a new panel. The name is not important
Eventually, this directory will contain the following files:
marker.txt - continas the navigation XML marker name
panel.ui - the Qt UI description file
apply.py - python script to run when "Apply" is clicked by the user
preview.py - [optional] python script to run when the user clicks "Preview"
Note: if this file is missing, the Preview button will automatically be removed
8.2.3 Navigation Marker
Open one of the navigation XML files
In the Cubit installation directory, find and open bin/xml/action-based-xml/GeometryCreateNavigation.xml
Insert your panel marker
Copy/paste the Brick NavigationNode and modify with your panel details:
Save the XML file
Restart Cubit for the changes to take effect
The Brick with Hole panel will now appear in the button hierarchy but the panel will have no contents because we have not yet created a panel.ui file.
8.2.4 Create Panel UI
Cubit is built using Qt 5 (see qt.io for more info)
Qt Designer is required to make a .ui file
This is available as part of the standard Qt download OR
Available from Coreform upon request
Use Qt Designer to create a new widget with two line edits (see the example below)
Tip: Remember to add a layout to the widget so it formats properly
Save the file as panel.ui in the BrickWithHole directory we created earlier
In Cubit, right-click on the panel where it says "No panel contents to display" and choose "Reset Data".
The new custom panel should now appear.
Tip: The panel.ui file is reloaded when "Reset Data" is executed. This allows you to modify the ui layout without restarting Cubit.
8.2.5 Panel UI Widgets
Values for the panel widgets can be retrieved in Python for the following types of widgets:
Pick Widget (aka selection widget)
Line edit
Combo box
Radio button
Check box
Spin box (integers)
Double spin box (decimals)
Sliders
Values are retrieved using the widget’s name, as specified in the panel.ui file.
8.2.5.1 Pick Widget
Pick widgets are not part of the default Qt toolkit. They are created by the developers of Cubit to interact specifically with the graphics engine of Cubit
To create a pick widget, use a line edit and give it a name following the pattern: pw<type>_...
For example, to create a volume pick widget, name the line edit something like "pwvolume_something".
Cubit will automatically convert the line edit to a pick widget when the UI is loaded
Note that the name IS case-sensitive
8.2.5.2 Pick Types
|
|
|
|
|
8.2.6 Apply Script
With the panel UI complete we are now ready to implement the panel’s apply script.
In the BrickWithHole directory, create a new file called ’apply.py" and add the following contents:
Save apply.py, then in Cubit, set values for the brick size and cylinder radius in the panel and click "Apply" to create a brick with a hole in it.
8.2.7 UserPanel Functions
The following functions are available in the cubitgui.UserPanel class to get UI values in Python:
pick_widget_text(name) -> string
pick_widget_type(name) -> string
line_edit_text(name) -> string
combo_box_text(name) -> string
radio_button_is_checked(name) -> bool
check_box_is_checked(name) -> bool
spin_box_value(name) -> int
double_spin_box_value(name) -> float
slider_value(name) -> int
8.2.8 Preview Script
To enable the Preview button in a custom panel, simply create the file preview.py in the panel’s directory and add the code to execute.
Reset the panel and the preview button should appear.
Note that not all commands in Cubit will have a preview option, so this button may have limited use.