I'm encountering confusing (at least to me) behavior when spanning
items across rows and columns that haven't had an item specifically
added to them.
In the contrived example I will post below, I am creating two red
blocks on the top and bottom of the column that each span two rows. I
placed a green block that only spans a single row in the next column
over. As you can see when you run the script, the height of the
spanning blocks are only a single row in height. However, if I add an
empty panel into the rows where the blocks are spanning into, the
example works as I expect. You can uncomment the block of code that
performs those actions to see the desired behavior.
##############################Begin Awesome ASCII
Art###############################
What I'd like to see:
XX
X
o
o
o
o
X
X
What I'm seeing:
XX
o
o
o
o
X
###################################Begin
Code#######################################
import wx
class Box(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, pos=(100, 100),
style=wx.SIMPLE_BORDER)
self.wnwBorder = wx.Panel(self, wx.ID_ANY)
self.wBorder = wx.Panel(self, wx.ID_ANY)
self.wswBorder = wx.Panel(self, wx.ID_ANY)
self.nBorder = wx.Panel(self, wx.ID_ANY)
self.wnwBorder.SetBackgroundColour('red')
self.wBorder.SetBackgroundColour('black')
self.wswBorder.SetBackgroundColour('red')
self.nBorder.SetBackgroundColour('green')
self.sizer = wx.GridBagSizer()
self.sizer.Add(self.wnwBorder, (0, 0), (2, 1), wx.EXPAND)
self.sizer.Add(self.wBorder, (2, 0), (1, 1), wx.EXPAND)
self.sizer.Add(self.wswBorder, (3, 0), (2, 1), wx.EXPAND)
self.sizer.Add(self.nBorder, (0, 1), (1, 1), wx.EXPAND)
···
#===============================================================================
# #Put me in to make the example work as expected
# self.sizer.Add(wx.Panel(self), (1, 1))
# self.sizer.Add(wx.Panel(self), (4, 1))
#===============================================================================
self.sizer.AddGrowableRow(2)
self.SetSizer(self.sizer)
self.SetSize((200, 200))
#self.sizer.Fit(self)
print self.sizer.GetCellSize(0, 0), self.sizer.GetCellSize(1,
0), self.sizer.GetCellSize(2, 0), self.sizer.GetCellSize(3, 0),
self.sizer.GetCellSize(4, 0)
app = wx.App(0)
frame = wx.Frame(None, title="HELLO")
panel = wx.Panel(frame)
panel.SetBackgroundColour('pink')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel, 1, wx.EXPAND)
frame.SetSizer(sizer)
m = Box(panel)
frame.SetSize((600, 400))
frame.Show()
app.MainLoop()