-
Notifications
You must be signed in to change notification settings - Fork 140
Dynamically load graphical interface definition
Gaël Écorchard edited this page Jun 1, 2021
·
2 revisions
In order to reduce the number of lines in macros with graphical interfaces it is better to define the graphical interface in a ui
file that is loaded at runtime. Cf. https://github.com/FreeCAD/FreeCAD-macros/blob/master/FEM/FemAnimateModeShapes.FCMacro as an example.
Things to do:
- Design you graphical interface with Qt Designer
- Add the
ui
file to the__Files__
variable in the metadata - In the macro
import FreeCADGui as gui
- Later in the macro
ui = gui.PySideUic.loadUi('relative_path_to_ui_file')
orform, widget = gui.PySideUic.loadUiType('relative_path_to_ui_file')
Running form, widget = gui.PySideUic.loadUiType('relative_path_to_ui_file')
with FreeCAD v0.19 on Ubuntu 20.04 requires the manual installation of pyside2uic
from PySide2-tools. Commands to be executed in the terminal:
cd /tmp
git clone https://github.com/pyside/pyside2-tools
mkdir build && cd build
cmake ..
make
sudo make install
sudo mv /usr/local/lib/python3/dist-packages/pyside2uic /usr/local/lib/python3.8/dist-packages