[wxPython-users] wx.grid column sizing
Robin Dunn
robin at alldunn.com
Sat Feb 23 15:54:43 PST 2008
Randall Smith wrote:
> I'm developing an app that shows database results in a grid and trying
> to keep performance a priority. I'm happy with the grid performance
> using a subclass of PyGridTableBase (it's astonishing), but I lose those
> gains when I need to choose a good size for my columns.
>
> grid.AutoSizeColumns is terribly slow even on a small data set. So I'm
> considering these two approaches at the moment.
>
> 1. Get the width of the rendered column labels and set the width of the
> columns to the label width or a minimum default. I can't figure out how
> to get the width of the label text. Is there a straight forward way to
> do this so that I get the correct width regardless of font size, style,
> etc. Something like FontRenderSize(text, font_style, font_size)?
wx.DC.GetTextExtent
>
> 2. Fake it. Build a temporary grid with a subset of the results, call
> AutoSizeColumns (assuming it completes quickly on a very small data set)
> and use those sizes. I guess it would be quicker to use the functions
> used by AutoSizeColumns directly instead of creating a grid. Or would
> it be quicker to write an algorithm in Python? Maybe a C extension? Hmm.
AutoSizeColumns simply loops through all the values, and calls
GetTextExtent on each of them and sets the width to the the max.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list