When is wx.EvtHandler.Unbind() recommended/required?
I am attempting maintenence of an application where users interact with hundreds
of controls per virtual page (implemented as a wx.Panel), and with scores of
such pages. Apparently some users must run other resource-intensive applications
concurrently, reportedly hitting the platform-specific (Windows XP) limit of 64k
native window objects. Reconfiguration of user kernels is not an acceptable
workaround.
I propose changing the application to instantiate panels only when they are
viewed, and then wx.Window.Destroy() them - instead of wx.Window.Hide() them -
when they are not in the users' view. But I cannot find an overview describing
if/when/why Unbind() is recommended. I raise six questions below.
I am using Python 2.7.2, wxPython 2.8.12.1, win32, (wxMSW, Unicode,
wx-assertions-on, SWIG-1.3.29)
Example A: thisPanel.Bind(wx.EVT_BUTTON, thisPanel.onButton,
source=thisPanel.button)
My understanding from Robin Dunns' notes in this forum: when thisPanel.Destroy
is invoked, the dynamic event handler table (of thisPanel) is destroyed after
pending events are processed.
Q1. thisPanel.Unbind(wx.EVT_BUTTON) does not need to be invoked
before invoking thisPanel.Destroy(), correct?
Example B: thisFrame.Bind(wx.EVT_BUTTON, thisPanel.onButton,
source=thisPanel.button)
Here thisFrame is the parent of thisPanel, and it will not be closed/destroyed.
Q2. Should the UnBind() below be invoked before thisPanel.Destroy()?
thisFrame.Unbind(wx.EVT_BUTTON, handler=thisPanel.onButton,
source=thisPanel.button)
Q3. What problems (e.g. memory growth) might result if
this Unbind() is not done?
Example C: anotherFrame.Bind(wx.EVT_BUTTON, thisPanel.onButton,
source=anotherFrame.button)
Here anotherFrame is outside the containment hierarchy of thisPanel's parents
and children, and it will not be closed/destroyed.
Q4. I presume this should be treated like Example B,
e.g. anotherFrame.Unbind(… handler=thisPanel.onButton) before
invoking thisPanel.Destroy()? Are there different problems that
might result if this is not done?
Currently panel methods are bound to events within their class __init__()
method. Instead of invoking thisPanel.Destroy() external to the class methods, I
propose to invoke thisPanel.Close(). Each panel would implement this:
def __init__(self, ...):
...
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, evt):
"""Unbind() any methods of this instance that are
bound to event sources (menu items or windows) that
are not children of this instance."""
...
self.Destroy()
Q5. Would this work, and would it be considered good Python/wxPython style?
Curiously, Bind() and Unbind() are not included in the wxPython documentation
application titled "wxWidgets 2.8.12: A portable C++ and Python GUI toolkit",
though they can be found in their C++ form at
http://www.wxpython.org/docs/api/wx.EvtHandler-class.html. Alas, I do not know
C++, and am new to Python and wxPython.
Q6. Does this documentation difference imply that use of these
methods is discouraged or deprecated?
Thank you in advance for your educational efforts on my behalf.