How do I Block Events in wxPython

Frank Millman frank at chagford.com
Fri Dec 11 02:00:23 EST 2009


Stephen Hansen wrote:
>
> Well if you have a legitimate case for pre-empting the event loop with 
> these
> periodic regular short blocking moments (it seems you may), I think what 
> you
> want to do is overwrite FilterEvent on your App object. You can then make
> that flag something you set on the app, and while it's true, returning 
> False
> (or True, I really don't know the differenced between telling wx 'Ok, I
> processed this event you can ignore it' and 'Ok, I'm not going to process
> this event and neither should you'). Otherwise, return -1.
>

This works beautifully - thanks, Stephen.

As you say, the difference between returning True or False is not clear, but 
in practice I found that I had to return True - then all mouse and keyboard 
activity is blocked.

There is another step required, which I did not find in the docs, but found 
in help(wx.App.FilterEvent). If you override FilterEvent, you also have to 
call SetCallFilterEvent(True) on the App object when you want it to be 
called, and set it back to False when finished. This is handy, as it avoids 
the overhead of calling it when you don't need it.

In fact, as I am writing this, I realise that I don't need a flag at all. I 
just override FilterEvent, and return True. Then when I want to block, I 
call SetCallFilterEvent(True), and when I want to stop, I call 
SetCallFilterEvent(False).

This is very useful. Thanks again.

Frank






More information about the Python-list mailing list