import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from sface.config import config 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) # 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) def redirectOutput(self): print "Redirecting all output to Log Window. Please open the log window to see the output" 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())