how to force wxGrid in sizer to show all columns?

Hello:
Thanks for the previous help, particularly to Robin.
And while Im at it, Robin thanks for the book--it
would be more difficult for a beginner like me without
it. I have three vertical BoxSizers placed in a
horizontal BoxSizer. In one vertical BoxSizer is a
wxGrid and I would like the grid to show all its
columns (i.e., no scroll). If any extra room is left,
I would like the spacing between vertical sizers to
adjust accordingly. The following code works except
that not all columns of the wxGrid are shown. Can
anyone tell me where I am going wrong? I dont want to
set the size of the wxGrid by hand (I'd like it to
size automatically).

Also, note that if you maximize the frame, there will
be an ugly white block to the right of the wxGrid. Im
just curious if there is a way to get rid of that.

Thanks much, John

#!/usr/bin/env python
import wx
import wx.grid

class myApp(wx.App):
  def OnInit(self):
    frame = Frame1("hello",(50,160),(450,340))
    frame.Show()
    self.SetTopWindow(frame)
    return True

class Frame1(wx.Frame):
  def __init__(self,title,pos,size):
    wx.Frame.__init__(self,None,-1,title,pos,size)
    
    panelA = wx.Panel(self, -1, name='panelA',
pos=wx.Point(0, 0), style=wx.TAB_TRAVERSAL )
    mainBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
    boxsizer_1 = wx.BoxSizer(wx.VERTICAL)
    boxsizer_2 = wx.BoxSizer(wx.VERTICAL)
    boxsizer_3 = wx.BoxSizer(wx.VERTICAL)
    
    txtctrl_1= wx.TextCtrl(panelA, -1, size=(100,-1))
    txtctrl_2= wx.TextCtrl(panelA, -1, size=(100,-1))
    grid_1 = wx.grid.Grid(panelA, -1, size=(-1,-1))
    
    boxsizer_1.Add(txtctrl_1, 0, wx.TOP | wx.EXPAND,
border=0)
    boxsizer_2.Add(txtctrl_2, 0, wx.TOP | wx.EXPAND,
border=0)
    boxsizer_3.Add(grid_1, 0, wx.TOP | wx.EXPAND,
border=0)
    
    # put columns together
    mainBoxSizer.Add(boxsizer_1, 0, flag=wx.EXPAND |
wx.ALL, border=6)
    mainBoxSizer.Add(boxsizer_2, 0, flag=wx.EXPAND |
wx.ALL, border=6)
    mainBoxSizer.Add(boxsizer_3, 1, flag=wx.EXPAND |
wx.ALL, border=6)
    
    grid_1.CreateGrid(8,12)
    grid_1.SetDefaultColSize(55)
    grid_1.SetRowLabelSize(40)
    
    panelA.SetSizerAndFit(mainBoxSizer)
    
if __name__ == '__main__':
  #app = MixLowApp(True)
  app = myApp(False)
  app.MainLoop()

···

____________________________________________________________________________________
Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz

Sorry, slight typo here. The flags for the first two
.Add's should be 1 and 1, not 0 and 0. But leaving
them at 0 and 0 does show the ugly white block I was
referring to when the frame is maximized.
John

···

--- JJ <josh8912@yahoo.com> wrote:
     

    # put columns together
    mainBoxSizer.Add(boxsizer_1, 0, flag=wx.EXPAND
>
wx.ALL, border=6)
    mainBoxSizer.Add(boxsizer_2, 0, flag=wx.EXPAND
>
wx.ALL, border=6)
    mainBoxSizer.Add(boxsizer_3, 1, flag=wx.EXPAND
>

      ____________________________________________________________________________________
Shape Yahoo! in your own image. Join our Network Research Panel today! http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7

JJ wrote:

Hello:
Thanks for the previous help, particularly to Robin. And while Im at it, Robin thanks for the book--it
would be more difficult for a beginner like me without
it. I have three vertical BoxSizers placed in a
horizontal BoxSizer. In one vertical BoxSizer is a
wxGrid and I would like the grid to show all its
columns (i.e., no scroll).

You'll probably need to write some code that adjusts the grid column widths to fill the space given the grid. Check the wiki and also the list archives as this has been discussed before so there are probably some examples somewhere.

If any extra room is left,
I would like the spacing between vertical sizers to
adjust accordingly. The following code works except
that not all columns of the wxGrid are shown. Can
anyone tell me where I am going wrong? I dont want to
set the size of the wxGrid by hand (I'd like it to
size automatically).

Part of the problem is how you are using the sizers. You are Fit()ing the panel to be large enough to show all the widgets, but you are not doing anything to the frame to make it large enough. So the grid is drawn off the edge of the frame and you can't see some of it unless you make the frame larger. One way to handle this is to do this instead of your SetSizerAndFit:

     panelA.SetSizer(mainBoxSizer)
     mainBoxSizer.SetSizeHints(self)

That will not only make the frame start out to be large enough to show all the widgets as dictated by the sizer, but will also limit it from being resized too small.

Also, note that if you maximize the frame, there will
be an ugly white block to the right of the wxGrid. Im
just curious if there is a way to get rid of that.

It is not to the right of the grid, it is the grid. That is simply how the grid displays itself when its size is larger than the width of its columns. Since you are putting it into the sizer with a proportion of 1 then the sizer will give it an equal share of all the extra space, so it will size the grid larger and larger as you resize the containing window.

···

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