From: Alex T. <al...@tw...> - 2005-10-23 00:23:51
|
Mike Pippin wrote: > I want to use a python card GUI to get information from users and save > it to a file then when a button is clicked close the pythonCard gui > and start an application running in pygame.....But I also want the > ability from the pygame application to close the pygame application > and reopen the PythonCard app.....Im having trouble figuring out > pythoncard because of the lack of documentation > > ..... How would I start and close a pythoncard app from another module??? > > I can get my pythoncard app up and running but only when directly > using the module the app is defined in........I am coming close to the > deadline of an application and I can restart it without using > pythoncard...But I would really prefer not to....So any help I can get > asap would be greatly appreciated Mike, there are three basic approaches you *might* take, and I'm not sure which one you are trying (far less which one to recommend). When you say "start and close a Pythoncard app from another module", I'm not sure if you mean "a separate app" of whether you're trying to do both within a single application executable. So this is a kind of generic response to the question - if you can fill in more detail of what you need (or want) I can try to be more specific. The reason this is difficult is that both wx and pygame like to have control of the event loop - so there are likely to be conflicts between them The three approaches I can see to this overall idea are: 1. A wxPython application, which uses a pygame (SDL) window. This is perhaps the most complex - there is some discussion of it on http://wiki.wxpython.org/index.cgi/IntegratingPyGame It uses threads and explicit control over the pygame event loop. 2. a dual-mode application (may be easy, may be impossible) I can't find any examples of other people having tried this - so it may be impossible. But it might be possible to have an overall application in which you never have both pygame GUI and wx GUI active. The app would need to start one up (say wxPython) - than when it had done everything it needed to do, it could simply exit to the main app - which could start up the pygame GUI; it in turn would exit and the main app would (if appropriate) start the wxPython GUI up again. I did a simple test of the wxPython part of this - starting and re-starting the wxPython event loop, and it appears to work. Take any of the basic PythonCard applications from the sample directory, and you will find at the end of the source something like: > > if __name__ == '__main__': > app = model.Application(Boids) > app.MainLoop() I simply changed this to if __name__ == '__main__': while 1: print "round the main loop again" app = model.Application(Boids) app.MainLoop() and the when I exited the PythonCard program, it would again print out the message and restart the GUI. So this gives me some hope it could be done; I don't have pygame installed (and can't find a Python2.3 installer for it), so I wasn't able to test whether or not you can start / end / restart pygame as easily. 3. Easy, simple, recommended. Just make them two separate applications. Have the user run the PythonCard application, gather any data you need, etc. Then when she clicks on the button, you start another completely separate app to run the pygame app. (using os.execl() or similar). When ready to switch back from the pygame app, do the same thing to re-run the initial PythonCard app -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.361 / Virus Database: 267.12.4/146 - Release Date: 21/10/2005 |