X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Flogwindow.py;h=a77eab214ee505647e5ac6579eca45a40a17a50f;hp=336818535b5a449769544a94190d7e9d27355116;hb=6aa68f810c351faa9107b915c2422c1c55cac0ac;hpb=56eeddf9de82bfb79a5cced82e448809eefe9352 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())