resizing a wx.grid

Hey people,

I have a wx.grid inside of a wx.Frame, but the grid isn't filling in all of
the space inside of the frame, nor does it resize when the frame resizes.

How might I accomplish that?

        topVertBoxSizer = self.GetSizer()
        self.processGrid = wx.grid.Grid(self, -1, size=(1, 1))
        self.processGrid.CreateGrid(0, self.nColumns)
        self.processGrid.SetColLabelValue(0, "PID")
        self.processGrid.SetColLabelValue(1, "SILOS")
        self.processGrid.SetColLabelValue(2, "TASKS")
        self.processGrid.SetColLabelValue(3, "%CPU")
        self.processGrid.SetColLabelValue(4, "%MEM")
        self.processGrid.SetColLabelValue(5, "COMMAND")
        topVertBoxSizer.Add(self.processGrid, 1, wx.EXPAND, 0)

Thanks,
Mike

···

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein

Michael P. Soulier wrote:

Hey people,

I have a wx.grid inside of a wx.Frame, but the grid isn't filling in all of
the space inside of the frame, nor does it resize when the frame resizes.

How might I accomplish that?

        topVertBoxSizer = self.GetSizer()
        self.processGrid = wx.grid.Grid(self, -1, size=(1, 1))
        self.processGrid.CreateGrid(0, self.nColumns)
        self.processGrid.SetColLabelValue(0, "PID")
        self.processGrid.SetColLabelValue(1, "SILOS")
        self.processGrid.SetColLabelValue(2, "TASKS")
        self.processGrid.SetColLabelValue(3, "%CPU")
        self.processGrid.SetColLabelValue(4, "%MEM")
        self.processGrid.SetColLabelValue(5, "COMMAND")
        topVertBoxSizer.Add(self.processGrid, 1, wx.EXPAND, 0)

That should work, and with quick test in PyShell it does work for me. The grid is sized to fill the frame. (You can tell by the white area of the grid getting stretched as the frame does.) You're not expecting the sizer to resize the columns or to add rows are you?

···

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

Saturday, February 18, 2006, 1:21:42 AM, Michael P. Soulier wrote:

Hey people,

I have a wx.grid inside of a wx.Frame, but the grid isn't filling in
all of the space inside of the frame, nor does it resize when the
frame resizes.

How might I accomplish that?

        topVertBoxSizer = self.GetSizer()
        self.processGrid = wx.grid.Grid(self, -1, size=(1, 1))
        self.processGrid.CreateGrid(0, self.nColumns)
        self.processGrid.SetColLabelValue(0, "PID")
        self.processGrid.SetColLabelValue(1, "SILOS")
        self.processGrid.SetColLabelValue(2, "TASKS")
        self.processGrid.SetColLabelValue(3, "%CPU")
        self.processGrid.SetColLabelValue(4, "%MEM")
        self.processGrid.SetColLabelValue(5, "COMMAND")
        topVertBoxSizer.Add(self.processGrid, 1, wx.EXPAND, 0)

If self is the frame and self.processGrid is the only thing inside the
frame, do this somewhere after the grid creation:

        self.processGrid.Bind(wx.EVT_SIZE, self.OnSize)

And add this method on the frame:

    def OnSize(self, evt):
        self.processGrid.SetSize(self.GetClientSize())

-- tacao

No bits were harmed during the making of this e-mail.

The parent does contain widgets above the grid.

Your code left me with an incomplete grid for some reason, but this seems to
help.

    self.processGrid.Bind(wx.EVT_SIZE, self.onGridSize)

def onGridSize(self, event):
    width, height = self.GetClientSizeTuple()
    for col in range(NCOLUMNS):
        self.processGrid.SetColSize(col, width/(NCOLUMNS+1))

This works!

Is there a way to get rid of the first column where it holds the row number?
I'd rather not have it.

Also, is this the best solution? Isn't there a simple way to tell the child to
always resize to the client area of the parent?

Thanks,
Mike

···

On 18/02/06 E. A. Tacao said:

If self is the frame and self.processGrid is the only thing inside the
frame, do this somewhere after the grid creation:

        self.processGrid.Bind(wx.EVT_SIZE, self.OnSize)

And add this method on the frame:

    def OnSize(self, evt):
        self.processGrid.SetSize(self.GetClientSize())

--
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein

Michael P. Soulier wrote:

Is there a way to get rid of the first column where it holds the row number?
I'd rather not have it.

grid.SetRowLabelSize(0)

Also, is this the best solution? Isn't there a simple way to tell the child to
always resize to the client area of the parent?

Proper use of sizers will let you do this.

···

On 18/02/06 E. A. Tacao said:

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