Threads and GUI question

Grant Edwards grante at visi.com
Tue Oct 22 12:18:55 EDT 2002


In article <mailman.1035300268.5770.python-list at python.org>, Alessandro Bottoni wrote:

>> I am using wxWindows in win2000 to start a loop that writes to a COM -port:
>>
>> runOK = 1
>> while runOK != -1:
>>          -- write data to COM -port--
>>
>> My original idea was to have a Stop -selection in menubar,
>> that would set runOK = -1 and cause the while loop above to stop.
>>
>> The problem is that menubar does not response while
>> the while -loop is running.

> I think that your original idea does not work just because the
> while loop does not give the GUI any time (that is: any CPU
> cicle) for listening to the user's actions. Just add a sleep(n)
> (where n are seconds) inside the while loop and it should work
> fine.

Does wxWindows use a separate thread for the GUI?  Most of the
widget tookits I've used don't.  If that's the case with
wxWindows, then putting a sleep() into the loop won't help.

Generally there's a single event handling loop, and the GUI
wont respond until your code returns control to that loop.  The
way this is usually handled is to tell the widget-kit to add
the serial port to the list of "events" it watches for in its
main event loop and tell it what handler to call when the port
is ready to read or write.

> Have a look at the wxWindows doc for the details and the
> correct sintax. Look for "sleep", "process control" or "process
> management".

-- 
Grant Edwards                   grante             Yow!  Finally, Zippy
                                  at               drives his 1958 RAMBLER
                               visi.com            METROPOLITAN into the
                                                   faculty dining room.



More information about the Python-list mailing list