wxPython: Terminal Output -> Scrollable Panel?
Peter Hansen
peter at engcorp.com
Sat Jul 2 16:04:37 EDT 2005
flamesrock wrote:
> I looked at PyCrust, and while its given me a few cool ideas, I may
> have described the problem incorrectly. What I really need is not
> something that takes input, but merely redirects the 'print' statements
> to something like a terminal window.
>
> Is this even possible without entering the function calls directly into
> a pycrust like terminal? Maybe I'm trying to do the wrong thing.
PyCrust would show you a mechanism to get lines of text into a "terminal
window". Actually capturing those lines of output is a different story.
Here's one approach, if you have control over the print statements:
class Redirector:
def __init__(self, infoAboutTerminal):
# store "infoAboutTerminal" in local attributes
def write(self, text):
'''output lines of text to terminal window'''
# here you do whatever PyCrust does to get output to its window
# using the info stored in the constructor
Assuming you have a PyCrust-like terminal window open somewhere,
you would create a Redirector and pass it whatever info about the
terminal window that it might need.
terminal = Redirector(infoAboutPyCrustLikeWindow)
Then just send your prints to this location using the >> syntax sugar:
print >>terminal, 'This line of text goes to the GUI window.'
print >>terminal, 'So does all this\neven multiple lines...'
If you *don't* have the ability to change the print statements like
this, then you can install a Redirector in place of sys.stdout, but that
will affect all prints, including those in standard library modules and
elsewhere.
HTH
-Peter
More information about the Python-list
mailing list