X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Flogwindow.py;h=fd252ef6905c721844bb8439a54660ffb8dd1d8d;hp=2719dcfb9fc60822d815942a9757c0ef89fc7e98;hb=e05a4f6ac4c3e6d0e8a88ad31ec8516440cdd2b3;hpb=cd1f30ca7ef981e5c9c5c83eae26db9e1f4e5d5a diff --git a/sface/logwindow.py b/sface/logwindow.py index 2719dcf..fd252ef 100644 --- a/sface/logwindow.py +++ b/sface/logwindow.py @@ -1,36 +1,53 @@ import sys +from cStringIO import StringIO from PyQt4.QtCore import * from PyQt4.QtGui import * from sface.config import config +import time + +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): + val = self.io.getvalue() + # looks like there is no other way + # to empty the StringIO + del self.io + self.io = StringIO() + return val class LogWindow(QDialog): def __init__(self, parent=None): QWidget.__init__(self, parent) self.setWindowTitle("SFI Log") self.text = QTextBrowser(self) + self.text.ensureCursorVisible() layout = QVBoxLayout() layout.addWidget(self.text) self.setLayout(layout) - self.io = QIODevice(self) - 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") - - def appendLine(self): - self.text.append(self.io.readLine()) - - - + sys.stdout = self.logio + sys.stderr = self.logio + + def update(self): + self.text.insertPlainText(self.logio.getText()) + c = self.text.textCursor() + c.movePosition(QTextCursor.End) + self.text.setTextCursor(c)