wx.Grid inside multiple sizers

Did you try with rulegrid.SetMaxSize()?

···

2009/2/8 David LePage dwlepage@yahoo.com

I apologize if this has been asked before but I’ve scoured all sources without any luck.

I’ve got a wxPython wizard that is basically a single frame that will show/hide widgets as the user progresses through the prompts. The frame is not resizable.

On one of the pages i’m displaying a wx.Grid that is added to a Horizontal BoxSizer, and that BoxSizer is then added to Vertical BoxSizer, which is added to the main panel.

Everything is fine if there is no data in the Grid, it displays within the frame and panel properly.

Once I start adding data to the wx.Grid, it expands out to the right beyond the borders of the frame rather than creating scrollbars so I cannot get to any of the cells.

I think all I need to do is somehow force the grid to remain with the confines of the horizontal boxsizer but can’t seem to figure it out.

Here is a small sample of the code (the entire project is a bit big so this is only a small part to show the problem):

class ModelExample(wx.Frame):

def init(self, parent, id):

wx.Frame.__init__(self, parent, id, 'Policy Convertor', #size=(724,600), style=wx.DEFAULT_FRAME_STYLE ^ (wx.RESIZE_BORDER | wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX))



self.SetIcon(wx.Icon('icons\\Sidewinder.ico', wx.BITMAP_TYPE_ICO))

panel = wx.Panel(self)

panel.Centre()



self.panel = panel

self.page = 1 #keep track of which page we should display



#Call our model class

self.model = CollectedInput(None, None)

#Add listener methods. Any time these are called, our model class is notified

self.model.addListener(self.OnUpdate)

#top level vertical sizer

vsizer = wx.BoxSizer(wx.VERTICAL)

panel.SetSizer(vsizer)



#horizontral sizer for button menu at bottom of frame

hsizer = wx.BoxSizer(wx.HORIZONTAL)



#horizontal box for bitmap image

bitmapbox = wx.BoxSizer(wx.HORIZONTAL)

sb = wx.StaticBitmap(panel, wx.ID_ANY, wx.BitmapFromImage(wx.Image('icons\\StartWizard.png', wx.BITMAP_TYPE_ANY)))

bitmapbox.Add(sb, 0, wx.ALL, 5)

#vertical box for holding main part of panel (rt of the image)

vmainbox = wx.BoxSizer(wx.VERTICAL)



#main boxsizer for main part of screen - to the right of the banner image

mainbox = wx.BoxSizer(wx.HORIZONTAL)

title = wx.StaticText(panel, wx.ID_ANY, "Welcome to the Policy Migration Tool", (0,0))

title.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD))

mainbox.Add(title, 0, wx.EXPAND, 1)

descpg4box = wx.BoxSizer(wx.HORIZONTAL)

descpg4 = wx.StaticText(panel, wx.ID_ANY, "Here are a list of rules    found from your policy. Please verify these rules look correct", (0,0))

descpg4.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL))

descpg4box.Add(descpg4, 0, wx.EXPAND, 1)



rulemapbox = wx.BoxSizer(wx.HORIZONTAL)

#create an empty grid - gets updated in GetBurbGridData

rulegrid = wx.grid.Grid(panel, wx.ID_ANY)

rulemapbox.Add(rulegrid, 1, wx.EXPAND | wx.ALL, 5)



vmainbox.Add(mainbox, 0, wx.TOP, 5)

vmainbox.Add(descbox, 0, wx.ALL, 5)

vmainbox.Add(sbsizer, 0, wx.ALL | wx.LEFT, 5)

vmainbox.Add(sbbtmsizer, 0, wx.ALL | wx.LEFT, 5)

vmainbox.Add(descpg2box, 0, wx.ALL | wx.BOTTOM, 5)

vmainbox.Add(burbmapbox, 0, wx.ALL | wx.BOTTOM, 5)

vmainbox.Add(descpg3box, 0, wx.ALL | wx.BOTTOM, 5)

vmainbox.Add(updaterbox, 0, wx.ALL | wx.EXPAND | wx.BOTTOM, 5)

vmainbox.Add(rulestatsbox, 0, wx.ALL | wx.EXPAND | wx.BOTTOM, 5)

vmainbox.Add(ckptbuttonbox, 0, wx.ALL | wx.CENTER, 5)

vmainbox.Add(descpg4box, 0, wx.ALL | wx.BOTTOM, 5)

vmainbox.Add(rulemapbox, 0, wx.ALL | wx.BOTTOM, 5)

The rulegrid is populated when the user clicks the Next button by the following method:

def make_rulegrid(self, panel):

rulemap = ["rule", "src", "src burb", "dest", "dest burb", "service", "action", "nat"]

rulelist = ConverterUtil.get_rules()

self.rulegrid.CreateGrid(len(rulelist), len(rulemap)) #x and y

#print margin heading

for x in range(len(rulemap)):

  self.rulegrid.SetColLabelValue(x, rulemap[x])



#align rule data with proper cell heading

for col in range (len(rulelist)):

  rule = rulelist[col]

  print "rule is: ", rule

  if rule:

    if rule["Number"]:

      self.rulegrid.SetCellValue(col, rulemap.index("rule"), rule["Number"])

    if rule["From"]:

      self.rulegrid.SetCellValue(col, rulemap.index("src"), rule["From"])

    if rule["To"]:

      self.rulegrid.SetCellValue(col, rulemap.index("dest"), rule["To"])

    if rule["Service"]:

      self.rulegrid.SetCellValue(col, rulemap.index("service"), rule["Service"])

self.rulegrid.SetRowLabelSize(17)

self.rulegrid.SetColLabelSize(15)

self.rulegrid.AutoSize()

Thanks very much!

David


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users