Guification of console app

Steve Holden steve at holdenweb.com
Fri Nov 25 03:50:09 EST 2005


metiu wrote:
> Say I have a console app that does something in three steps:
> - opens a file
> - transfers the file through a serial port
> - does some elaborations
> 
> and I want to build a GUI around it that, for example, sets the file
> name to open or starts the different steps.
> 
> I started using wxPython (actually boa-constructor) to build a frame
> with everything I want.
> The problem is: when the console app method is working, the GUI is
> locked...
> 
> How can the console app communicate with the GUI in order to make it
> tick (think of status messages, progress bars, log messages...)?
> If I use threads and events, or wxYield, or EVT_IDLE, I'm tweaking the
> console app so that it won't work just in console anymore.
> 
> How do you do that?
> 
> Thanks!
> 
I've achieved this in the past by having the GUI trigger the console app 
in a separate thread and then use a Queue.Queue to send output from the 
console app to the GUI. As long as the GUI portion is careful never to 
block on an empty Queue this can work quite well.

There's also a cookbook recipe by Jacob Hallen that shows you how to 
keep a Tkinter GUI running with parallel worker threads.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list