How to change the font of the redirected stdout window

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.

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.

Thanks,

Ray Pasco

REDIRECT.PY (982 Bytes)

Check out my attached examples.

redirectOne.py (135 Bytes)

redirectTwo.py (794 Bytes)

···

On Tue, Jul 27, 2010 at 2:08 PM, Ray Pasco pascor@verizon.net wrote:

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.

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.

Thanks,

Ray Pasco

Mike Driscoll

Blog: http://blog.pythonlibrary.org

The first example doesn't apply. It only indirectly uses
wx.PyOnDemandOutputWindow.

> 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.

The second example doesn't call wx.PyOnDemandOutputWindow from a
frame. I need an example that can be called anywhere and not just
__main__. That, specifically, is what I can't get to work.

Ray

···

On Jul 27, 3:25 pm, Mike Driscoll <m...@pythonlibrary.org> wrote:

On Tue, Jul 27, 2010 at 2:08 PM, Ray Pasco <pas...@verizon.net> wrote:
> 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.

> 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.

> Thanks,
> Ray Pasco

Check out my attached examples.

--
-----------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

redirectOne.py
< 1KViewDownload

redirectTwo.py
1KViewDownload

Hi,

The first example doesn't apply. It only indirectly uses
wx.PyOnDemandOutputWindow.

> 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.

The second example doesn't call wx.PyOnDemandOutputWindow from a
frame. I need an example that can be called anywhere and not just
__main__. That, specifically, is what I can't get to work.

The redirect window is managed by the App object, you never need to
call it directly as it will be invoked by the App when the application
attempts to write to stdout/stderr.

wx.App.outputWindowClass is a variable used by the App to know what
class object to create when it needs to show the redirect window.

Cody

P.S)
Sorry to jump in and play unoffical moderator but

1) This group prefers bottom posting. So if you could, please don't
reply to messages with top posting. (if you need a 'why' the article
at the following link sums it up fairly well
Why is Bottom-posting better than Top-posting ).

2) When replying to an existing topic could you please 'reply' to it
and not start a new email thread with the same title? Otherwise there
is a loss of context in the discussion as earlier messages for the
topic are now in a separate email thread.

···

On Wed, Jul 28, 2010 at 10:23 AM, WinCrazy <pascor@verizon.net> wrote:

Hi,

A long time ago (2005!), I wrote a small frame, which
can be used as a replacement for the DOS console for
displaying stdout/err messages.

The frame has to be hooked to the main frame and it
is working in the same way as does an interactive
interpreter: by redirecting sys.stdout/err to Pseudofiles.

On advantage of this, the "stdout/err frame" can be
easily configurated or modified to include features
like:
- colorisation, different msg colours for stsou/err
- fonts
- frame opening on the first error msg only
- clearing outputs
- ...

The code may look obsolete, I wrote it for the fun
and never used it seriously, but I have just
run it on Win7, Py2.7 and wxPy2.8.11.0-ansi and
it seems to work.

Still available here:
http://spinecho.ifrance.com/ -> frameouterr-py251-wxpy2842.zip

Today, I would write something similar by using the
io module (Py > 2.5).

jmf

  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