Difference between revisions of "PySide/it"

From FreeCAD Documentation
Jump to: navigation, search
m (FuzzyBot moved page PyQt/it to PySide/it without leaving a redirect: Part of translatable page "PyQt".)
(Updating to match new version of source page)
Line 1: Line 1:
{{Note|PySide|Di recente, FreeCAD è stato modificato internamente per usare [http://qt-project.org/wiki/PySide PySide] al posto di PyQt. Questo cambiamento è stato fatto soprattutto per risolvere una questione di licenze, PySide ha una licenza LGPL che è più compatibile con FreeeCAD. A parte  questo, PySide funziona esattamente come PyQt, e in genere in FreeCAD si può utilizzare indifferentemente uno dei due, come si preferisce. Se si decide di utilizzare PySide, basta sostituire tutti i "PyQt" con "PySide" nel codice di esempio sottostante. Vedere le 
+
<H2>PySide</H2>
[http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differenze tra PySide e PyQt]}}
 
  
[http://en.wikipedia.org/wiki/PyQt PyQt] è un modulo di Python che consente alle applicazioni in Python di creare, accedere e modificare le applicazioni [http://en.wikipedia.org/wiki/Qt_(toolkit) Qt]. Può essere utilizzato, per esempio, per creare i programmi Qt in Python oppure per accedere e modificare l'interfaccia di un'applicazione Qt in esecuzione, come FreeCAD.  
+
[http://en.wikipedia.org/wiki/PySide PySide] is a Python binding of the cross-platform GUI toolkit Qt. FreeCAD uses PySide for all GUI (Graphic User Intercase) purposes. PySide evolved from the PyQt package which was previously used by FreeCAD for it's GUI. See [http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt] for more information on the differences.
  
Quindi, usando il modulo PyQt all'interno di FreeCAD, si ha il controllo completo della sua interfaccia. È possibile ad esempio:
+
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 it's user interaction Python with FreeCAD uses PySide, which is what is documented on this page.
* Aggiungere propri pannelli, widget e barre degli strumenti
 
* Aggiungere o nascondere gli elementi nei pannelli già esistenti
 
* Modificare, reindirizzare o aggiungere connessioni tra tutti questi elementi
 
  
PyQt ha una ampia [http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html documentazione API], e in rete ci sono molti tutorial che spiegano come funziona.
+
Python offers the 'print' statement which gives the code:
 
 
Se si desidera lavorare sull'interfaccia di FreeCAD, la prima cosa da fare è creare un riferimento alla finestra principale di FreeCAD:
 
 
{{Code|code=
 
{{Code|code=
import sys
+
print 'Hello World'
from PySide import QtGui ,QtCore
 
app = QtGui.qApp
 
mw = FreeCADGui.getMainWindow()
 
 
}}
 
}}
In seguito, è possibile ad esempio sfogliare tutti i widget dell'interfaccia:
+
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.
{{Code|code=
+
 
for child in mw.children():
+
PySide's abilities range from:
  print 'widget name = ', child.objectName(), ', widget type = ', child
+
 
}}
+
[[File:PySideScreenSnapshot1.jpg]]
Di solito, in una interfaccia Qt, i widget sono annidati in widget "contenitori", in questo modo i figli della finestra principale possono contenere altri figli. Secondo il tipo di widget, si possono fare un sacco di cose. Controllare la documentazione delle API per vedere quello che è possibile fare.
+
 
 +
to:
 +
 
 +
[[File:PySideScreenSnapshot2.jpg]]
 +
 
 +
PySide is described in the following 3 pages which should follow on one from each other:
  
Per aggiungere un nuovo widget, ad esempio un dockWidget (che può essere posizionato in uno dei pannelli laterali di FreeCAD), fare semplicemente:
+
* [[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)
myWidget = QtGui.QDockWidget()
+
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (widgets etc.)
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myWidget)
 
}}
 
In seguito, si può continuare e aggiungere altre cose direttamente al proprio widget:
 
{{Code|code=
 
myWidget.setObjectName("my Nice New Widget")
 
myWidget.resize(QtCore.QSize(300,100)) # sets size of the widget
 
label = QtGui.QLabel("Hello World", myWidget) # creates a label
 
label.setGeometry(QtCore.QRect(2,50,200,24))  # sets its size
 
label.setObjectName("myLabel") # sets its name, so it can be found by name
 
}}
 
Di solito, il metodo preferito consiste nel creare un oggetto UI (interfaccia utente) che faccia tutta la configurazione del proprio widget in una sola volta. Il grande vantaggio è che tale oggetto dell'interfaccia utente può essere [[Dialog creation/it|creato graficamente]] con il programma Qt Designer. Un tipico oggetto generato da Qt Designer si presenta come questo:
 
{{Code|code=
 
class myWidget_Ui(object):
 
  def setupUi(self, myWidget):
 
    myWidget.setObjectName("my Nice New Widget")
 
    myWidget.resize(QtCore.QSize(300,100).expandedTo(myWidget.minimumSizeHint())) # sets size of the widget
 
  
    self.label = QtGui.QLabel(myWidget) # creates a label
+
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.
    self.label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size
 
    self.label.setObjectName("label") # sets its name, so it can be found by name
 
  
  def retranslateUi(self, draftToolbar): # built-in QT function that manages translations of widgets
+
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.
    myWidget.setWindowTitle(QtGui.QApplication.translate("myWidget", "My Widget", None, QtGui.QApplication.UnicodeUTF8))
 
    self.label.setText(QtGui.QApplication.translate("myWidget", "Welcome to my new widget!", None, QtGui.QApplication.UnicodeUTF8))
 
}}
 
Per usarlo, basta applicarlo al pannello (widget) appena creato in questo modo:
 
{{Code|code=
 
app = QtGui.qApp
 
FCmw = app.activeWindow()
 
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget
 
myNewFreeCADWidget.ui = myWidget_Ui() # load the Ui script
 
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # setup the ui
 
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
 
}}
 
{{docnav/it|[[Pivy/it|Pivy]]|[[Scripted objects/it|Script per oggetti]]}}
 
  
[[Category:Poweruser Documentation/it]]
+
{{docnav|Pivy|Scripted objects}}
  
 +
[[Category:Poweruser Documentation]]
 
{{clear}}
 
{{clear}}
 
<languages/>
 
<languages/>

Revision as of 19:17, 9 February 2015

PySide

PySide is a Python binding of the cross-platform GUI toolkit Qt. FreeCAD uses PySide for all GUI (Graphic User Intercase) purposes. PySide evolved from the PyQt package which was previously used by FreeCAD for it's GUI. See Differences Between PySide and PyQt for more information on the differences.

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. The Python interface for FreeCAD had great flexibility and power. For it's user interaction Python with FreeCAD uses PySide, which is what is documented on this page.

Python offers the 'print' statement which gives the 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.

PySide's abilities range from:

PySideScreenSnapshot1.jpg

to:

PySideScreenSnapshot2.jpg

PySide is described in the following 3 pages which should follow on one from each other:

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 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.

Other languages:
čeština • ‎Deutsch • ‎English • ‎español • ‎français • ‎Bahasa Indonesia • ‎italiano • ‎日本語 • ‎polski • ‎português • ‎română • ‎русский • ‎svenska • ‎Türkçe