Python Qt Error
Angel Lopez Muñoz
lopez en esrf.fr
Mie Mayo 19 18:03:01 CEST 2004
At 14:48 19/05/2004 +0000, you wrote:
> Gracias Chema segui tu consejo sobre el uso de pyuic, fantastico, pero
> sabes luego seguir un ejemplo del tipico Hola Mundo, desarrollado en Qt ,
> luego importe el codigo a Python usando pyuic, enseguida desarrolle el
> script de ejemplo que hace uso de la clase recien creada con pyuic, pero
> me da un error de sintaxis, te adjunto el ejemplo:
>
>Programa interface.py
>
># -*- coding: utf-8 -*-
>
># Form implementation generated from reading ui file 'interface.ui'
>#
># Created: Wed May 19 00:33:29 2004
># by: The PyQt User Interface Compiler (pyuic) 3.8
>#
># WARNING! All changes made in this file will be lost!
>
>
>from qt import *
>
>
>class Hola_Mundo(QWidget):
> def __init__(self,parent = None,name = None,fl = 0):
> QWidget.__init__(self,parent,name,fl)
>
> if not name:
> self.setName("Hola_Mundo")
>
>
>
> self.botonHola = QPushButton(self,"botonHola")
> self.botonHola.setGeometry(QRect(60,110,107,27))
>
> self.botonSalir = QPushButton(self,"botonSalir")
> self.botonSalir.setGeometry(QRect(200,110,107,27))
>
> self.textEdit1 = QTextEdit(self,"textEdit1")
> self.textEdit1.setGeometry(QRect(100,190,168,112))
>
> self.languageChange()
>
> self.resize(QSize(600,484).expandedTo(self.minimumSizeHint()))
> self.clearWState(Qt.WState_Polished)
>
>
> def languageChange(self):
> self.setCaption(self.__tr("Hola Mundo"))
> self.botonHola.setText(self.__tr("Hola"))
> self.botonSalir.setText(self.__tr("Salir"))
>
>
> def __tr(self,s,c = None):
> return qApp.translate("Hola_Mundo",s,c)
>
>
>***********************************************
>
>Aqui va el script que hace uso de la clase Hola_Mundo, hola.py
>
>#/usr/bin/python2.3
>import qt
>import sys
>
>from interface import *
>
>def botonHola_clicked():
> widget_principal.TextEdit1.setText('Hola Pinguino')
>
>
>app=QApplicatin(sys.argv)
>QObject.connect(app,SIGNAL('lastWindowClosed()',app,SLOT('quit()')
>
>Widget_principal=Hola_Mundo()
>
>Widget_principal.show()
>
>Widget_principal.connect(widget_principal.botonHola,SIGNAL('clicked()'),botonHola_clicked)
>
>Widget_principal.connect(Widget_principal.botonSalir,SIGNAL('clicked()'),app,SLOT('quit()'))
>
>app.exec_loop()
>
>
>
> Esto me lanza el siguiente error:
>
>fvillarroel en pc01:~$ emacs interface.py
>fvillarroel en pc01:~$ python hola.py
> File "hola.py", line 14
> Widget_principal=Hola_Mundo()
> ^
>SyntaxError: invalid syntax
>fvillarroel en pc01:~$
>
>
>No entiendo pues en esa linea se trata de crear una instancia de la clase
>Hola_Mundo
Ten cuidado con las Mayusculas y minusculas (Widget_principal lo has
escrito con minusculas en la línea 8)
En la línea 11 app=QApplicatin(sys.argv) debe ser app=QApplication(sys.argv).
tienes mas cosillas erroneas, por hay... tengo un tutorial muy muy majo de
pyqt que intentaré enviarte más tarde.
Un saludo y ánimo.
____________________________________
Angel Lopez Muñoz
Spanish CRG BeamLine
at the European Synchrotron Radiation Facility
6, Rue Jules Horowitz
ESRF-B. P. 220
F-38043 Grenoble Cedex 09
France
Tel. +33-(0)476 88 24 49
Fax +33-(0)476 88 28 16
Más información sobre la lista de distribución Python-es