views:

50

answers:

2

Hi,

I have to start a GUI from an existing Python application. The GUI is actually separate Python GUI that can run alone. Right now, I am starting the GUI using something like:

           res=Popen(['c:\python26\pythonw.exe',
                   full_filename,
                   str(RESULTs),
                   str(context)], stdout=PIPE).communicate()[0]

where full_filename is the full path to the python GUI. As you can see, the problem is that I have to communicate the RESULTS variable to the GUI via the commandline. This works fine until the commandline get too long and I have to pickle the variables to a separate file and then re-load them when the GUI starts. This works but it is slow.

Thus, what I want to do is somehow start the GUI from within my python script, transfer the variables in question to the GUI for it to process, and then capture the GUI's results back in the calling script. As you can see above, this currently happens through the res variable since the GUI can be configured to write its output to the standard output which is captured in this variable.

Any ideas? I'm hoping someone can suggest a more elegant way of doing this. This all happens on a winXP machine.

A: 

Is the python application opensource? You can look at how the GUI itself hooks up into the back end, and directly import the relative modules into your application, then call it as the GUI would, bypassing this messy hack.

Nazarius Kappertaal
+1  A: 

From the sounds of it, unless Nazarius' excellent suggestion for a first step is infeasible, a program like pyWinAuto would do what you need. We use it to control our own wxPython-based application for use in automated testing, with a Python script controlling the program by entering text into GUI fields, clicking buttons, and so on. The general term for this is "GUI automation" and you can find lots of other information about that by searching. pyWinAuto is only one option available in the Python world for this, but it's a pretty good one.

Peter Hansen