[wxPython-users] Grid Width

Raffaello Barella barbarossa.platz at gmail.com
Tue Jan 1 21:55:24 PST 2008


Obviously, both the vertical and the horizontal scrollbars occupy some
pixels, and as you wrote their sizes depend on OS and display themes. You
have to choose: either you accept that one of the columns is of variable
width, or the whole grid, hence the frame are of variable size. You need a
method that, gauging the difference between grid.GetSize() and
grid.GetClientSize(), checks the number of pixels necessary to show exactly
all the columns. This is the code I wrote for my grids:
quote
def SetOptimalSize(grid):
    # Resets the grid width to show exactly all columns
        GridWidth =3D 0
        for c in range(grid.GetNumberCols() ):
                GridWidth +=3D grid.GetColSize(c)
        sz =3D grid.GetSize()
        csz =3D grid.GetClientSize()
        delta =3D sz.width - csz.width  + 10  # (I don't know why, but it
seems necessary)
        GridWidth +=3D (delta + grid.GetRowLabelSize())
        GridHeight =3D grid.GetColLabelSize()  + \
            grid.GetDefaultRowSize() * grid.VisibleRows + 7 # (idem)

        szp =3D  grid.GetParent().GetClientSize()
        if szp.width < GridWidth:
            szp.SetWidth(GridWidth)
            grid.GetParent().SetClientSize(szp)

        grid.SetSize((GridWidth, GridHeight))
        szParent =3D grid.GetParent().GetClientSize()
        if szParent.width < (GridWidth + 10):
            szParent.width =3D (GridWidth + 10)
            grid.GetParent().SetClientSize(szParent)
 unquote

and I called this method in:
grid.__init__
grid.EndBatch
grid.OnEVT_GRID_ROW_SIZE
grid.SetColAttr
grid.SetRowAttr
grid.SetColSize
grid.SetRowSize
grid.SetNumberCols
grid.SetNumberRows
and all variants of grid.Autosize

Sorry, I didn't say it was simple, but it works.
Cheers


2008/1/2, Mark Erbaugh <mark at microenh.com>:
>
> Is there a way to determine the width needed to display a grid without a
> horizontal scrollbar even when a vertical scrollbar is displayed.
>
> I added a grid to a vertical box sizer on a frame. The grid is the
> widest thing on the frame.  As long as there is no vertical scrollbar,
> the entire grid is displayed.  However, if I reduce the height of the
> frame so that a vertical scrollbar is needed for the grid, the width of
> the vertical scrollbar reduces the width of the grid and a horizontal
> scrollbar is displayed.
>
> Is there a way to determine the width of a vertical scrollbar or the
> height of a horizontal scrollbar. I believe they are different sizes
> depending on the operating system and perhaps display themes.
>
> When the above grid is displayed (under GTK, at least), there are a few
> pixels of background color to the left and bottom of the grid. If I
> resize the frame to eliminate those, the scrollbars return.  Is there a
> way to have the bottom and right edges of the grid exactly at the edge
> of the grid, except for space for an undisplayed vertical scrollbar.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200801=
02/73ee12cc/attachment.htm


More information about the wxpython-users mailing list