[PyQt] Catching exceptions everywhere

Lukas Hetzenecker LuHe at gmx.at
Fri May 8 09:30:20 BST 2009


Hello,

this is also done in my example.
sys.__stderr__ stores the original value of the error output handler.
If a new message is shown it is also written to this object:

Main class:
sys.stderr = lib.log.QtOutput(self.logWindow.outputEdit,  sys.__stderr__,  
QColor(Qt.red))

QtOutput class:
def __init__(self, parent, out=None, color=None):
   # ... out is sys.__stderr__
def write(self, m):
   # Write message to TextEdit
   self.textWidget.insertPlainText( m )

   # Write message to original sterr
   self.out.write(m)

Am Freitag 08 Mai 2009 03:28:01 schrieb Grissiom:
> 在 星期四 07 五月 2009 23:32:26,Lukas Hetzenecker 写道:
>
> > Hello,
> >
> > you could redirect the interpreter’s standard error output stream:
> > sys.stderr = YourClass(window.edit,  sys.__stderr__,  QColor(Qt.red))
> > YourClass in an "file-like" object (it has an write function)
> > window.edit is an instance of Qt's QTextEdit class and is used to display
> > the message.
>
> It seems this is a Really good idea! But what if I want to write messages
> to the original stderr(i.e, to the terminal)?




More information about the PyQt mailing list