Windows GUI - which way?

Peter Hansen peter at engcorp.com
Sat Mar 2 18:22:37 EST 2002


Spencer Ernest Doidge wrote:
> 
> I want to maintain and use a library of Python scripts. I want to invoke
> any script from this library by using a GUI app. The script itself would
> have no GUI features. It would be sending and receiving serial port
> messages. (This is like the script I am already running.)
> 
> Some frequently-used scripts would be invoked directly from a Tools menu,
> others would be named in a File/Open dialog. I want to begin execution of
> the script by using either a menu, a dialog, or a toolbar icon. When the
> execution begins, I want to be able to abort the script at any time by
> either a dialog button, a menu item, or a toolbar icon.

Sounds a lot like some kind of automated testing system.  Can you 
describe the nature of the application, to help us envision appropriate
approaches?

> If I write the GUI app all in Python, is it a simple matter to, say, load
> and run the script in its own thread, and have it be responsive to a
> signal from the main thread telling it to abort?

Sure.  Scripts can be loaded at any time with 'import', and it's
trivial to derive a Thread class which sports a spiffy "stop()"
method that sets a flag which is polled in the main loop as a way
of telling the thread to clean up and exit.

> For nice-to-haves, it would be nice to display some sort of output, even a
> progress control (thermometer, or whatever one calls it), or some text in
> an output window, the way it's done in Visual C++ when you build a
> project.

The background thread can communicate with the GUI thread by using
the various mechanisms for such a thing that are provided by Python
(e.g. 'Queue') and by the GUI framework you pick (for example, the
wxWindows/wxPython 'PostEvent()' method).

> Do you know of straightforward ways to accomplish the must-haves?
> 
> What about the nice-to-haves?

Just start building and ask away in this forum as you encounter 
difficulties. :-)



More information about the Python-list mailing list