How do I Block Events in wxPython

Stephen Hansen apt.shansen at gmail.com
Thu Dec 10 02:57:59 EST 2009


On Wed, Dec 9, 2009 at 10:21 PM, Frank Millman <frank at chagford.com> wrote:

> 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 don't think "blocking" events is the right way to think about this.

If you need to halt new input for some reason (bearing in mind that its best
to run such things in a background task, but yes, sometimes blocking the UI
is important), then there's a couple ways to go about it. But trying to mess
with the event loop isn't it.

First, you always want a visual indicator-- use SetCursor on your top level
window to set a busy cursor. You never want any sort of block-ish action to
happen without the user being able to see "something is going on"; if its
more then a second or so I /really/ think you should throw up a progress
indicator dialog, even if its an infinate one.

To actually 'block' the events themselves, you can just call
wnd.Enable(False). Just be sure to Enable(True) when you want to process
stuff again.

Another approach is to use wnd.CaptureMouse() on a particular control which
doesn't really respond to anything. Just be sure to ReleaseMouse() later and
follow the instructions in the docs about capturing that cancel-capture
event.

HTH,
--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091209/e9df92f3/attachment-0001.html>


More information about the Python-list mailing list