dabo Commit
Revision 5647
Date: 2010-02-04 21:55:40 -0800 (Thu, 04 Feb 2010)
Author: Paul
Trac: http://trac.dabodev.com/changeset/5647

Changed:
U   trunk/dabo/ui/uiwx/dPemMixin.py

Log:
Finally figured out how to react to the destroy event before the C++ part of 
the object is inaccessible: in most cases, bind to the parent. I still had to
bind to self as well to cover all cases, and put a hack in the handler to 
only react to the first destroy event.


Diff:
Modified: trunk/dabo/ui/uiwx/dPemMixin.py
===================================================================
--- trunk/dabo/ui/uiwx/dPemMixin.py     2010-02-05 05:52:02 UTC (rev 5646)
+++ trunk/dabo/ui/uiwx/dPemMixin.py     2010-02-05 05:55:40 UTC (rev 5647)
@@ -367,6 +367,15 @@
        def _initEvents(self):
                # Bind wx events to handlers that re-raise the Dabo events:
                targ = self._EventTarget
+
+               # Bind EVT_WINDOW_DESTROY twice: once to parent, and once to 
self. Binding 
+               # to the parent allows for attribute access of the child in the 
dEvents.Destroy
+               # handler, in most cases. In some cases (panels at least), the 
self binding fires
+               # first. We sort it out in __onWxDestroy, only reacting to the 
first destroy
+               # event.
+               parent = self.GetParent()
+               if parent:
+                       parent.Bind(wx.EVT_WINDOW_DESTROY, self.__onWxDestroy)
                self.Bind(wx.EVT_WINDOW_DESTROY, self.__onWxDestroy)
                self.Bind(wx.EVT_IDLE, self.__onWxIdle)
                self.Bind(wx.EVT_MENU_OPEN, targ.__onWxMenuOpen)
@@ -518,7 +527,12 @@
                
                
        def __onWxDestroy(self, evt):
-               self._finito = (self == evt.GetEventObject() )
+               if getattr(self, "_destroyAlreadyFired", False):
+                       # we bind twice, once to parent and once to self, 
because some wxPython
+                       # objects are still accessible this way while others 
are not. 
+                       return
+               self._finito = (self is evt.GetEventObject() )
+               self._destroyAlreadyFired = True
                self.raiseEvent(dEvents.Destroy, evt)
 
                



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to