[wxPython-users] The grid control -- problems and questions

Robin Dunn robin at alldunn.com
Mon Sep 3 19:10:57 PDT 2007


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?  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.  Otherwise only 
those cells that intersect with whatever region the OS reports needs to 
be redrawn are painted.  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.


> 
>     (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.


>                       (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.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list