2 from cStringIO import StringIO
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
7 from sface.config import config
12 def __init__(self, parent, old_stdout):
13 QObject.__init__(self, parent)
15 self.old_stdout = old_stdout
19 self.parent().update()
22 val = self.io.getvalue()
23 # looks like there is no other way
24 # to empty the StringIO
29 class LogWindow(QDialog):
30 def __init__(self, parent=None):
31 QWidget.__init__(self, parent)
32 self.setWindowTitle("SFI Log")
33 self.text = QTextBrowser(self)
34 self.text.ensureCursorVisible()
36 layout = QVBoxLayout()
37 layout.addWidget(self.text)
38 self.setLayout(layout)
40 self.logio = LogIO(self, sys.stdout)
42 def redirectOutput(self):
43 print "\n\nRedirecting all output to Log Window. Please open the log window to see the output\n"
44 self.old_stdout = sys.stdout
45 self.old_stderr = sys.stderr
46 sys.stdout = self.logio
47 sys.stderr = self.logio
50 self.text.insertPlainText(self.logio.getText())
51 c = self.text.textCursor()
52 c.movePosition(QTextCursor.End)
53 self.text.setTextCursor(c)