wxGrid not sizing right

Hi,

Try this with width and height by trial and error:
self.grid.SetSize((width, height))

Regards,
Steven.

Jeffrey O'Neill wrote:

···

Dear List,

I have a dialog with a few nested sizers and a custom wxGrid. Everything worked fine with 2.4.2.4 but the sizing isn't working right with 2.5.1.5. (I'm on windows 2000 with Python 2.3.) Basically, the dialog isn't made big enough for the grid so scroll bars are added. I would rather have the size of the dialog increase so scroll bars would not be necessary.

Another issue is that wxGrid.AutoSize() doesn't seem to work as advertised.

A screenshot of the dialog is at http://www.people.cornell.edu/pages/jco8/griddlg.jpg. A code snippet is also pasted below.

Any hints as to how I should go about fixing this? Any help greatly appreciated.

Jeff

##################################################################

class BallotsDialog(wx.Dialog):

  def __init__(self, parent, b):
    wx.Dialog.__init__(self, parent, -1, "Enter Ballots")

    self.b = b
    self.raw = b.raw[:]

    sizer = wx.BoxSizer(wx.VERTICAL)

    hsizer = wx.BoxSizer(wx.HORIZONTAL)

    # grid for entering ballots
    self.g = BallotGrid(self, self.b) # defined below
    hsizer.Add(self.g, 0, wx.EXPAND, 0)

    # info, add button, and clear button
    vsizer = wx.BoxSizer(wx.VERTICAL)
    self.st = wx.StaticText(self, -1,
                            "Ballots already entered: %d" % len(self.raw))
    vsizer.Add(self.st, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    btn = wx.Button(self, -1, " Add ")
    wx.EVT_BUTTON(self, btn.GetId(), self.OnAddButton)
    vsizer.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    btn = wx.Button(self, -1, " Clear ")
    wx.EVT_BUTTON(self, btn.GetId(), self.OnClearButton)
    vsizer.Add(btn, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    st = wx.StaticText(self, -1, "Press 'Tab' after entering a ranking\nto advance to the next candidate.")
    vsizer.Add(st, 0, wx.EXPAND|wx.ALL, 5)
    hsizer.Add(vsizer, 0, wx.EXPAND, 0)

    sizer.Add(hsizer, 0, wx.EXPAND|wx.ALL, 5)

    # separator line
    line = wx.StaticLine(self, -1)
    sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER|wx.ALL, 5)

    # OK and Cancel buttons
    hsizer = wx.BoxSizer(wx.HORIZONTAL)
    btn = wx.Button(self, wx.ID_OK, " OK ")
    wx.EVT_BUTTON(self, btn.GetId(), self.OnOK)
    hsizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    btn = wx.Button(self, wx.ID_CANCEL, " Cancel ")
    hsizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    sizer.AddSizer(hsizer, 0, wx.ALIGN_CENTER|wx.ALL, 0)

    self.SetSizer(sizer)
    self.SetAutoLayout(True)
    sizer.Fit(self)

[...]

##################################################################

class BallotGrid(wx.grid.Grid):

  def __init__(self, parent, b):
    wx.grid.Grid.__init__(self, parent, -1)

    self.CreateGrid(len(b.c), 1)
    self.SetColLabelValue(0, "Rank")
    for i in range(len(b.c)):
      self.SetRowLabelValue(i, b.name[ b.c[i] ])
      editor = wx.grid.GridCellNumberEditor()
      self.SetCellEditor(i, 0, editor)
    self.SetColFormatNumber(0)
    self.AutoSize()
    self.EnableDragGridSize(False)
    self.EnableDragRowSize(False)
    self.EnableDragColSize(False)

    self.SetGridCursor(0, 0)
    self.EnableCellEditControl()

    wx.grid.EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellClick)
    wx.grid.EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelClick)
    wx.EVT_KEY_DOWN(self, self.OnKeyDown)

###

  def OnCellClick(self, event):
    r = event.GetRow()
    c = event.GetCol()
    self.SetGridCursor(r, c)
    self.EnableCellEditControl()

###

  def OnLabelClick(self, event):
    pass # do nothing

###

  def OnKeyDown(self, event):
    # I'd like to process up and down arrows but I don't know
    # how to wrest these events away from the text control.
    if event.KeyCode() not in [wx.WXK_RETURN, wx.WXK_TAB]:
      event.Skip()
      return

    self.DisableCellEditControl()
    r = self.GetGridCursorRow() + 1
    r = r % self.GetNumberRows()
    self.SetGridCursor(r, 0)
    self.EnableCellEditControl()

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org