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): QWidget.__init__(self, parent) self.setWindowTitle("SFI Log") self.text = QTextBrowser(self) layout = QVBoxLayout() layout.addWidget(self.text) self.setLayout(layout) self.logio = LogIO(self, sys.stdout) def redirectOutput(self): 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.logio sys.stderr = self.logio def update(self): self.text.setText(self.logio.getText())