Creare l'interfaccia
Introduzione
Gli utenti esperti hanno la possibilità di creare delle interfacce che li aiutino a produrre strumenti complessi per i loro addon personalizzati, come le macro o interi ambienti .
Le interfacce vengono create usando PySide, che è una libreria per l'utilizzo di Qt con Python.
Due metodi generali per creare delle interfacce, includendo l'interfaccia nel file Python o usando i file .ui
.
Descrizione
Esistono in genere due modi per creare delle interfacce con PySide.
Interface in a .ui file
In this method the interface is defined in a .ui
file (an XML document that defines the structure of the interface), which is then imported into Python code that uses it. This is the recommended approach.
- It allows the programmer to work with the graphical interface separately from the logic that will use it.
- It allows anybody to look at the interface alone, that is, the
.ui
file, without having to run Python code. - The
.ui
file may be designed by anybody without programming knowledge. - The
.ui
interface can be used in a standalone window (modal), or in an embedded window (non-modal); therefore, this method is ideal to create custom task panels. - Since the
.ui
file just describes the "appearance" of the interface, it does not need to be tied to a particular programming language; it may be used both in Python and C++ code.
For examples on this method see Interface creation with UI files.
Interface completely in Python code
In this method the entire interface is defined by several Python calls.
- This is an older way of working with interfaces.
- This method produces very verbose code because many details of the interface need to be specified by hand.
- It is not simple to separate the interface from the logic that uses that code, meaning that a user would need to run the Python file in the correct context in order to see how the interface would look.
- This method has the advantage that several interfaces may be contained within a single document, at the expense of making the file very large.
- This method is recommended only for small interfaces that don't define more than a few widgets, for example in macros.
For examples on this method see Interface creation completely in Python.
- FreeCAD scripting: Python, Introduction to Python, Python scripting tutorial, FreeCAD Scripting Basics
- Modules: Builtin modules, Units, Quantity
- Workbenches: Workbench creation, Gui Commands, Commands, Installing more workbenches
- Meshes and Parts: Mesh Scripting, Topological data scripting, Mesh to Part, PythonOCC
- Parametric objects: Scripted objects, Viewproviders (Custom icon in tree view)
- Scenegraph: Coin (Inventor) scenegraph, Pivy
- Graphical interface: Interface creation, Interface creation completely in Python (1, 2, 3, 4, 5), PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Embedding: Embedding FreeCAD, Embedding FreeCADGui
- Other: Expressions, Code snippets, Line drawing function, FreeCAD vector math library (deprecated)
- Hubs: User hub, Power users hub, Developer hub