From: Barış Metin Date: Wed, 15 Sep 2010 13:42:05 +0000 (+0200) Subject: use a simple QObject and StringIO for log window X-Git-Tag: sface-0.1-1~13 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=6aa68f810c351faa9107b915c2422c1c55cac0ac;ds=sidebyside use a simple QObject and StringIO for log window --- diff --git a/sface.py b/sface.py index 256c8be..a66d739 100644 --- a/sface.py +++ b/sface.py @@ -37,7 +37,7 @@ QLabel { win = MainWindow() -# win.redirectOutputToLog() + win.redirectOutputToLog() win.setWindowTitle("Sface: SFA Interface") win.show() win.raise_() diff --git a/sface/logwindow.py b/sface/logwindow.py index 3368185..a77eab2 100644 --- a/sface/logwindow.py +++ b/sface/logwindow.py @@ -1,10 +1,23 @@ import sys +from cStringIO import StringIO from PyQt4.QtCore import * from PyQt4.QtGui import * from sface.config import config +class LogIO(QObject): + def __init__(self, parent, old_stdout): + QObject.__init__(self, parent) + self.io = StringIO() + self.old_stdout = old_stdout + + def write(self, txt): + self.io.write(txt) + self.parent().update() + + def getText(self): + return self.io.getvalue() class LogWindow(QDialog): def __init__(self, parent=None): @@ -16,25 +29,17 @@ class LogWindow(QDialog): layout.addWidget(self.text) self.setLayout(layout) - # To Baris: from the doc, - # QIODevice is abstract and can not be instantiated - # I am putting QObject just to let the GUI start. - #self.io = QIODevice(self) - self.io = QObject() - self.connect(self.io, SIGNAL('canReadLine()'), self.appendLine) + self.logio = LogIO(self, sys.stdout) def redirectOutput(self): - print "Redirecting all output to Log Window. Please open the log window to see the output" + print "\n\nRedirecting all output to Log Window. Please open the log window to see the output\n" self.old_stdout = sys.stdout self.old_stderr = sys.stderr - sys.stdout = self.io - sys.stderr = self.io - - self.old_stdout.write("test") - self.text.append("io Test\n") + sys.stdout = self.logio + sys.stderr = self.logio - def appendLine(self): - self.text.append(self.io.readLine()) + def update(self): + self.text.setText(self.logio.getText()) diff --git a/sface/mainwindow.py b/sface/mainwindow.py index 140a6ff..b04e638 100644 --- a/sface/mainwindow.py +++ b/sface/mainwindow.py @@ -118,7 +118,7 @@ class MainWindow(QWidget): def showLogWindow(self, link): self.logWindow.show() - self.logWindow.resize(500, 500) + self.logWindow.resize(800, 400) self.logWindow.raise_() self.logWindow.activateWindow()