Hi all,
I'm using wx.GetApp().RedirectStdio() to show the user some IO in
certain parts of my program. However, the output window does not stay
on top when another part of the screen is selected. Is there a way to
keep this window on top, and then restore the original IO stream later
when needed?
BTW, the IO I am interested in seeing is coming from C++ extensions.
I'm on Solaris 10, python 2.5, wxPython 2.6.3.3.
Any suggestions most appreciated.
Chris Botos
Hi Chris,
Hi all,
I’m using wx.GetApp().RedirectStdio() to show the user some IO in
certain parts of my program. However, the output window does not stay
on top when another part of the screen is selected. Is there a way to
keep this window on top, and then restore the original IO stream later
when needed?
BTW, the IO I am interested in seeing is coming from C++ extensions.
I’m on Solaris 10, python 2.5, wxPython 2.6.3.3.
Any suggestions most appreciated.
Chris Botos
Take a look at this tutorial: http://www.blog.pythonlibrary.org/2009/01/01/wxpython-redirecting-stdout-stderr/
It looks like I forgot to include code in there on how to restore stdout though. The basic idea goes like this:
import sys
old_sysout = sys.stdout
# do the redirection according to the linked tutorial above
reset stdout
sys.stdout = old_sysout
Of course, since this would be in a wxPython program, old_sysout would probably need to be “self.old_sysout”, but you get the idea. As for getting it to stay on top, but the multi-line text control in a frame with the wx.STAY_ON_TOP style applied to it.
HTH
···
On Sun, Dec 6, 2009 at 8:25 AM, Chris Botos chris.botos@gmail.com wrote:
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Thanks Mike! This looks like just what I need. And your blog looks
very helpful in general.
Chris
···
On Dec 6, 3:29 pm, Mike Driscoll <m...@pythonlibrary.org> wrote:
Hi Chris,
On Sun, Dec 6, 2009 at 8:25 AM, Chris Botos <chris.bo...@gmail.com> wrote:
> Hi all,
> I'm using wx.GetApp().RedirectStdio() to show the user some IO in
> certain parts of my program. However, the output window does not stay
> on top when another part of the screen is selected. Is there a way to
> keep this window on top, and then restore the original IO stream later
> when needed?
> BTW, the IO I am interested in seeing is coming from C++ extensions.
> I'm on Solaris 10, python 2.5, wxPython 2.6.3.3.
> Any suggestions most appreciated.
> Chris Botos
Take a look at this tutorial:wxPython - Redirecting stdout / stderr - Mouse Vs Python…
It looks like I forgot to include code in there on how to restore stdout
though. The basic idea goes like this:
<code>
import sys
old_sysout = sys.stdout
# do the redirection according to the linked tutorial above
# reset stdout
sys.stdout = old_sysout
</code>
Of course, since this would be in a wxPython program, old_sysout would
probably need to be "self.old_sysout", but you get the idea. As for getting
it to stay on top, but the multi-line text control in a frame with the
wx.STAY_ON_TOP style applied to it.
HTH
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Thanks! I’m glad you like it. I just noticed that you are using a really old wxPython. Lots of new widgets have been added since then, not to mention lots of bug-fixes. If you can, I’d recommend upgrading to the latest version.
By the way, this group usually doesn’t top-post. I don’t really care myself, but you may raise the ire of others.
Have a good day!
···
On Sun, Dec 6, 2009 at 5:53 PM, Chris Botos chris.botos@gmail.com wrote:
Thanks Mike! This looks like just what I need. And your blog looks
very helpful in general.
Chris
Mike Driscoll
Blog: http://blog.pythonlibrary.org
A few random comments.
* It is not necessary to keep/save instances of std[io|err] before
redirecting them. Python provides all the machinery with the
attributes sys.__std[out|err]__ (note the underscores).
* Long time ago, I wrote a small application showing how one can
write a personalized frame for displaying std[out|err] messages:
frameouterr-py251-wxpy2842.zip. Shoud be still available here
http://spinecho.ze.cx/
* /off topic/
For those who like to toy with IO, I recommand to have a look
at the new Python 3 IO framework. (It's a jewel).
Regards
Jean-Michel Fauth, Switzerland
Thanks, Jean-Michel.
An issue I just discovered found with Mike's suggestion is that it
does not seem to redirect IO from a C++ extension. Does your method
handle this? Or do you or Mike (or anyone) have suggestions on this
point?
Chris
···
On Dec 7, 5:05 am, jmfauth <wxjmfa...@gmail.com> wrote:
A few random comments.
* It is not necessary to keep/save instances of std[io|err] before
redirecting them. Python provides all the machinery with the
attributes sys.__std[out|err]__ (note the underscores).
* Long time ago, I wrote a small application showing how one can
write a personalized frame for displaying std[out|err] messages:
frameouterr-py251-wxpy2842.zip. Shoud be still available herehttp://spinecho.ze.cx/
* /off topic/
For those who like to toy with IO, I recommand to have a look
at the new Python 3 IO framework. (It's a jewel).
Regards
Jean-Michel Fauth, Switzerland
I’m not sure about the details, but some of my colleagues experienced the same problem with command-line Python programs which rely on Boost.Python for wrapping C++ extensions. You need some way of wrapping Python filehandles in C++ that allows you to use the standard C++ stream API. It’s definitely possible (I use one solution for a wxPython app with a very large C++ backend), but requires some additional C++ code. Part (maybe all?) of the answer is here:
http://cctbx.svn.sourceforge.net/viewvc/cctbx/trunk/boost_adaptbx/python_streambuf.h?revision=10044&view=markup
It’s unrestricted open-source, so you can probably adapt it to your needs. Don’t ask me how it works, but I can request more details if you’re interested.
···
On Mon, Dec 7, 2009 at 1:34 PM, Chris Botos chris.botos@gmail.com wrote:
An issue I just discovered found with Mike’s suggestion is that it
does not seem to redirect IO from a C++ extension. Does your method
handle this? Or do you or Mike (or anyone) have suggestions on this
point?
Oops...all the examples I've seen online said to do it by saving a
reference to it. I'll have to add this information to my article at
some point. Thanks for the info!
···
On Dec 7, 4:05 am, jmfauth <wxjmfa...@gmail.com> wrote:
A few random comments.
* It is not necessary to keep/save instances of std[io|err] before
redirecting them. Python provides all the machinery with the
attributes sys.__std[out|err]__ (note the underscores).
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org