From: Barış Metin Date: Tue, 14 Sep 2010 14:10:42 +0000 (+0200) Subject: start output redirecting to the log viewer X-Git-Tag: sface-0.1-1~34 X-Git-Url: http://git.onelab.eu/?p=sface.git;a=commitdiff_plain;h=cd1f30ca7ef981e5c9c5c83eae26db9e1f4e5d5a start output redirecting to the log viewer --- diff --git a/sface.py b/sface.py index 07a8c2e..256c8be 100644 --- a/sface.py +++ b/sface.py @@ -37,6 +37,7 @@ QLabel { win = MainWindow() +# win.redirectOutputToLog() win.setWindowTitle("Sface: SFA Interface") win.show() win.raise_() diff --git a/sface/logwindow.py b/sface/logwindow.py index 64d4e9f..2719dcf 100644 --- a/sface/logwindow.py +++ b/sface/logwindow.py @@ -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()) + diff --git a/sface/mainwindow.py b/sface/mainwindow.py index 0ae038d..39e68a0 100644 --- a/sface/mainwindow.py +++ b/sface/mainwindow.py @@ -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()