[wxPython-users] nested window sizers crashes wxpython

Robin Dunn robin at alldunn.com
Fri Mar 14 16:31:14 PDT 2008


Tim Black wrote:

> class MyOtherPanel(wx.Panel):
>     """Creating one of these seems to crash wxPython."""
>     def __init__(self, parent):
>         wx.Panel.__init__(self, parent, -1)
>         self.MainStaticBoxSizer = StaticBoxSizer(self, wx.HORIZONTAL,
> label="MyOtherPanel" )   
>         self.Sizer = wx.GridBagSizer(2, 2) # vgap, hgap

self.Sizer (with the capital S) is a property that maps to the 
GetSizer/SetSizer methods, so this statement is the same as calling 
self.SetSizer(...).

>         self.item1 = wx.StaticText(self, -1, "item1")
>         self.Sizer.Add(self.item1, (0, 1), (1, 2))
>         self.item2 = wx.StaticText(self, -1, "item2")
>         self.Sizer.Add(self.item2, (1, 1), (1, 1))
>         self.item3 = wx.StaticText(self, -1, "item3")
>         self.Sizer.Add(self.item3, (1, 2), (1, 1))
>         print "Adding grid bag sizer to static box sizer..."
>         self.MainStaticBoxSizer.Add(self.Sizer, proportion=1,
> flag=wx.EXPAND|wx.ALL, border=2)

Here the current sizer attached to the window is getting added to 
MainStaticBoxSizer, because the self.Sizer evaluates to self.GetSizer().

>         print "Done"
>         self.SetAutoLayout(1)
>         print "Setting window sizer to static box sizer..."
>         self.SetSizer(self.MainStaticBoxSizer)

So this ends up deleting the grid bag sizer because the SetSizer will 
first destroy any sizer that is already attached to the window, but the 
MainStaticBoxSizer still thinks that it exists and will try to use it 
for the layout.


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





More information about the wxpython-users mailing list