views:

44

answers:

1
+1  Q: 

Wxwidgets and Pyqt

Hello, is there a similar function PyOnDemandOutputWindow in Pyqt? This function redirect the console output to a separate window. Sorry for my english.

+3  A: 

It is possible to replace sys.std[out|err] with a wrapper that writes all output to e.g. a QPlainTextEdit. A very basic example:

class StdoutWrapper(object):
    def __init__(self, outwidget):
        self.widget = outwidget
        self.widget.setReadOnly(True) # assuming QPlainTextEdit
        self.widget.hide()

    def write(self, s):
        self.widget.show()
        self.widget.appendPlainText(s) # again assuming QPlainTextEdit

And somewhere else:

import sys

sys.stdout = StdoutWrapper(yourwidget)
# similar for stderr, but you might want an error dialog or make 
# the text stand out using appendHtml
delnan