I am trying to show/hide a bank of controls by removing an
interior sizer from another sizer (hide) and then reinserting
it (show). The problem is, that I get a wxPyDeadObject
after calling Sizer.Remove. The docs for Remove say that
the window is not deleted - is this true for sizers or
is there some problem with OOR?
Looking at the C++ code in the wxWindows sources, the
code for removing a window or a sizer seems similar
enough that I think that if a window isn't deleted then
neither is a sizer. So what's up? Are the docs wrong
and the window or sizer actually deleted or is this
a problem with OOR and this new wxPyDeadObject?
I suspect that it's the docs that are incorrect, but if not
then there's the possibility of a memory leak.....
code:
def updateToolbar(self):
#Fix up toolbar if necc
#openButton
inst = self.pw.instance
def getWindow(item):
if item.IsWindow():
return item.GetWindow()
def getSizer(item):
if item.IsSizer():
return item.GetSizer()
#process the 'showControls' feature first:
#if we remove the ctlsSizer (or it's already removed)
#then we don't need to (and can't, since it doesn't exist)
#process the removal or addition of the load button!
state = inst.showControls
wins = self.box.GetChildren()
#need to get list of SIZERs this time
wins = map(getSizer,wins)
target = self.ctlsSizer <------------------------------------this becomes a wxPyDeadObject after -
present = target in wins
if not present and state == 1: #then add it
self.box.PrependSizer(target,0, wxCENTER) |
self.box.Layout()
if present and state == 0: #then remove it |
self.box.RemoveSizer(target) <----------------------------------------this is executed! -----------
self.box.Layout()
#process add/remove LOAD button
if state: #if the ctls Sizer is present
#handle the LOAD button
state = inst.showLoad
wins = self.ctlsSizer.GetChildren() #but this is a list of wxSizerItems
#need a list of windows!
wins = map(getWindow,wins)
target = self.openButton
present = target in wins
if not present and state == 1: #then add it
self.ctlsSizer.PrependWindow(target,1, wxALL, 2)
self.ctlsSizer.Layout()
if present and state == 0: #then remove it
self.ctlsSizer.RemoveWindow(target)
self.ctlsSizer.Layout()
···
#--------------------------------
Jeff Sasmor
jeff@sasmor.com