[wxPython] Oddity in wxSizer.Remove

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

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?

Windows are owned by their parent window. Sizers are owned by the window or
the parent sizer, so they are deleted when you remove them from a parent
sizer.

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?

Look at wxSizerItem::~wxSizerItem.

···

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

OK, thanx. Then the way to do what I want is to group all
the controls on a little window or panel with a sizer in _it_
and add or delete the _panel_ rather than the sizer!

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com
----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Thursday, May 23, 2002 4:05 PM
Subject: Re: [wxPython] Oddity in wxSizer.Remove

> 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?

Windows are owned by their parent window. Sizers are owned by the window or
the parent sizer, so they are deleted when you remove them from a parent
sizer.

>
> 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?

Look at wxSizerItem::~wxSizerItem.

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

OK, thanx. Then the way to do what I want is to group all
the controls on a little window or panel with a sizer in _it_
and add or delete the _panel_ rather than the sizer!

Yep that should work. And you'll also want to Hide() it when you remove it
from the sizer.

···

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