How do I Block Events in wxPython

Frank Millman frank at chagford.com
Thu Dec 10 01:21:34 EST 2009


Wanderer wrote:

>I have a wxPython program which does some calculations and displays
> the results. During these calculations if I click the mouse inside the
> dialog the program locks up. If I leave the dialog alone the process
> completes fine. I have tried running the function from a separate
> dialog with Show Modal and I have tried using SetEvtHandlerEnabled all
> to no avail. The program is long and occupies several files so I won't
> show the whole thing but here is the calculation part. How do I block
> events?
>

I also need to block events in my wxPython app, though the time duration is 
very short. I have a separate thread that sends notification of gui events 
to a server, and waits for a response. I do not want the user to do anything 
until the response is received.

I use threading.Event() for this -
    import threading
    event_waiting = threading.Event()
    event_waiting.set()  # set event to True

In the gui thread, when I want to block, I have this -
    event_waiting.clear()  # set event to False
    event_waiting.wait()   # block until event becomes True

In the worker thread, when the response has been received and acted upon, I 
have -
    event_waiting.set()  # set event to True, which unblocks the gui thread

HTH

Frank Millman
 






More information about the Python-list mailing list