Robin,
It's not clear how wx.App.outputWindowClass is actually used. There
seems to be no working examples anywhere. Apparently it was designed to
be an internal Python utility which is automatically used internally
when creating a wx.App and wx.PySimpleApp when redirect is set True. How
this is done is a mystery.
It's all in Python code in the wx.App class. outputWindowClass is initialized like this:
class App(wx.PyApp):
...
outputWindowClass = PyOnDemandOutputWindow
So it is a class attribute that is just a reference to another class. You can either reassign it directly as I did in my other email, or a more correct way to use a different class for the output would be to derive a new class and reassign it there:
class MyApp(wx.App):
outputWindowClass = MyOutputWindowClass
Anything that implements the same API as PyOnDemandOutputWindow will work, it does not have to be a class derived from PyOnDemandOutputWindow.
Further down in the wx.App class we have this method which is where that class attribute is used to create an instance of the output window class:
def RedirectStdio(self, filename=None):
"""Redirect sys.stdout and sys.stderr to a file or a popup window."""
if filename:
_sys.stdout = _sys.stderr = open(filename, 'a')
else:
self.stdioWin = self.outputWindowClass()
_sys.stdout = _sys.stderr = self.stdioWin
The PyOnDemandOutputWindow is also Python code that can be browsed in the wx._core module. It's fairly simple and self-explanatory. The key feature is that it has file-like methods write, close, and flush so it can be a substitute for sys.stdout and sys.stderr. When write is called (because something has been printed to sys.stdout) then the class will create a frame with with a textctrl (if it doesn't exist already) that will display the text.
If you want to see a more complex use for this feature check out the feedback window in Chandler, at http://svn.osafoundation.org/chandler/trunk/chandler/application/.
Please show a small demonstration app in which something like a wx.Frame
instantiates it, writes something, destroys it and then writes to just
the original stdout/stderr.
I have attached a working example using a wx.App, but I can't figure out
how to get it to work substituting a wx.PySimpleApp.
There is almost no difference between wx.App and wx.PySimpleApp any more. It is now just a class derived from wx.App which does nothing but default the redirect parameter to False, so there really isn't any need to use it rather than just using wx.App itself. Either way, you can just derive a new class from it that sets outputWindowClass to your own class like I showed above.
···
On 7/27/10 12:08 PM, Ray Pasco wrote:
--
Robin Dunn
Software Craftsman