[wxPython-users] The grid control -- problems and questions
Bob Klahn
bobstones at comcast.net
Tue Sep 4 05:49:51 PDT 2007
Trying again; I fat-fingered my preceding post and sent it prematurely.
At 10:10 PM 9/3/2007, Robin wrote:
>Bob Klahn wrote:
>>The attached grid code features a custom renderer. In that
>>renderer, apart from drawing the given cell, I print the row, col,
>>and isSelected values to stdout, along with the number of the
>>current call to the draw routine (1, 2, 3, ...).
>>Some questions:
>> (1) How do I best avoid the excessive drawing that occurs
>> (a) when switching to another application and switching back?
>> (b) when resizing the test frame?
>
>Which platform are you on?
Windows XP SP2
>If on the Mac then I think there is code in wxGrid that always
>redraws all of the visible cells instead of optimizing it down as is
>done on the other platforms.
It's not optimized here. wxGrid is redrawing =all= the visible
cells, both when I resize the test frame, and when I switch to
another application and switch back. And if there's a lot of text on
the screen, I get a good bit of flicker during resizing, and during
horizontal scrolling. But no flicker during vertical scrolling,
which surprises me.
>Otherwise only those cells that intersect with whatever region the
>OS reports needs to be redrawn are painted.
Then, since many more cells are being redrawn, on my PC at least,
than the old one and those immediately surrounding it, I guess you're
telling me that Windows XP is the culprit, that it's telling wxPython
to redraw several unchanged cells.
>The Grid class doesn't make use of any double buffering at all, and
>would probably need to be rearchitected to be able to do so, but in
>practice the method it does use is normally efficient enough.
As I said above, I get a good bit of flicker during resizing and
horizontal scrolling. Hmmm, I wonder if I can use Freeze/Thaw and
only draw during idle time. That might work for resizing, but
>> (2) Note the rows that are redrawn as one clicks on different rows.
>> (a) When one clicks on the row immediately below the
>> current row,
>> (i) notice the color of the rightmost column
>> -- Why is that happening?
>> -- Why is it different when moving
>> from row 0 to row 1, versus
>> moving from row n to row n+1 where n <> 0 ?
>
>I don't notice any color problem so I'm not quite sure what you are
>talking about, but I do notice that you never specify in your
>renderer's Draw method what the text foreground color should be, so
>whatever it was set to previously in the DC will be used. Perhaps
>that is what you are seeing.
This morning, the code, untouched from yesterday, is not
demonstrating the color problem. But you're probably right about
what I was seeing. I'll proceed on that basis.
>> (ii) notice which rows are redrawn, and in what order
>> -- Why so many?
>> (b) When one clicks on any row not immediately below
>> the current row,
>> (i) notice that the color problem seen above
>> does not occur
>> -- Why not?
>> (ii) notice that fewer rows are redrawn
>> -- Why?
>
>IIRC, when a new cell selected then the cells around the old one are
>marked as needing refreshed because the cursor rectangle can overlap
>the other cells by 1 pixel, so those cells end up getting redrawn to
>be able to restore the border where the cursor used to be.
That I understand, and that is exactly what's done when I use the
two-argument CreateGrid call:
self.CreateGrid( len(data), 2 )
But when I include the selmode argument:
self.CreateGrid( len(data), 2, gridlib.Grid.SelectRows)
many more cells are redrawn, and I see no reason for that.
By the way, I'm only using wxGrid because I need to support italics,
subscripts, superscripts, the Greek alphabet, color, etc.
In my real application, the wxGrid will have a single column, i.e.,
conceptually it'll be a list control, but I can't use ListCtrl, as
you've mentioned in a previous note, because ListCtrl only supports
plain text.
To me, that seems like a significant gap in wxPython's GUI coverage.
Bob
More information about the wxpython-users
mailing list