wx.grid column sizing

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!

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.

···

2008/2/24, Robin Dunn robin@alldunn.com:

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

  1. 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 unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Robin Dunn wrote:

AutoSizeColumns simply loops through all the values, and calls GetTextExtent on each of them and sets the width to the the max.

Thanks. I decided to evaluate the first few rows of data with GetTextExtent and am pleased with the results.

Randall

Raffaello Barella wrote:

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!

Thanks, Robin and Andrea

···

2008/2/25, Andrea Gavana andrea.gavana@gmail.com:

Hi Robin & All,

On Mon, Feb 25, 2008 at 7:39 PM, Robin Dunn wrote:

Raffaello Barella wrote:

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.

I remember also using wx.DC.GetMultiLineTextExtent, which works with
the following call:

width, height, lineHeight = wx.DC.GetMultiLineTextExtent(string, font=None)

I have used it with CustomTreeCtrl (and many other widgets) and it

works pretty well.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org