from PySide2.QtUiTools import QUiLoader from PySide2.QtWidgets import QDialog class MyDialog(QDialog): def __init__(self): super(MyDialog, self).__init__() loader = QUiLoader() self.ui = loader.load("my_dialog.ui") self.ui.button.clicked.connect(self.on_button_clicked) def on_button_clicked(self): # do something when the button is clicked pass
import FreeCADGui from PySide2.QtUiTools import QUiLoader class MyWorkbench: def __init__(self): self.form = self.load_form() def load_form(self): loader = QUiLoader() return loader.load("my_workbench.ui") def GetClassName(self): return "MyWorkbench" def GetResources(self): return {'MenuText': 'My Workbench', 'ToolTip': 'My Workbench Tooltip'} def Activated(self): FreeCADGui.Control.showDialog(self.form) FreeCADGui.addWorkbench(MyWorkbench())In this example, a custom workbench is added to FreeCAD using the FreeCADGui module. The load_form method uses the QUiLoader to load a UI file named "my_workbench.ui" and return the loaded form. The Activated method is called when the workbench is activated, showing the loaded form in a dialog. Package/library: PySide2