Interface creation/it: Difference between revisions

From FreeCAD Documentation
No edit summary
(Created page with "Con questo metodo l'interfaccia è definita in un file {{incode|.ui}} (un documento XML che definisce la struttura dell'interfaccia), che viene poi importato nel codice Pyth...")
Line 23: Line 23:
=== Interfaccia in un file .ui ===
=== Interfaccia in un file .ui ===


In this method the interface is defined in a {{incode|.ui}} file (an XML document that defines the structure of the interface), which is then imported into [[Python|Python]] code that uses it. This is the recommended approach.
Con questo metodo l'interfaccia è definita in un file {{incode|.ui}} (un documento XML che definisce la struttura dell'interfaccia), che viene poi importato nel codice [[Python|Python]] che lo utilizza. Questo è l'approccio consigliato.
* Consente al programmatore di lavorare con l'interfaccia grafica separatamente dalla logica che la utilizzerà.
* 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 {{incode|.ui}} file, without having to run Python code.
* Permette a chiunque di guardare solo l'interfaccia, cioè il file {{incode|.ui}}, senza dover eseguire codice Python.
* The {{incode|.ui}} file may be designed by anybody without programming knowledge.
* Il file {{incode|.ui}} può essere progettato da chiunque non abbia conoscenze di programmazione.
* The {{incode|.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_panel|task panels]].
* L'interfaccia {{incode|.ui}} può essere utilizzata in una finestra autonoma (modale) o in una finestra incorporata (non modale); pertanto, questo metodo è ideale per creare [[Task_panel|task panel]].
* Since the {{incode|.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|Python]] and C++ code.
* Dato che il file {{incode|.ui}} descrive solo "l'aspetto" dell'interfaccia, non ha bisogno di essere legato a un particolare linguaggio di programmazione; può essere utilizzato sia nel codice [[Python|Python]] che in quello C++.


=== Interfaccia completamente in codice Python ===
=== Interfaccia completamente in codice Python ===

Revision as of 16:40, 18 December 2022

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.

Interfaccia in un file .ui

Con questo metodo l'interfaccia è definita in un file .ui (un documento XML che definisce la struttura dell'interfaccia), che viene poi importato nel codice Python che lo utilizza. Questo è l'approccio consigliato.

  • Consente al programmatore di lavorare con l'interfaccia grafica separatamente dalla logica che la utilizzerà.
  • Permette a chiunque di guardare solo l'interfaccia, cioè il file .ui, senza dover eseguire codice Python.
  • Il file .ui può essere progettato da chiunque non abbia conoscenze di programmazione.
  • L'interfaccia .ui può essere utilizzata in una finestra autonoma (modale) o in una finestra incorporata (non modale); pertanto, questo metodo è ideale per creare task panel.
  • Dato che il file .ui descrive solo "l'aspetto" dell'interfaccia, non ha bisogno di essere legato a un particolare linguaggio di programmazione; può essere utilizzato sia nel codice Python che in quello C++.

Interfaccia completamente in codice Python

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.

Per esempi su questo metodo vedi Creare delle finestre di dialogo.