Rules/Guidelines for Event Handler cleanup?

OK - I haven't got a test case yet - I just sometimes see random behaviour
with help messages that I can't explain yet. If I narrow it down to a test
case, I'll post it here.

Thanks,

S.

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Thursday, May 08, 2003 5:42 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] Rules/Guidelines for Event Handler
cleanup?

Sean Slattery wrote:
>
> Are there any suggestions/rules for how to clean up event
handlers for
> windows that disappear during the course of the
application? I'm getting
> buggy behaviour that could be because an event handler for
a deleted window
> is still active. Can this happen?
>
> For example, if I create an wxTreeCtrl and set up an
EVT_HELP handler, do I
> need to disconnect that handler explicitly when the
wxTreeCtrl is nuked (the
> frame it was in is destroyed)?

No, the event handler table is destroyed when the C++ window
instance is
destroyed. In the process the reference counts for the handler
functions are decremented as well as the reference to the
Python proxy
object for the window.

In rare cases there can sometimes still be a message waiting for the
window and it can cause problems when trying to deliver it to an
instance that has been destroyed. If you suspect something like this
then please provide a sample and we'll try to fix it.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org

I've addressed this issue in the past but putting this in my event
handler:

    def onSomeEvent(self, event):
        if not self:
            return
        ....

This works because when wxWindows objects are destroyed the Python
wrapper objects become PyDeadObjects which evaluate to false.

This issue came up for me because of aggressive wx.CallAfter()
invocations, some of which were still around as the application was
being shut down.

This technique might work for you, Sean.

···

--
Chuck
http://ChuckEsterbrook.com

On Monday 12 May 2003 03:48 am, Sean Slattery wrote:

OK - I haven't got a test case yet - I just sometimes see random
behaviour with help messages that I can't explain yet. If I narrow it
down to a test case, I'll post it here.

Thanks,

S.

> -----Original Message-----
> From: Robin Dunn [mailto:robin@alldunn.com]
> Sent: Thursday, May 08, 2003 5:42 PM
> To: wxPython-users@lists.wxwindows.org
> Subject: Re: [wxPython-users] Rules/Guidelines for Event Handler
> cleanup?
>
> Sean Slattery wrote:
> > Are there any suggestions/rules for how to clean up event
>
> handlers for
>
> > windows that disappear during the course of the
>
> application? I'm getting
>
> > buggy behaviour that could be because an event handler for
>
> a deleted window
>
> > is still active. Can this happen?
> >
> > For example, if I create an wxTreeCtrl and set up an
>
> EVT_HELP handler, do I
>
> > need to disconnect that handler explicitly when the
>
> wxTreeCtrl is nuked (the
>
> > frame it was in is destroyed)?
>
> No, the event handler table is destroyed when the C++ window
> instance is
> destroyed. In the process the reference counts for the handler
> functions are decremented as well as the reference to the
> Python proxy
> object for the window.
>
> In rare cases there can sometimes still be a message waiting for
> the window and it can cause problems when trying to deliver it to
> an instance that has been destroyed. If you suspect something like
> this then please provide a sample and we'll try to fix it.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> -------------------------------------------------------------------
>-- To unsubscribe, e-mail:
> wxPython-users-unsubscribe@lists.wxwindows.org For additional
> commands, e-mail:
> wxPython-users-help@lists.wxwindows.org

---------------------------------------------------------------------
To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwindows.org For additional
commands, e-mail: wxPython-users-help@lists.wxwindows.org