GetSize() method doesn't return the correct size of parent panel

Hi,

I have placed a wx.grid on a panel,
I try to get panel’s width, and then use this width to set grid’s column size:

def init(self, parent, *args, **kwargs):
wx.Panel.init(self, parent, *args, **kwargs)
self.my_grid = SidePanelGrid(self)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.mainSizer.Add(self.capacity_grid, 0, wx.ALIGN_LEFT)
self.SetSizer(self.mainSizer)
widthx,heightx = self.GetSize()
print "widthx: ", widthx
self.my_grid.SetColSize(0, widthx)

When I inspect the widget inspection tool, I see that the panel has size (220, 720)
but above “widthx” print “20” (should be 220)

what causes the difference?

···

By the time you use the WIT all layout is done, where in init of
your panel that is not the case.
Maybe create a method ‘upgradeGridSize’ or something along those
lines and call it using wx.CallAfter.
Werner

···

Hi Steve,

  On 7/18/2014 12:59, steve wrote:

Hi,

    I have placed a wx.grid on a panel,

    I try to get panel's width, and then use this width to set

grid’s column size:

              def

init(self, parent, *args, **kwargs):

          wx.Panel.__init__(self, parent, *args, **kwargs)

          self.my_grid = SidePanelGrid(self)

          self.mainSizer = wx.BoxSizer(wx.VERTICAL)

          self.mainSizer.Add(self.capacity_grid, 0, wx.ALIGN_LEFT)

          self.SetSizer(self.mainSizer)

          widthx,heightx = self.GetSize()

          print "widthx: ", widthx

          self.my_grid.SetColSize(0, widthx)



    When I inspect the widget inspection tool, I see that the panel

has size (220, 720)

    but above "widthx" print "20" (should be 220)



    what causes the difference?

When should I upgrade the size of grid column exactly?

···

On Friday, July 18, 2014 2:05:52 PM UTC+3, werner wrote:

Hi Steve,

  On 7/18/2014 12:59, steve wrote:

Hi,

    I have placed a wx.grid on a panel,

    I try to get panel's width, and then use this width to set

grid’s column size:

              def

init(self, parent, *args, **kwargs):

          wx.Panel.__init__(self, parent, *args, **kwargs)

          self.my_grid = SidePanelGrid(self)

          self.mainSizer = wx.BoxSizer(wx.VERTICAL)

          self.mainSizer.Add(self.capacity_grid, 0, wx.ALIGN_LEFT)

          self.SetSizer(self.mainSizer)

          widthx,heightx = self.GetSize()

          print "widthx: ", widthx

          self.my_grid.SetColSize(0, widthx)



    When I inspect the widget inspection tool, I see that the panel

has size (220, 720)

    but above "widthx" print "20" (should be 220)



    what causes the difference?
By the time you use the WIT all layout is done, where in __init__ of

your panel that is not the case.

Maybe create a method 'upgradeGridSize' or something along those

lines and call it using wx.CallAfter.

Werner

so wx.CallAfter(self.upgradeGridSize) instead of your last three
lines in init and move those to the method 'updateGridSize.
Werner

···

On 7/18/2014 13:14, steve wrote:

    When should I upgrade the size of grid column

exactly?

http://wxpython.org/Phoenix/docs/html/functions.html?highlight=callafter#CallAfter

    On Friday, July 18, 2014 2:05:52 PM UTC+3, werner wrote:

Hi Steve,

          On 7/18/2014 12:59, steve wrote:

Hi,

            I have placed a wx.grid on a panel,

            I try to get panel's width, and then use this width to

set grid’s column size:

                              def

init(self, parent, *args, **kwargs):

                  wx.Panel.__init__(self, parent, *args, **kwargs)

                  self.my_grid = SidePanelGrid(self)

                  self.mainSizer = wx.BoxSizer(wx.VERTICAL)

                  self.mainSizer.Add(self.                  capacity_grid, 0,

wx.ALIGN_LEFT)

                  self.SetSizer(self.mainSizer)

                  widthx,heightx = self.GetSize()

                  print "widthx: ", widthx

                  self.my_grid.SetColSize(0, widthx)



            When I inspect the widget inspection tool, I see that

the panel has size (220, 720)

            but above "widthx" print "20" (should be 220)



            what causes the difference?
        By the time you use the WIT all layout is done, where in

init of your panel that is not the case.

        Maybe create a method 'upgradeGridSize' or something along

those lines and call it using wx.CallAfter.

        Werner

  You received this message because you are subscribed to the Google

Groups “wxPython-users” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to wxpython-users+unsubscribe@googlegroups.com.

  For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

I think you can call either self.Layout just after setting the sizer, or self.mainSizer.Layout() just before the SetSizer.

···

On Friday, July 18, 2014 3:59:25 AM UTC-7, steve wrote:

Hi,

I have placed a wx.grid on a panel,
I try to get panel’s width, and then use this width to set grid’s column size:

def init(self, parent, *args, **kwargs):
wx.Panel.init(self, parent, *args, **kwargs)
self.my_grid = SidePanelGrid(self)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.mainSizer.Add(self.capacity_grid, 0, wx.ALIGN_LEFT)
self.SetSizer(self.mainSizer)
widthx,heightx = self.GetSize()
print "widthx: ", widthx
self.my_grid.SetColSize(0, widthx)

When I inspect the widget inspection tool, I see that the panel has size (220, 720)
but above “widthx” print “20” (should be 220)

what causes the difference?