I've started a project that does a series of database queries that then returns data to be displayed to the user.
There is one grid control that drives the other three where as the user selects a row and that then sends a new query to the database to populate the other three tables.
The trouble I'm running into is layout. I've set up a few sizers and I made a subclass of wx.Panel to put the grid controls in. The issue I have is sizing the grid controls. I've tried a few different things with sizer.Fit() and sizer.FitInside() and things however nothing seems to get the grid controls to lay out like I need them to. Here is what I have with some minor things excluded.
It works for the most part, except for the fact that the grids are not expanding to fill the panels / sizer space. I'm not sure what I should add to make them fill the space in the sizer but not make the frame any larger.
Thanks for any and all help
Joe Losco
class myFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size = (200,200))
self.panel = wx.Panel(self, -1)
self.setUpSizers()
self.SetSizer(self.sizer)
self.sizer.Fit(self)
self.Center(direction = wx.BOTH)
def setUpSizers(self):
self.sizer = wx.BoxSizer(wx.VERTICAL) #main sizer including all others.
self.topbarsizer = wx.GridBagSizer(hgap=1, vgap = 1) #button bar on top
self.mainsizer = wx.BoxSizer(wx.HORIZONTAL) #main content sizer including both left and right sizers.
self.leftsizer = wx.BoxSizer(wx.VERTICAL)
self.rightsizer = wx.BoxSizer(wx.VERTICAL)
···
----------------
CODE to set up buttons etc not included to make message smaller
is top bar sizer
----------------
self.sizer.Add(self.topbarsizer, flag = wx.EXPAND)
grid = GridPanel(self) #example grid
self.rightsizer.Add(grid, 2, flag = wx.EXPAND)
grid = GridPanel(self)
self.leftsizer.Add(grid, 2, flag = wx.EXPAND)
grid = GridPanel(self)
self.rightsizer.Add(grid, 1, flag = wx.EXPAND)
grid = GridPanel(self)
self.leftsizer.Add(grid, 1, flag = wx.EXPAND)
self.mainsizer.Add(self.leftsizer,1, flag = wx.EXPAND)
self.mainsizer.Add(self.rightsizer,1, flag = wx.EXPAND)
self.sizer.Add(self.mainsizer,-1,flag = wx.EXPAND)
class GridPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
grid = wx.grid.Grid(self, -1)
grid.CreateGrid(40, 40)
for row in range(40):
for col in range(40):
grid.SetCellValue(row, col,
"cell (%d,%d)" % (row, col))