1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| from PyQt4.QtGui import *
from PyQt4.QtCore import *
from threading import Thread as Worker
import time
class TextLogger(QFrame):
def __init__(self, parent=None):
super(TextLogger, self).__init__(parent)
tw = self._textWidget = QTextEdit(parent=self)
tw.setReadOnly(True)
self.connect(self, SIGNAL("add_line(QString)"), tw.insertPlainText)
def add_line(self, text):
self.emit(SIGNAL("add_line(QString)"), text + '\n')
def activity(count, add_line):
for x in range(count):
add_line('line-%d' % x)
time.sleep(0.1)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
widget = TextLogger()
widget.show()
m = Worker(target=activity, args=(5, widget.add_line))
m.start()
app.exec_() |
Partager