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!
To me, wx.DC.GetTextExtent works fine if the text is on a single line, but if I add one or more linefeed escape sequences (‘\n’) it keeps evaluating the text as a single line.
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.
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
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!
To me, wx.DC.GetTextExtent works fine if the text is on a single line, but if I add one or more linefeed escape sequences ('\n') it keeps evaluating the text as a single line.
Correct. GetTextExtent does not do multi-line measurements, you need to split and or wrap the text yourself and then measure each line and sum the results.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!