update for win
[sface.git] / sface / logwindow.py
1 import sys
2 from cStringIO import StringIO
3
4 from PyQt4.QtCore import *
5 from PyQt4.QtGui import *
6
7 from sface.config import config
8
9 class LogIO(QObject):
10     def __init__(self, parent, old_stdout):
11         QObject.__init__(self, parent)
12         self.io = StringIO()
13         self.old_stdout = old_stdout
14
15     def write(self, txt):
16         self.io.write(txt)
17         self.parent().update()
18
19     def getText(self):
20         return self.io.getvalue()
21
22 class LogWindow(QDialog):
23     def __init__(self, parent=None):
24         QWidget.__init__(self, parent)
25         self.setWindowTitle("SFI Log")
26         self.text = QTextBrowser(self)
27
28         layout = QVBoxLayout()
29         layout.addWidget(self.text)
30         self.setLayout(layout)
31
32         self.logio = LogIO(self, sys.stdout)
33
34     def redirectOutput(self):
35         print "\n\nRedirecting all output to Log Window. Please open the log window to see the output\n"
36         self.old_stdout = sys.stdout
37         self.old_stderr = sys.stderr
38         sys.stdout = self.logio
39         sys.stderr = self.logio
40
41     def update(self):
42         self.text.setText(self.logio.getText())
43         
44         
45