How do I Block Events in wxPython
Jeff Peck
jpeck at fedex.com
Wed Dec 9 12:00:47 EST 2009
Philip Semanchuk wrote:
>
> On Dec 9, 2009, at 10:42 AM, 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?
>
>
> Hi Wanderer,
> I don't have a solution for you but I have three suggestions.
>
> First, your program shouldn't be locking up just because you clicked
> on it. IMO that's the real problem, and discarding events is just a
> band-aid to cover it up. Nevertheless, sometimes a band-aid is an
> appropriate solution and you're the best judge of that.
>
> Second, the wxPython mailing list would be a better place for this
> question.
>
> Third, if you can't seem to resolve the problem, try paring it down to
> a minimal example that reproduces the problem. It's difficult to offer
> suggestions when we can't see the whole code or try the sample code
> ourselves.
>
>
> Good luck
> Philip
Wanderer,
I agree with Philip. You probably want your calculation code in a
separate thread. I'd advise against this, but if you're just looking for
a bandaid you could try creating an event handler to catch the mouse
clicks and simply call event.Skip(). If you do this, you might have to
introduce a flag that gets set to True only during your calculation, and
then your event hander could look something like this:
def OnMouseClick(self, event):
# Only skip mouse click event if calculating
if self.busy:
event.Skip()
Jeff
More information about the Python-list
mailing list