[PyQt] thread in pyqt ... simple example needed
massimo di stefano
massimodisasha at yahoo.it
Sun Apr 5 20:00:38 BST 2009
.. done little step ahead :
import sys
from PyQt4 import QtCore, QtGui
import time
class MyThread(QtCore.QThread):
def run(self):
n = 0
step = 1
while True:
n += step
print n
class Gui(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QGroupBox.__init__(self, parent)
self.gcenter = QtGui.QPushButton("X", self)
self.gcenter.setAutoRepeat(True)
guiLayout = QtGui.QGridLayout()
guiLayout.addWidget(self.gcenter,1,0)
self.setLayout(guiLayout)
self.thread = MyThread()
self.connect(self.gcenter, QtCore.SIGNAL("clicked()"),
self.thread.start)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
gui = Gui()
gui.show()
sys.exit(app.exec_())
now i need to stop it when i "release" the button,
tried with :
self.connect(self.gcenter, QtCore.SIGNAL("released()"),
self.thread.quit)
but give :
AttributeError: stop
Il giorno 05/apr/09, alle ore 19:56, massimo di stefano ha scritto:
>
> Hi All,
>
> i'm doing my first experience using pyqt and tring to learn more
> about it
> unlucky i'm not able to solve some problems by myself :-(
> i googled a lot about and i tried to use QTassistant
> ....
> but i'm pretty new to programming and i've some difficoult to learn.
>
> i tried to resume my problem in a sample script, that is :
>
>
> import sys
> from PyQt4 import QtCore, QtGui
> import time
>
> class Gui(QtGui.QWidget):
> def __init__(self, parent=None):
> QtGui.QGroupBox.__init__(self, parent)
> self.gcenter = QtGui.QPushButton("X", self)
> self.gcenter.setAutoRepeat(True)
> self.connect(self.gcenter, QtCore.SIGNAL("clicked()"),self.count)
> guiLayout = QtGui.QGridLayout()
> guiLayout.addWidget(self.gcenter,1,0)
> self.setLayout(guiLayout)
>
>
> def count(self):
> n = 0
> step = 1
> while True:
> n += step
> print n
> time.sleep(0.5)
>
>
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
> gui = Gui()
> gui.show()
> sys.exit(app.exec_())
>
>
>
> as you can see the gui do not exit from the "while" statment
> and it freeze ...
> i know, i need to learn more about QTrhead usage...
> an example on how to change the previouse code, will give me a great
> help!
>
> thanks for help me !!!
>
>
>
>
>
> Massimo Di Stefano
> massimodisasha at yahoo.it
>
> epifanio on irc.freenode.net /join gfoss
>
>
>
>
>
>
>
> Chiacchiera con i tuoi amici in tempo reale!http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Chiacchiera con i tuoi amici in tempo reale!
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
More information about the PyQt
mailing list