I’ve recently found that some events are catched by some widgets after my application exits. Consequently, when some buttons are clicked just before the window is closed a PyDeadObjectError exception is generated. To prevent this kind of exception, I use the Freeze method without using its counterpart Thaw to prevent the user to click on a button and propagate unwanted events.
Is there a more elegant way to deactivate event propagation when a user choose to exit an application ?
I've recently found that some events are catched by some widgets after
my application exits. Consequently, when some buttons are clicked just
before the window is closed a PyDeadObjectError exception is generated.
To prevent this kind of exception, I use the Freeze method without using
its counterpart Thaw to prevent the user to click on a button and
propagate unwanted events.
Is there a more elegant way to deactivate event propagation when a user
choose to exit an application ?
PyDeadObjectError exceptions can be avoided by testing the window before calling its methods, perhaps something like this:
if not self:
return
self.SetSomething(something)
In some cases there may be events that cause problems when a frame has started to be destroyed, but it still exists (so the if self test won't work) and some of its children have already been destroyed. There is an IsBeingDeleted method that can be used in those cases, for example:
if not self or self.IsBeingDeleted():
return
for child in self.Children():
child.DoSomething()
Or if you are nested several layers deep, then you can use something like self.GetTopLevelParent().IsBeingDeleted().
Have you got a link explaning how to do class decorators in order to not do the job for all problematic methods ?
Cheers.
···
Le jeudi 24 octobre 2013 00:15:53 UTC+2, Robin Dunn a écrit :
Thierry Brizzi wrote:
Hi,
I’ve recently found that some events are catched by some widgets after
my application exits. Consequently, when some buttons are clicked just
before the window is closed a PyDeadObjectError exception is generated.
To prevent this kind of exception, I use the Freeze method without using
its counterpart Thaw to prevent the user to click on a button and
propagate unwanted events.
Is there a more elegant way to deactivate event propagation when a user
choose to exit an application ?
PyDeadObjectError exceptions can be avoided by testing the window before
calling its methods, perhaps something like this:
if not self:
return
self.SetSomething(something)
In some cases there may be events that cause problems when a frame has
started to be destroyed, but it still exists (so the if self test won’t
work) and some of its children have already been destroyed. There is an
IsBeingDeleted method that can be used in those cases, for example:
if not self or self.IsBeingDeleted():
return
for child in self.Children():
child.DoSomething()
Or if you are nested several layers deep, then you can use something
like self.GetTopLevelParent().IsBeingDeleted().