wxPython: Terminal Output -> Scrollable Panel?

F

flamesrock

First, I'm very new to gui programming, so please go lightly on me :)

Ok, so far I've settled on wxPython, and what I'd like to do as a first
leap is *convert* a text program into a gui program. It would have a
few buttons as function controls and one main scrollable panel that
acts like a terminal window.

I want to make it so that clicking on a button that performs an
operation will output it to the scrollable wxpython terminal panel, and
(if possible) save that output as text (or maybe into a logfile).

Anyone know how to do this? Like a log window? I've seen something like
this in a program called 'nicotine' but have no idea how to implement
it myself.

-thanks
 
P

Peter Hansen

flamesrock said:
I want to make it so that clicking on a button that performs an
operation will output it to the scrollable wxpython terminal panel, and
(if possible) save that output as text (or maybe into a logfile).

The example code includes something called "PyCrust" which does pretty
much this. (The logging part is fairly trivial, so I won't mention it.)
I'm sure you could look in the source to learn more. You can start by
running the demo, and finding that particular one, playing with it a
bit, and then seeing how the demo code invokes PyCrust. Then find the
source for PyCrust in the wxPython folder (under your lib/site-packages
folder in c:\python24) and start reading.

-Peter
 
F

flamesrock

Thanks much for your response.

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.

Thanks
 
P

Peter Hansen

flamesrock said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top