Help On GridBagSizer & Layout

andrea_gavana@tin.it wrote:

Thanks for the suggestion Robin. I'm working on it. I have however another
problem regarding the same module. It is still related to the grid.

When the number of rows/cols is small (say 10 and 8), the grid dimension
is acceptable. But, if I use:

self.griddesign.CreateGrid(30,28)

The grid becomes incredibly big and causes the GridBagSizer to expand *a
lot* the rows/cols (of the GrdiBagSizer). So the grid occupy most of my
Frame, and if I increase further the grid dimensions (rows/cols) my frame
becomes bigger than my screen.

I have tried to eliminate all the wx.EXPAND relative to the sizer that contains
the grid, and also I have eliminated the GridBagSizer.AddGrowableRow() andGridBagSizer.AddGrowableCol()
relative to the grid... but no avail.

Does anyone have a suggestion on how to limit the grid size?

Yep. Sizers use GetBestFittingSize when determining how much space is needed to display a child window, and in GetBestFittingSize the min size, if it is set, takes priority over the best size. So setting a min size value for the grid should do it for you, the sizer will use that minsize as the starting point and will only expand larger than that if you use the wx.EXPAND flag and growable row/col, etc. Here is the implementation of GetBestFittingSize for reference:

wxSize wxWindowBase::GetBestFittingSize() const
{
     // merge the best size with the min size, giving priority to the min size
     wxSize min = GetMinSize();
     if (min.x == wxDefaultCoord || min.y == wxDefaultCoord)
     {
         wxSize best = GetBestSize();
         if (min.x == wxDefaultCoord) min.x = best.x;
         if (min.y == wxDefaultCoord) min.y = best.y;
     }
     return min;
}

Moreover, when the frame shows up, the grid has scrollbars with really *big*
"scrollrate" available, but this is useless because the hidden columns and
rows are 2 or 3 and the grid should not need so much scrollrate to make
them visible. I attach a small picture to demonstrate the problem (in the
picture, I have a 10x8 grid, almost all the cells are visible but still
I have big scrollrates).

I'm not sure what is going on there. Do the scrollbars adjust to more normal values if the grid is resized? If so then perhaps posting a size event to the grid would take care of it.

At last, how do I get rid of the white margins below and on the right? I
have tried SetMargins(0,0) but they are still there...

The margin settings basically add that much space to the virtual size of the window. If the grid window is sized larger than the virtual size then there will be extra white space added to fill the empty area. Also, the virtual size is in effect increased until it is an exact multiple of the scrollrate, so that can give some extra "margin" area as well. Unfortunatly I don't think that there is a sure-fire way to elimiate it.

ยทยทยท

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