I have a program where I want to be able to have print statements get
written to a TextCtrl, and errors show up in another. So I made my two
TextCtrls and assigned them to sys.stdout and sys.stderr. So far so
good. However, sometimes when I print to them, I get this error:
Traceback (most recent call last):
File "C:\Python27x64\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 14660, in <lambda>
lambda event: event.callable(*event.args, **
event.kw) )
File "C:\mui\gui\loggingWindow.py", line 48, in stdOut
window.stdOut.write(' '.join([str(s) for s in args]))
File "C:\Python27x64\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py",
line 1990, in write
return _controls_.TextCtrl_write(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "m_count == -1 || m_count ==
-2" failed at ..\..\src\msw\textctrl.cpp(140) in
UpdatesCountFilter::UpdatesCountFilter(): wrong initial m_updatesCount
value
I'm guessing the problem is that print statements made outside of the
main thread are causing UI updates when those should only happen in
the main thread. I tried working around it by overriding the
TextCtrl.write method:
self.stdOut.__labWrite = self.stdOut.write
self.stdOut.write = lambda *args:
wx.CallAfter(self.stdOut.__labWrite(*args))
but this results in massive error spew about NoneType not being
callable. Oddly this shows up in my stderr window just fine, but the
spew locks up the program and I can't copy&paste it.
So what's the proper way to capture stdout and stderr to a text control?
-Chris