Font size in grids

Hello list,
I am new to, and experimenting with grids.
It is difficult to set everywhere the right width and/or height.
At this moment I am really experimenting, but I would prefer to
do some calculations based on the height and average width of
the default fonts used for the row labels and within cells.
Is it possible to get these widths and heights programmatically ?
e

···

--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991

Hi Egbert,

It is difficult to set everywhere the right width and/or height.
At this moment I am really experimenting, but I would prefer to
do some calculations based on the height and average width of
the default fonts used for the row labels and within cells.
Is it possible to get these widths and heights programmatically ?

One possibility is to use GetTextExtent to retrieve the width/height
of your text. For example, let's assume you want to know the maximum
width of the cells in the first column (here "self" is the grid):

maxWidth = 0

# Create a client DC to calculate the text extent
dc = wx.ClientDC(self)

for row in xrange(self.GetNumberRows()):
    # Get the cell value for every row in the first column
    text = self.GetCellValue(row, 0)
    # Get the font for every row in the first column
    font = self.GetCellFont(row, 0)

    # Set the dc to have the font of the current cell
    dc.SetFont(font)
    # Get the text extent
    width, height = dc.GetTextExtent(text)

    maxWidth = max(maxWidth, width)

self.SetColSize(0, maxWidth)

Please triple check the code I have written, I didn't test it. This
small sample does not take into account the column labels, but it's
trivial to extend it.

Hope this helps.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 3/12/07, egbert wrote: