confused about wx.EXPAND , nested sizers

Having not coded in wxpython for a few months . I have forgotten everything I had understood about sizers. I am looking to get started again and am struggling to get wx.EXPAND to behave right in this trivial example.I am pasting the code below .

I want the TextCtrl boxes to stretch as the screen in stretched . But somehow that does not happen.

Also tabbing from one TextCtrl box does not position the cursor in the next TextCtrl box on a MAC OSX .

I am using ex python version ‘2.8.10.1’

Any pointers on what I am doing wrong .

Thanks for your help

Hari

Test code:

#!/usr/bin/env python

import wx

import wx.lib.inspection

class MyFrame(wx.Frame):

def __init__(self,*args,**kwargs):

	wx.Frame.__init__(self,*args,**kwargs)

	panel = wx.Panel(self)

	textlabel = wx.StaticText(panel, -1, label="Name")

	# Text ctrl boxes that need to stretch horizontally

	textentry_box = wx.TextCtrl(panel,-1)

	textentry_box_line2 = wx.TextCtrl(panel,-1)

	# # Top Vertical Sizer

	topvertsz = wx.BoxSizer(wx.VERTICAL)

	# # Flexgridsizer for Name and two lines of addresses

	address_sizer = wx.FlexGridSizer(2,2,10,10)

	# address_sizer.AddGrowableCol(0)

	# address_sizer.AddGrowableRow(0)

	# address_sizer.AddGrowableRow(1)

	# # Adding Address entry elements

	address_sizer.Add(textlabel,0,wx.EXPAND)

	address_sizer.Add(textentry_box,0,wx.EXPAND)

	address_sizer.Add((10,10))

	address_sizer.Add(textentry_box_line2,0,wx.EXPAND)

	topvertsz.Add(address_sizer,0,wx.EXPAND)

	panel.SetSizer(topvertsz)

	# topvertsz.Fit(self)

	# topvertsz.SetSizeHints(self)

class MyApp(wx.App):

def OnInit(self):

	f = MyFrame(None,-1,title="Atext")

	f.Show(True)

	self.SetTopWindow(f)

	return True

if name==“main”:

a = MyApp()

wx.lib.inspection.InspectionTool().Show()

a.MainLoop()

Hi everyone,

I figured it out after looking at an email Werner had sent this group a while back.

The wx.EXPAND for a FlexGridSizer controls the growth along the non primary direction - i.e the Horizontal direction provided the Column or Row is declared as growable.

So in my example with the following mod I can get it to behave the way I want it to.

Thanks

Hari

#!/usr/bin/env python

import wx

import wx.lib.inspection

class MyFrame(wx.Frame):

def __init__(self,*args,**kwargs):

	wx.Frame.__init__(self,*args,**kwargs)

	panel = wx.Panel(self)

	textlabel = wx.StaticText(panel, -1, label="Name")

	textentry_box = wx.TextCtrl(panel,-1)

	textentry_box_line2 = wx.TextCtrl(panel,-1)

	# # Top Vertical Sizer

	topvertsz = wx.BoxSizer(wx.VERTICAL)

	# # Flexgridsizer for Name and two lines of addresses

	address_sizer = wx.FlexGridSizer(2,2,10,10)

	address_sizer.AddGrowableCol(1)

	# Adding Address entry elements

	address_sizer.Add(textlabel,0,wx.EXPAND)

	address_sizer.Add(textentry_box,0,wx.EXPAND|wx.RIGHT,10)

	address_sizer.Add((10,10))

	address_sizer.Add(textentry_box_line2,0,wx.EXPAND|wx.RIGHT,10)

	topvertsz.Add(address_sizer,0,wx.EXPAND)

	panel.SetSizer(topvertsz)

	# topvertsz.Fit(self)

	# topvertsz.SetSizeHints(self)

class MyApp(wx.App):

def OnInit(self):

	f = MyFrame(None,-1,title="Atext")

	f.Show(True)

	self.SetTopWindow(f)

	return True

if name==“main”:

a = MyApp()

wx.lib.inspection.InspectionTool().Show()

a.MainLoop()

“”"

···

On Sun, Feb 21, 2010 at 8:45 PM, hari jayaram harijay@gmail.com wrote:

Having not coded in wxpython for a few months . I have forgotten everything I had understood about sizers. I am looking to get started again and am struggling to get wx.EXPAND to behave right in this trivial example.I am pasting the code below .

I want the TextCtrl boxes to stretch as the screen in stretched . But somehow that does not happen.

Also tabbing from one TextCtrl box does not position the cursor in the next TextCtrl box on a MAC OSX .

I am using ex python version ‘2.8.10.1’

Any pointers on what I am doing wrong .

Thanks for your help

Hari

Test code:

#!/usr/bin/env python

import wx

import wx.lib.inspection

class MyFrame(wx.Frame):

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

  wx.Frame.__init__(self,*args,**kwargs)
  panel = wx.Panel(self)
  textlabel = wx.StaticText(panel, -1, label="Name")
  # Text ctrl boxes that need to stretch horizontally
  textentry_box = wx.TextCtrl(panel,-1)
  textentry_box_line2 = wx.TextCtrl(panel,-1)
  # # Top Vertical Sizer
  topvertsz = wx.BoxSizer(wx.VERTICAL)
  # # Flexgridsizer for Name and two lines of addresses
  address_sizer = wx.FlexGridSizer(2,2,10,10)
  # address_sizer.AddGrowableCol(0)
  # address_sizer.AddGrowableRow(0)
  # address_sizer.AddGrowableRow(1)
  # # Adding Address entry elements
  address_sizer.Add(textlabel,0,wx.EXPAND)
  address_sizer.Add(textentry_box,0,wx.EXPAND)
  address_sizer.Add((10,10))
  address_sizer.Add(textentry_box_line2,0,wx.EXPAND)
  topvertsz.Add(address_sizer,0,wx.EXPAND)
  panel.SetSizer(topvertsz)
  # topvertsz.Fit(self)
  # topvertsz.SetSizeHints(self)

class MyApp(wx.App):

def OnInit(self):

  f = MyFrame(None,-1,title="Atext")
  f.Show(True)
  self.SetTopWindow(f)
  return True

if name==“main”:

a = MyApp()

wx.lib.inspection.InspectionTool().Show()

a.MainLoop()

Actually for grid sizers wx.EXPAND means to "fill the cell." In other words, to expand in both dimensions to fill the space allocated to that item by the sizer, after taking any borders into account.

···

On 2/21/10 11:33 PM, hari jayaram wrote:

Hi everyone,
I figured it out after looking at an email Werner had sent this group a
while back.

The wx.EXPAND for a FlexGridSizer controls the growth along the non
primary direction - i.e the Horizontal direction provided the Column or
Row is declared as growable.

--
Robin Dunn
Software Craftsman