PySide/es: Difference between revisions

From FreeCAD Documentation
m (FuzzyBot moved page PyQt/es to PySide/es without leaving a redirect: Part of translatable page "PyQt".)
(Updating to match new version of source page)
Line 1: Line 1:
<H2>PySide</H2>
{{Note|PySide|Recently, FreeCAD has switched internally to use [http://qt-project.org/wiki/PySide PySide] instead of PyQt. That change was mainly done because of the licenses, PySide having an LGPL license which is more compatible with FreeeCAD. Other than that, PySide works exactly the same way as PyQt, and in FreeCAD you can usually use any of them, as you prefer. If you choose to use PySide, just replace all "PyQt" in the example code below with "PySide". See [http://qt-project.org/wiki/Differences_Between_PySide_and_PyQt Differences Between PySide and PyQt]}}


[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.
[http://en.wikipedia.org/wiki/PyQt PyQt] es un módulo de Python que permite a las aplicaciones en Python crear, acceder y modificar aplicaciones [http://en.wikipedia.org/wiki/Qt_(toolkit) Qt]. Se puede utilizar por ejemplo para crear tus propios programas de Qt en Python, o para acceder y modificar la interfaz de una aplicación Qt en ejecución, como FreeCAD.


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.
Al utilizar el módulo de PyQt desde el interior de FreeCAD, se tiene un control total sobre su interfaz. Por ejemplo, puedes:
* Añadir tus propios paneles, complementos (widgets) y barras de herramientas
* Añadir u ocultar los elementos en los paneles existentes
* Cambiar, redirigir o agregar conexiones entre todos los elementos


Python offers the 'print' statement which gives the code:
PyQt tiene una extensa [http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html documentación del API], y hay muchos tutoriales en la red que te enseñan cómo funciona.

Si quieres trabajar en la interfaz de FreeCAD, lo primero que debes hacer es crear una referencia a la ventana principal de FreeCAD :
{{Code|code=
{{Code|code=
print 'Hello World'
import sys
from PySide import QtGui ,QtCore
app = QtGui.qApp
mw = FreeCADGui.getMainWindow()
}}
}}
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.
A continuación, puedes navegar por ejemplo a través de todos los complementos (widgets) de la interfaz:
{{Code|code=
for child in mw.children():
print 'widget name = ', child.objectName(), ', widget type = ', child
}}
Los complementos (widgets) en una interfaz Qt se suelen anidar en otros complementos o (widgets) "contenedores", de modo que los hijos de nuestra ventana principal pueden contener otros hijos. Dependiendo del tipo de complemento (widget), hay un montón de cosas que puedes hacer. Comprueba la documentación de la API para ver lo que es posible.


PySide's abilities range from:
Agregar un nuevo complemento (widget), por ejemplo un dockWidget (que puede ser colocado en uno de los paneles laterales de FreeCAD), es sencillo:
{{Code|code=
myWidget = QtGui.QDockWidget()
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myWidget)
}}
A continuación, podrías agregar cosas directamente a tu complemento (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
}}
Sin embargo, es preferible un método que consiste en crear un objeto de interfaz de usuario (UI) que hará todo el trabajo de la configuración del complemento (widget) a la vez. La gran ventaja es que tales objetos de interfaz de usuario puede ser [[Dialog creation/es|creados gráficamente]] con el programa Qt Designer. Un objeto típico generado por Qt Designer es así:
{{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


[[File:PySideScreenSnapshot1.jpg]]
self.label = QtGui.QLabel(myWidget) # creates a label
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


to:
def retranslateUi(self, draftToolbar): # built-in QT function that manages translations of widgets

myWidget.setWindowTitle(QtGui.QApplication.translate("myWidget", "My Widget", None, QtGui.QApplication.UnicodeUTF8))
[[File:PySideScreenSnapshot2.jpg]]
self.label.setText(QtGui.QApplication.translate("myWidget", "Welcome to my new widget!", None, QtGui.QApplication.UnicodeUTF8))

}}
PySide is described in the following 3 pages which should follow on one from each other:
Para utilizarlo, sólo tienes que aplicarlo a tu recién creado complemento (widget) de este modo:

{{Code|code=
* [[PySide_Beginner_Examples|Beginner PySide Examples]] (Hello World, announcements, enter text, enter number)
app = QtGui.qApp
* [[PySide_Medium_Examples|Medium PySide Examples]] (window sizing, hiding widgets, popup menus, mouse position, mouse events)
FCmw = app.activeWindow()
* [[PySide_Advanced_Examples|Advanced PySide Examples]] (widgets etc.)
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget

myNewFreeCADWidget.ui = myWidget_Ui() # load the Ui script
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.
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # setup the ui

FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
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.
}}
{{docnav/es|Pivy/es|Scripted objects/es}}


{{docnav|Pivy|Scripted objects}}
[[Category:Poweruser Documentation/es]]


[[Category:Poweruser Documentation]]
{{clear}}
{{clear}}
<languages/>
<languages/>

Revision as of 18: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:

to:

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.

Pivy
Scripted objects