PySide/ro: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
 
(29 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<languages/>

{{Docnav
|[[Pivy|Pivy]]
|[[Interface_creation|Interface creation]]
}}

{{TOCright}}

<div class="mw-translate-fuzzy">
<H2>PySide</H2>
<H2>PySide</H2>
</div>


<div class="mw-translate-fuzzy">
[http://en.wikipedia.org/wiki/PySide PySide] este o legare instrument Python multiplatformă obligatoriu pentru a crea GUI în QT. FreeCAD utilizează PySide pentru toate GUI (Graphic User Interface) în interiorul Python. PySide este o alternativă la pachetul PyQt folosit anterior de FreeCAD pentru GUI. PySide are o licență mai permisivă. A se vedea [http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt] for more information on the differences.
[http://en.wikipedia.org/wiki/PySide PySide] este un instrument Python multiplatformă obligatoriu pentru a crea GUI în QT. FreeCAD utilizează PySide pentru toate GUI (Graphic User Interface) în interiorul Python. PySide este o alternativă la pachetul PyQt folosit anterior de FreeCAD pentru GUI. PySide are o licență mai permisivă. A se vedea [http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt] for more information on the differences.
</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.
Users of FreeCAD often achieve everything using the built-in interface. But for users who want to customise their operations then the Python interface exists which is documented in the [[Python_scripting_tutorial|Python Scripting Tutorial]]. The Python interface for FreeCAD had great flexibility and power. For its user interaction Python with FreeCAD uses PySide, which is what is documented on this page.


In the past, FreeCAD used PyQt, another Qt binding for Python, but in 2013 ([https://github.com/FreeCAD/FreeCAD/commit/1dc122dc9a commit 1dc122dc9a]) the project migrated to PySide because it has a more permissible [[licence|license]].
Python offers the 'print' statement which gives the code:
{{Code|code=
print 'Hello World'
}}
With Python's print statement you have only limited control of the appearance and behaviour. PySide supplies the missing control and also handles environments (such as the FreeCAD macro file environment) where the built-in facilities of Python are not enough.


For more information see:
PySide's abilities range from:
* [https://en.wikipedia.org/wiki/PySide Wikipedia:PySide]
* [https://wiki.qt.io/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt]


[[File:PySideScreenSnapshot1.jpg]]
[[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==
to:


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.
[[File:PySideScreenSnapshot2.jpg]]


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.
PySide is described in the following 3 pages which should follow on one from each other:


This {{incode|PySide}} module is located in the {{incode|Ext/}} directory of an installation of FreeCAD compiled for Qt5.
* [[PySide_Beginner_Examples|Beginner PySide Examples]] (Hello World, announcements, enter text, enter number)
{{Code|code=
* [[PySide_Medium_Examples|Medium PySide Examples]] (window sizing, hiding widgets, popup menus, mouse position, mouse events)
/usr/share/freecad/Ext/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=
PySide2.QtCore -> PySide.QtCore
PySide2.QtGui -> PySide.QtGui
PySide2.QtSvg -> PySide.QtSvg
PySide2.QtUiTools -> PySide.QtUiTools
}}

The only unusual aspect is that the {{incode|PySide2.QtWidgets}} classes are placed in the {{incode|PySide.QtGui}} namespace.
{{Code|code=
PySide2.QtWidgets.QCheckBox -> PySide.QtGui.QCheckBox
}}
{{Top}}
==Examples of PySide use==

<div class="mw-translate-fuzzy">
* [[PySide_Beginner_Examples|Beginner PySide Examples]] (Hello World, anunțuri, introducerea textului, intgroducerea numerului)
* [[PySide_Intermediate_Examples|PySide Intermediate Examples]] (mărimea ferestrei, ascunderea widgets, meniuri popup, poziția mouse , evenimentele mouse-ului)
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (widgets etc.)
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (widgets etc.)
</div>

<div class="mw-translate-fuzzy">
Acestea împart subiectul în 3 părți, diferențiate după nivelul de cunoaștere a PySide, Python și FreeCAD. Prima pagină are o imagine de ansamblu și un material de referință care oferă o descriere a PySide și modul în care sunt setate împreună, în timp ce a doua și a treia pagină sunt în mare parte exemple de cod la diferite niveluri.
</div>

<div class="mw-translate-fuzzy">
Intenția este ca paginile asociate să furnizeze un cod Python simplu pentru a rula PySide, astfel încât utilizatorul care lucrează la o problemă să poată copia cu ușurință codul, să-l lipsească în munca proprie, să-l adapteze după cum este necesar și să se întoarcă la rezolvarea problemelor cu FreeCAD. Sperăm că nu trebuie să meargă pe Internet în căutarea răspunsurilor la problemele PySide. În același timp, această pagină nu are intenția de a înlocui diferitele tutoriale și site-uri de referință PySide disponibile pe 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.
They divide the subject matter into 3 parts, differentiated by level of exposure to PySide, Python and the FreeCAD internals. The first page has overview and background material giving a description of PySide and how it is put together while the second and third pages are mostly code examples at different levels.


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.
The intention is that the associated pages will provide simple Python code to run PySide so that the user working on a problem can easily copy the code, paste it into their own work, adapt it as necessary and return to their problem solving with FreeCAD. Hopefully they don't have to go chasing off across the internet looking for answers to PySide questions. At the same time this page is not intended to replace the various comprehensive PySide tutorials and reference sites available on the web.
* [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">
{{docnav|Pivy|Scripted objects}}
{{docnav|Pivy|Scripted objects}}
</div>


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

Latest revision as of 14:51, 13 January 2022

PySide

PySide este un instrument Python multiplatformă obligatoriu pentru a crea GUI în QT. FreeCAD utilizează PySide pentru toate GUI (Graphic User Interface) în interiorul Python. PySide este o alternativă la pachetul PyQt folosit anterior de FreeCAD pentru GUI. PySide are o licență mai permisivă. A se vedea Differences Between PySide and PyQt for more information on the differences.

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 (commit 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

Top

Examples of PySide use

Acestea împart subiectul în 3 părți, diferențiate după nivelul de cunoaștere a PySide, Python și FreeCAD. Prima pagină are o imagine de ansamblu și un material de referință care oferă o descriere a PySide și modul în care sunt setate împreună, în timp ce a doua și a treia pagină sunt în mare parte exemple de cod la diferite niveluri.

Intenția este ca paginile asociate să furnizeze un cod Python simplu pentru a rula PySide, astfel încât utilizatorul care lucrează la o problemă să poată copia cu ușurință codul, să-l lipsească în munca proprie, să-l adapteze după cum este necesar și să se întoarcă la rezolvarea problemelor cu FreeCAD. Sperăm că nu trebuie să meargă pe Internet în căutarea răspunsurilor la problemele PySide. În același timp, această pagină nu are intenția de a înlocui diferitele tutoriale și site-uri de referință PySide disponibile pe web.

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.

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.

Top

Pivy
Scripted objects