PySide/it: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
<languages/>
<languages/>

<div class="mw-translate-fuzzy">
{{docnav/it|[[Pivy/it|Pivy]]|[[FeaturePython Objects/it|Ogetti FeaturePython]]}}
{{docnav/it|[[Pivy/it|Pivy]]|[[FeaturePython Objects/it|Ogetti FeaturePython]]}}
</div>

{{TOCright}}


<div class="mw-translate-fuzzy">
<div class="mw-translate-fuzzy">
Line 10: Line 15:
</div>
</div>


When you install FreeCAD, you should get both Qt and PySide as part of the package. If you are [[Compiling|compiling]] yourself then you must verify that these two libraries are installed in order for FreeCAD to run correctly. Of course, PySide will only work if Qt is present.
== PySide in FreeCAD with Qt5 ==

In the past, FreeCAD used PyQt, another Qt binding for Python, but in 2013 ([https://github.com/FreeCAD/FreeCAD/commit/1dc122dc9a 1dc122dc9a]) the project migrated to PySide because it has a more permissible [[licence|license]].

For more information see:
* [http://en.wikipedia.org/wiki/PySide Wikipedia:PySide]
* [http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt]

[[File:PySideScreenSnapshot1.jpg]] [[File:PySideScreenSnapshot2.jpg]]
{{Caption|Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.}}

==PySide in FreeCAD with Qt5==


FreeCAD was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, FreeCAD transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.
FreeCAD was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, FreeCAD transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.


Normally, the {{incode|PySide}} module provides support for Qt4, while {{incode|PySide2}} provides support for Qt5. However, in FreeCAD, there is no need to use {{incode|PySide2}} directly, as a special {{incode|PySide}} module is included to handle Qt5.
Normally, the {{incode|PySide}} module provides support for Qt4, while {{incode|PySide2}} provides support for Qt5. However, in FreeCAD there is no need to use {{incode|PySide2}} directly, as a special {{incode|PySide}} module is included to handle Qt5.


This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of FreeCAD compiled for Qt5.
This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of FreeCAD compiled for Qt5.
Line 21: Line 37:
}}
}}


This module just imports the necessary classes from {{incode|PySide2}}, but places them in the {{incode|PySide}} namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as it imports {{incode|PySide}}.
This module just imports the necessary classes from {{incode|PySide2}}, and places them in the {{incode|PySide}} namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as we use the single {{incode|PySide}} module.
{{Code|code=
{{Code|code=
PySide2.QtCore -> PySide.QtCore
PySide2.QtCore -> PySide.QtCore
Line 33: Line 49:
PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox
PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox
}}
}}
{{Top}}]


==Examples of PySide use==
== PySide information ==

Spesso gli utenti di FreeCAD accedono a tutto tramite l'interfaccia integrata. Per gli utenti che desiderano personalizzare le loro operazioni esiste l'interfaccia Python, che è documentata nel [[Python_scripting_tutorial/it|Tutorial degli script Python]]. L'interfaccia Python di FreeCAD è molto flessibile e potente. Questa pagina documenta l'interazione di Python con FreeCAD tramite PySide.

Python offre la dichiarazione 'print', data dal codice:
{{Code|code=
print 'Hello World'
}}
Con l'istruzione print di Python si ha solo un limitato controllo dell'aspetto e del comportamento. PySide fornisce il controllo mancante e gestisce anche gli ambienti dove le funzionalità incorporate in Python non sono sufficienti, come ad esempio i file dell'ambiente macro di FreeCAD.

Le funzionalità di PySide vanno da:

[[File:PySideScreenSnapshot1.jpg]]

a:

[[File:PySideScreenSnapshot2.jpg]]


<div class="mw-translate-fuzzy">
'''Per acquisire familiarità con alcuni esempi reali di PySide'''
'''Per acquisire familiarità con alcuni esempi reali di PySide'''
* [[PySide Beginner Examples/it|Esempi di livello base di PySide]] (Hello World, avvisi, inserire un testo, inserire un numero)
* [[PySide Beginner Examples/it|Esempi di livello base di PySide]] (Hello World, avvisi, inserire un testo, inserire un numero)
* [[PySide Intermediate Examples/it|Esempi di livello medio di PySide]] (dimensionare le finestre, nascondere i widget, i menu popup, la posizione del mouse, gli eventi del mouse)
* [[PySide Intermediate Examples/it|Esempi di livello medio di PySide]] (dimensionare le finestre, nascondere i widget, i menu popup, la posizione del mouse, gli eventi del mouse)
* [[PySide Advanced Examples/it|Esempi di livello avanzato di PySide]] (widget etc.)
* [[PySide Advanced Examples/it|Esempi di livello avanzato di PySide]] (widget etc.)
</div>


<div class="mw-translate-fuzzy">
Esse suddividono l'argomento in 3 parti, e si differenziano per livello di esposizione per PySide, Python e le parti incorporate in FreeCAD. La prima pagina contiene una panoramica e le basi della materia, fornisce una descrizione di PySide e di come è organizzato, mentre la seconda e la terza pagina contengono soprattutto degli esempi di codice di diversi livelli.
Esse suddividono l'argomento in 3 parti, e si differenziano per livello di esposizione per PySide, Python e le parti incorporate in FreeCAD. La prima pagina contiene una panoramica e le basi della materia, fornisce una descrizione di PySide e di come è organizzato, mentre la seconda e la terza pagina contengono soprattutto degli esempi di codice di diversi livelli.
</div>


