The simple program below does not produce the desired behavior, which is to print text to a QTextBrowser once a second from another thread. Instead it just hangs after the thread posts 1 event. Is there something I'm doing horribly wrong? This breaks on 3.10 and 3.11 of PyQt with Qt 3.3.0 (using Gentoo emerge to install) Thanks. Please CC me for I am not subscribed.
- James Lamanna
from qt import * import sys import threading import time
class test_thread(threading.Thread):
def __init__(self, mainwin, group=None, target=None, name=None,
args=(), kwargs={}):
threading.Thread.__init__(self, group=group, target=target,
name=name, args=args, kwargs=kwargs) self.mainwin = mainwin
self.quit = False
self.counter = 10 def run(self):
while not self.quit and self.counter > 0:
time.sleep(1) # Sleep for 1s
print 'print'
QApplication.sendEvent(self.mainwin,
QCustomEvent(QEvent.User, None))
QApplication.sendPostedEvents()
self.counter -= 1
class test_Window(QMainWindow): def __init__(self,parent = None,name = None,fl = 0): QMainWindow.__init__(self,parent,name,fl) self.setCentralWidget(QWidget(self, 'central_widget')) self.textview = \ QTextBrowser(self.centralWidget(),"ResponseText") self.textview.setGeometry(QRect(0,0,480,420)) self.textview.setTextFormat(Qt.RichText) self.textview.setReadOnly(True) self.resize(QSize(1038,878).expandedTo(self.minimumSizeHint())) self.clearWState(Qt.WState_Polished)
def event(self, e):
if e.type() == QEvent.User:
self.postText()
return True
return QMainWindow.event(self, e) def postText(self):
print 'post'
self.textview.append('TEST TEXT<br>')
if __name__ == '__main__': a = QApplication(sys.argv) mw = test_Window()
QObject.connect(a, SIGNAL('lastWindowClosed()'),
a, SLOT('quit()'))
a.setMainWidget(mw)
mw.show()
test_thread(mw).start()a.exec_loop()
_______________________________________________ PyKDE mailing list [EMAIL PROTECTED] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
