Hi,
Searched google far and wide, but not coming up with a solution.
Trying to interface my GUI to an external python program. Wrote the program
initially for printing to std.out in the console. I would like to keep the functionality
of that program (just incase the user Xwindows doesn't start, but still wants to use
the program). So there are a lot of 'print' statements in there.
I realize I might have to edit some of the internals of the program to work with the
GUI, but will I have to greatly modify it to work with it?
So far the only option seems to be writing the information to a file, then read the
file into the wxTextCtrl. Then give the user the option to save the file or have the program
treat it as a tmp and delete it.
Or possibly collect the text from the external program in a list, then return it and
join it into a string to send to wxTextCtrl.
Is there a Class or something to redirect the text from the print statements to the wxTextCtrl
from within the GUI script??
PS. Thanks Robin. Found my problem sending a string to the wxTextCtrl.
---> self.frame.notebook_1.textDisp.SetValue(text)
Left out the: notebook_1
Hi,
Searched google far and wide, but not coming up with a solution.
Trying to interface my GUI to an external python program. Wrote the program
initially for printing to std.out in the console. I would like to keep the functionality
of that program (just incase the user Xwindows doesn't start, but still wants to use
the program). So there are a lot of 'print' statements in there.
I realize I might have to edit some of the internals of the program to work with the GUI, but will I have to greatly modify it to work with it?
Is the external program launched by the GUI program or is it already running? If your UI is doing the launching then you could look at the wxProcess sample in the demo for one way to capture the standard output of a child process. (You also hook to the program's standard input if you need to send data to it.) There are other ways to do it too if you don't need all that wxProcess gives you, such as os.popen.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Trying to interface my GUI to an external python
program. Wrote the program
initially for printing to std.out in the console. I would
like to keep the functionality
of that program (just incase the user Xwindows doesn't start,
but still wants to use
the program). So there are a lot of 'print' statements in there.
Hi. I'm not clear about what you mean by 'external' python program.
You could always derive a class from e.g. wxTextCtrl and add a print
method that basically uses AppendText. Then set sys.stdout of the
'external' program to an instance of this class and all the print calls
now go to the window instead of the console. AFAIK there's nothing in
python forcing sys.stdout to be connected to a file type, you just have
to implement the file class's API.
But be careful, if you let your external program run in a thread, then
you probably shouldn't call AppendText from the non-GUI thread. Use a
Queue to send text from your new print method to the GUI thread.
Surely, somebody on this list must have tried this before?