resizing a wx.grid

509 views
Skip to first unread message

Michael P. Soulier

unread,
Feb 17, 2006, 11:21:42 PM2/17/06
to wxPytho...@lists.wxwidgets.org
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 <msou...@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

E. A. Tacao

unread,
Feb 18, 2006, 4:10:49 PM2/18/06
to Michael P. Soulier
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.

Robin Dunn

unread,
Feb 18, 2006, 4:10:04 PM2/18/06
to wxPytho...@lists.wxwidgets.org
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!


Michael P. Soulier

unread,
Feb 19, 2006, 10:18:18 AM2/19/06
to wxPytho...@lists.wxwidgets.org, E. A. Tacao
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())

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?

Robin Dunn

unread,
Feb 19, 2006, 5:26:37 PM2/19/06
to wxPytho...@lists.wxwidgets.org
Michael P. Soulier wrote:
> On 18/02/06 E. A. Tacao said:
>

> 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.

Reply all
Reply to author
Forward
0 new messages