Cleaning up panel resources when a parent frame is closed
I try to create reusable windows as subclases of wx.Panel and then insert them into frames as needed. This morning I had a panel that needed to perform some cleanup. The problem was that the close event happens on the frame, not the panel. Overriding the obvious methods, Destroy, Close, etc did not work as expected. I found the answer from Robin Dunn deep in the wxPython mailing list:
<pre>
# __init__ method of wx.Panel subclass
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def OnDestroy(self, event):
## clean up resources as needed here
event.Skip()
</pre>
Seems obvious now. Another step forward in learning the wxPython/wxWidgets philosophy.





