From: Kevin A. <al...@se...> - 2005-03-07 01:39:49
|
I hope Andy's answer below gave you the info you needed. If you just want to call a short script and get a result then calling it from within a handler is probably the right thing to do. However, the application will be unresponsive until the handler finishes. For longer tasks you probably want to start a separate thread for the script. There are examples of using threads in the PythonCard samples. If you need a script to run continuously and communicate with your GUI and let each stay responsive then again you probably want to use a thread and probably pass data back and forth between the threads using the Queue module. Again, there are a number of samples that do this, so just use the findfiles tool to search for Queue in the samples. http://docs.python.org/lib/module-Queue.html http://docs.python.org/lib/module-threading.html I would like to hear more about your project, it sounds fun. Is there any info up on the web...? ka On Jan 24, 2005, at 2:20 AM, Andy Todd wrote: > Dr. Brooks wrote: >> Mr. Todd >> Thank you for your interest . >> While preparing an email in reply to your request for more information >> I launched the PythonCard script from the Pythonwin 2.3.2 interface >> and the PythonVideo image window opened. I have since changed my >> default python launching program to Pythonw (from python 2.3.4) and >> all works well. >> However I do have another question. >> What I am trying to do is have a user interface to a modified >> Evolutions ER1 robot. This interface accepts voice input from Dragon >> Speak NatLink and opens a TCP IP socket and RS232 Com port to my >> robot. It also allows to user to issue commands to the robot's >> Behavior program (a python script). I would like to have the robot's >> behavior program run and send and receive input from the user >> interface. Unfortunately I do not understand the method by which the >> PythonCard GUI communications with other modules. Can I have my my >> behavior program run and communicate with the TextArea of the GUI? >> Can the Behavior Module Call elements of the GUI ? >> It seems that the GUI runs in a loop and thus prevents the Behavior >> Module from executing in parallel. A pointer to an example or >> tutorial would be greatly appreciated. >> Again Thank for Your Interest >> On Mon, 03 Jan 2005 11:06:35 +1100, Andy Todd <an...@ha...> >> wrote: > [snip] >>> > > The answer is a qualified 'depends'. Yes, PythonCard (well, actually > wxPython) executes in a loop and is essentially the controlling > process whenever it runs. > > What you can do, though is import your behaviour program and call it > from your PythonCard application, e.g. > > import myProgram > > class MyApp(model.background): > > def on_<component>_<event name>(self, event): > myProgram.do_something() > > etc ... > > Where it may be troublesome is if your application is asynchronous. > This means that you ask it to do something and then have to keep > checking if it has finished. If that is the case then the > documentation on Timers and Threads may be useful to you; > > http://pythoncard.sourceforge.net/timers-threads.html > > If any of your calls are synchronous (i.e. return control to > PythonCard when they have finished) then writing the program is > easier. Just included in your PythonCard program anything that you > would normally type at the Python prompt. > > I've cc'ed this message to the PythonCard users list as you will > always get good feedback from the good people there. They will > generally be more prompt in answering your questions, as you can see I > get round to my email in fits and starts and your chances of a useful > and timely reply increase with the number of people who see it. > > Regards, > Andy |