start output redirecting to the log viewer
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Tue, 14 Sep 2010 14:10:42 +0000 (16:10 +0200)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Tue, 14 Sep 2010 14:10:42 +0000 (16:10 +0200)
sface.py
sface/logwindow.py
sface/mainwindow.py

index 07a8c2e..256c8be 100644 (file)
--- a/sface.py
+++ b/sface.py
@@ -37,6 +37,7 @@ QLabel {
 
 
     win = MainWindow()
+#    win.redirectOutputToLog()
     win.setWindowTitle("Sface: SFA Interface")
     win.show()
     win.raise_()
index 64d4e9f..2719dcf 100644 (file)
@@ -1,3 +1,5 @@
+import sys
+
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
@@ -9,12 +11,26 @@ class LogWindow(QDialog):
         QWidget.__init__(self, parent)
         self.setWindowTitle("SFI Log")
         self.text = QTextBrowser(self)
-        
+
         layout = QVBoxLayout()
         layout.addWidget(self.text)
         self.setLayout(layout)
 
-    def setText(self, txt):
-        self.text.setText(txt)
+        self.io = QIODevice(self)
+        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())
+        
         
         
index 0ae038d..39e68a0 100644 (file)
@@ -1,5 +1,6 @@
 
 import os
+import sys
 import time
 
 from PyQt4.QtCore import *
@@ -94,8 +95,12 @@ class MainWindow(QWidget):
         self.connect(self.log, SIGNAL('linkActivated(QString)'),
                      self.showLogWindow)
 
+    def redirectOutputToLog(self):
+        self.logWindow.redirectOutput()
+
     def showLogWindow(self, link):
         self.logWindow.show()
+        self.logWindow.resize(500, 500)
         self.logWindow.raise_()
         self.logWindow.activateWindow()