<div class="mw-translate-fuzzy">
Con le pagine allegate si intende fornire del semplice codice Python per eseguire PySide, in modo che l'utente possa facilmente copiarlo, incollarlo nel proprio lavoro, adattarlo se necessario, e risolvere i suoi problemi con FreeCAD. Sperando che non abbia bisogno di andare alla ricerca di risposte alle domande su PySide attraverso internet. Allo stesso tempo, queste pagine non vogliono sostituirsi ai vari tutorial completi e ai siti di riferimento a PySide presenti nel web.
Con le pagine allegate si intende fornire del semplice codice Python per eseguire PySide, in modo che l'utente possa facilmente copiarlo, incollarlo nel proprio lavoro, adattarlo se necessario, e risolvere i suoi problemi con FreeCAD. Sperando che non abbia bisogno di andare alla ricerca di risposte alle domande su PySide attraverso internet. Allo stesso tempo, queste pagine non vogliono sostituirsi ai vari tutorial completi e ai siti di riferimento a PySide presenti nel web.
</div>
{{Top}}
==Documentation==


There are some differences in handling of widgets in Qt4 (PySide) and Qt5 (PySide2). The programmer should be aware of these incompatibilities, and should consult the official documentation if something doesn't seem to work as expected on a given platform. Nevertheless, Qt4 is considered obsolete, so most development should target Qt5 and Python 3.
{{docnav/it|[[Pivy/it|Pivy]]|[[FeaturePython Objects/it|Ogetti FeaturePython]]}}


The PySide documentation refers to the Python-style classes; however, since Qt is originally a C++ library, the same information should be available in the corresponding C++ reference.
{{Userdocnavi/it}}
* [https://doc.qt.io/qtforpython/modules.html Qt Modules] available from PySide2 (Qt5).
* [https://doc.qt.io/qt-5/modules-cpp.html All Qt classes by module] in Qt5 for C++.
* [https://deptinfo-ensip.univ-poitiers.fr/ENS/pyside-docs/index.html Qt Modules] available from PySide (Qt4).
{{Top}}


<div class="mw-translate-fuzzy">
[[Category:Poweruser Documentation/it]]
{{docnav/it|[[Pivy/it|Pivy]]|[[FeaturePython Objects/it|Ogetti FeaturePython]]}}

</div>
[[Category:Developer/it]]


{{Powerdocnavi{{#translation:}}}}
[[Category:Developer Documentation/it]]
[[Category:Developer Documentation{{#translation:}}]]
{{clear}}
[[Category:Python Code{{#translation:}}]]

Revision as of 13:53, 22 October 2021

PySide

PySide è il legame tra Python e la multi-piattaforma GUI degli strumenti di Qt. FreeCAD usa PySide all'interno di Python per tutti gli effetti GUI (Interfaccia grafica per l'utente). PySide è una alternativa al pacchetto PyQt che è stato utilizzato in precedenza da FreeCAD per la sua GUI. PySide ha una licenza più permissiva. Per maggiori informazioni sulla differenza vedere Differences Between PySide and PyQt.

When you install FreeCAD, you should get both Qt and PySide as part of the package. If you are compiling yourself then you must verify that these two libraries are installed in order for FreeCAD to run correctly. Of course, PySide will only work if Qt is present.

In the past, FreeCAD used PyQt, another Qt binding for Python, but in 2013 (1dc122dc9a) the project migrated to PySide because it has a more permissible license.

For more information see:

Examples created with PySide. Left: a simple dialog. Right: a more complex dialog with graphs.

PySide in FreeCAD with Qt5

FreeCAD was developed to be used with Python 2 and Qt4. As these two libraries became obsolete, FreeCAD transitioned to Python 3 and Qt5. In most cases this transition was done without needing to break backwards compatibility.

Normally, the PySide module provides support for Qt4, while PySide2 provides support for Qt5. However, in FreeCAD there is no need to use PySide2 directly, as a special PySide module is included to handle Qt5.

This PySide module is located in the Ext/ directory of an installation of FreeCAD compiled for Qt5.

/usr/share/freecad/Ext/PySide

This module just imports the necessary classes from PySide2, and places them in the PySide namespace. This means that in most cases the same code can be used with both Qt4 and Qt5, as long as we use the single PySide module.

PySide2.QtCore -> PySide.QtCore
PySide2.QtGui -> PySide.QtGui
PySide2.QtSvg -> PySide.QtSvg
PySide2.QtUiTools -> PySide.QtUiTools

The only unusual aspect is that the PySide2.QtWidgets classes are placed in the PySide.QtGui namespace.

PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox

Inizio

]

Examples of PySide use

Per acquisire familiarità con alcuni esempi reali di PySide

Esse suddividono l'argomento in 3 parti, e si differenziano per livello di esposizione per PySide, Python e le parti incorporate in FreeCAD. La prima pagina contiene una panoramica e le basi della materia, fornisce una descrizione di PySide e di come è organizzato, mentre la seconda e la terza pagina contengono soprattutto degli esempi di codice di diversi livelli.

Con le pagine allegate si intende fornire del semplice codice Python per eseguire PySide, in modo che l'utente possa facilmente copiarlo, incollarlo nel proprio lavoro, adattarlo se necessario, e risolvere i suoi problemi con FreeCAD. Sperando che non abbia bisogno di andare alla ricerca di risposte alle domande su PySide attraverso internet. Allo stesso tempo, queste pagine non vogliono sostituirsi ai vari tutorial completi e ai siti di riferimento a PySide presenti nel web.

Inizio

Documentation

There are some differences in handling of widgets in Qt4 (PySide) and Qt5 (PySide2). The programmer should be aware of these incompatibilities, and should consult the official documentation if something doesn't seem to work as expected on a given platform. Nevertheless, Qt4 is considered obsolete, so most development should target Qt5 and Python 3.

The PySide documentation refers to the Python-style classes; however, since Qt is originally a C++ library, the same information should be available in the corresponding C++ reference.

Inizio