How to set size of wx.grid's columns expand to its parent?

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

We’ll need to see more code.

···

On Thursday, July 17, 2014 2:01:17 PM UTC-7, steve wrote:

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

Have you placed the grid in a sizer, and called yourPanel.SetSizer(yourSizer)?

···

On Thursday, July 17, 2014 2:01:17 PM UTC-7, steve wrote:

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

I did:

self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.mainSizer.Add(self.my_grid, 0, wx.EXPAND|wx.GROW)
self.SetSizer(self.mainSizer)

···

On Friday, July 18, 2014 12:15:59 AM UTC+3, Nathan McCorkle wrote:

Have you placed the grid in a sizer, and called yourPanel.SetSizer(yourSizer)?

On Thursday, July 17, 2014 2:01:17 PM UTC-7, steve wrote:

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

You don’t set the size of the grid, so it’s just using the minimum amount of size necessary. If you want a more accurate size, you would be better off changing that line to

self.GetTopLevelParent().GetSize()

This will get you a lot closer to what you want. When I tried it, the grid was actually wider than the screen and had scrollbars. I personally prefer that to the white background. If you want, you could set the size of the frame and use that size for your grid as well.

  • Mike
···

On Thursday, July 17, 2014 4:01:17 PM UTC-5, steve wrote:

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

wx.EXPAND is the same thing as wx.GROW.

  • Mike
···

On Thursday, July 17, 2014 4:19:59 PM UTC-5, steve wrote:

I did:

self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.mainSizer.Add(self.my_grid, 0, wx.EXPAND|wx.GROW)
self.SetSizer(self.mainSizer)

But I set the size of each column to 1/4 of grid size (there are 4 columns), so why is there whitespace on the right side of the cells?

self.SetColSize(col, (widt/4))

···

On Friday, July 18, 2014 12:23:59 AM UTC+3, Mike Driscoll wrote:

On Thursday, July 17, 2014 4:01:17 PM UTC-5, steve wrote:

Hi,

I try to place a wx.grid on a panel, and make its columns expand to parent, but I get a white space on the right side of cells:

I do:

import wx.grid as gridlib

class SidePanelGrid(gridlib.Grid):
def init(self, parent):
gridlib.Grid.init(self, parent, -1, name=“Side Panel Capacity Grid”)
self.CreateGrid(3,4)
self.HideRowLabels()
self.HideColLabels()
self.ShowScrollbars(wx.SHOW_SB_NEVER,wx.SHOW_SB_NEVER)
widt, heig = self.GetSize()
print "widt: ", widt
for row in xrange(3):
self.DisableRowResize(row)
for col in xrange(4):
self.SetCellAlignment(row, col, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)

    for col in xrange(4):
        self.SetColSize(col, (widt/4))
        self.DisableColResize(col)

self.my_grid = SidePanelGrid(self)

It doesn’t work. What do I do wrong above?

You don’t set the size of the grid, so it’s just using the minimum amount of size necessary. If you want a more accurate size, you would be better off changing that line to

self.GetTopLevelParent().GetSize()

This will get you a lot closer to what you want. When I tried it, the grid was actually wider than the screen and had scrollbars. I personally prefer that to the white background. If you want, you could set the size of the frame and use that size for your grid as well.

  • Mike

Because the grid is expanding, but the columns are not. The columns don’t expand when you change the size of your frame. If you want that to happen, you would have to catch EVT_SIZE and modify the grid’s column sizes yourself.

Mike

···

On Thursday, July 17, 2014 4:28:31 PM UTC-5, steve wrote:

But I set the size of each column to 1/4 of grid size (there are 4 columns), so why is there whitespace on the right side of the cells?

self.SetColSize(col, (widt/4))

But the whitespace is there when I first start the application as well. I don’t resize the window manually.

···

On Friday, July 18, 2014 12:41:11 AM UTC+3, Mike Driscoll wrote:

On Thursday, July 17, 2014 4:28:31 PM UTC-5, steve wrote:

But I set the size of each column to 1/4 of grid size (there are 4 columns), so why is there whitespace on the right side of the cells?

self.SetColSize(col, (widt/4))

Because the grid is expanding, but the columns are not. The columns don’t expand when you change the size of your frame. If you want that to happen, you would have to catch EVT_SIZE and modify the grid’s column sizes yourself.

Mike

You told the grid to expand in the sizer. It is expanding to fit the width of the frame. That’s why you see the whitespace.

Mike

···

On Thursday, July 17, 2014 4:45:15 PM UTC-5, steve wrote:

But the whitespace is there when I first start the application as well. I don’t resize the window manually.

wx.GROW is alias of wx.EXPAND, don’t know what happens if you use
both at the same time, don’t they negate each other?
wx.GROW
8192
wx.EXPAND
8192
Werner

···

Hi Steve,

  On 7/17/2014 23:19, steve wrote:

I did:

          self.mainSizer =

wx.BoxSizer(wx.VERTICAL)

    self.mainSizer.Add(self.my_grid, 0, wx.EXPAND|wx.GROW)

Honestly, aren’t they teaching you kids Boolean algebra in high
school any more? “|” is the logical “or” operator. 1|1 == 1. In
fact, for any x, x|x == x.

···

Werner wrote:

  wx.GROW is alias of wx.EXPAND, don't know what happens if you use

both at the same time, don’t they negate each other?
wx.GROW
8192
wx.EXPAND
8192

-- Tim Roberts, Providenza & Boekelheide, Inc.

Hi Steve,

    On 7/17/2014 23:19, steve wrote:

I did:

              self.mainSizer

= wx.BoxSizer(wx.VERTICAL)

      self.mainSizer.Add(self.my_grid, 0, wx.EXPAND|wx.GROW)

timr@probo.com

Kids, not sure I qualify for that and no never had algebra but then I didn’t
do high school or the equivalent when I want to school back a little
while ago,
but I know I should one day maybe learn this stuff.
Werner

···

On 7/18/2014 17:59, Tim Roberts wrote:

  Honestly, aren't they teaching you kids Boolean algebra in high

school any more? “|” is the logical “or” operator. 1|1 == 1. In
fact, for any x, x|x ==

    :-)   ;-) ., ,

Werner wrote:

    wx.GROW is alias of wx.EXPAND, don't know what happens if you

use both at the same time, don’t they negate each other?
wx.GROW
8192
wx.EXPAND
8192
Hi Steve,

      On 7/17/2014 23:19, steve wrote:

I did:

        self.mainSizer

= wx.BoxSizer(wx.VERTICAL)

        self.mainSizer.Add(self.my_grid, 0, wx.EXPAND|wx.GROW)

Well actually , Tim, "|" is the bitwise or operator; "or" is of course the
logical or operator.

···

On Fri, Jul 18, 2014 at 11:59 AM, Tim Roberts <timr@probo.com> wrote:

Honestly, aren't they teaching you kids Boolean algebra in high school
any more? "|" is the logical "or" operator. 1|1 == 1. In fact, for any
x, x|x == x.

--
Best Regards,
Michael Moriarity