My guess is that the replaced sizer is being destroyed twice, once by Replace, and once by wxPython when the refcount of the proxy object goes to zero. Try checking the value of attributeSizer.thisown after the call to choiceBox.sizer.Replace. If it's True then set it to False, and that should work around the problem.
···
On 6/22/11 9:13 AM, Neacsa Bogdan Valentin wrote:
Hello,
So I have a wx.Choice and a bunch of attributes that for each choice in
the checkbox. So each time I select something I need the old widgets
(buttons, textCtrls etc.) to dissapear and get replaced by the
coresponding components for the current selection. My approach is:def onChoice(self, event):
choiceBox = event.GetEventObject()
if hasattr(choiceBox, 'sizer'):
if hasattr(choiceBox, 'childSizer'):
choiceBox.childSizer.DeleteWindows()
attributeSizer = wx.FlexGridSizer(1, 2, 10, 10)
attributeSizer.itemIndex = 0
attributeSizer.AddGrowableCol(1)
print "Step 1"
choiceBox.sizer.Replace(choiceBox.childSizer, attributeSizer)
print "Step 2"
choiceBox.childSizer = attributeSizer
self._addAttributes(choiceBox.options, choiceBox, choiceBox.sizer)
print "Step 3"
choiceBox.sizer.Layout()
Here, choiceBox.sizer is the sizer that contains the wx.Choice, so the
parent sizer. choiceBox.childSizer is the sizer that contains the
specific components for each choice._addAttributes is the method that adds the necessary widgets to
childSizer. Now the part I don't understand is that for the first
refresh everything works fine and the sizers are replaced properly. But
the second time python crashes. So first time I get the output:Step 1
Step 2
Step 3
But the second time just: Step 1 then crash :
--
Robin Dunn
Software Craftsman