Grid Redraw

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Grid Redraw

Dietmar Schwertberger-2
Hi!

I've just tried to speed up the display of my data tables.
When profiling, I noticed that the GetValue and GetAttr methods are
called many more times than expected.

E.g. the script below defines a 2x2 grid.
For the first redraw, I counted 32 calls to GetValue and GetAttr.
E.g. the first 6 calls are:
  GetAttr 1 1
  GetAttr 1 1
  GetAttr 1 1
  GetAttr 1 1
  GetValue 1 1
  GetValue 1 1

This is with '2.8.12.0 (msw-unicode)'
Is there a way to avoid this?
I don't think that a single redraw should result in more than one call
per cell. It makes scrolling very slow even when I do some caching.
Is it fixed with a more recent version?


Regards,

Dietmar


=============================================================================
The script:

import  wx
import  wx.grid as  gridlib

class HugeTable(gridlib.PyGridTableBase):
     def __init__(self):
         gridlib.PyGridTableBase.__init__(self)
     def GetAttr(self, row, col, kind):
         print "GetAttr", row, col
         return None

     def GetNumberRows(self):
         return 2

     def GetNumberCols(self):
         return 2

     def IsEmptyCell(self, row, col):
         return False
     def GetValue(self, row, col):
         print "GetValue", row, col
         return str( (row, col) )

class HugeTableGrid(gridlib.Grid):
     def __init__(self, parent):
         gridlib.Grid.__init__(self, parent, -1)
         table = HugeTable()
         self.SetTable(table, True)

class TestFrame(wx.Frame):
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, -1, "Table", size=(400,200))
         grid = HugeTableGrid(self)
         #grid.SetReadOnly(5,5, True)


if __name__ == '__main__':
     def prn():
         print "Redraw Done"

     app = wx.PySimpleApp()
     frame = TestFrame(None)
     frame.Show(True)
     wx.CallLater(200, prn)
     app.MainLoop()

=============================================================================
The output:
GetAttr 1 1
GetAttr 1 1
GetAttr 1 1
GetAttr 1 1
GetValue 1 1
GetValue 1 1
GetAttr 1 0
GetAttr 1 0
GetAttr 1 0
GetAttr 1 0
GetValue 1 0
GetValue 1 0
GetAttr 0 1
GetAttr 0 1
GetAttr 0 1
GetAttr 0 1
GetValue 0 1
GetValue 0 1
GetAttr 0 0
GetAttr 0 0
GetAttr 0 0
GetAttr 0 0
GetValue 0 0
GetValue 0 0
GetAttr 0 0
GetAttr 0 1
GetAttr 1 0
GetAttr 1 1
GetAttr 0 0
GetAttr 0 0
GetAttr 0 0
GetAttr 0 0
Redraw Done

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Robin Dunn
On 3/7/12 2:34 PM, Dietmar Schwertberger wrote:

> Hi!
>
> I've just tried to speed up the display of my data tables.
> When profiling, I noticed that the GetValue and GetAttr methods are
> called many more times than expected.
>
> E.g. the script below defines a 2x2 grid.
> For the first redraw, I counted 32 calls to GetValue and GetAttr.
> E.g. the first 6 calls are:
> GetAttr 1 1
> GetAttr 1 1
> GetAttr 1 1
> GetAttr 1 1
> GetValue 1 1
> GetValue 1 1
>
> This is with '2.8.12.0 (msw-unicode)'
> Is there a way to avoid this?

Probably not with the current design of the wxGrid class, but the
DataViewCtrls in 2.9 should be better.

> I don't think that a single redraw should result in more than one call
> per cell. It makes scrolling very slow even when I do some caching.
> Is it fixed with a more recent version?

No.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Michael Hipp-3
On 2012-03-07 4:42 PM, Robin Dunn wrote:
> Probably not with the current design of the wxGrid class, but the
> DataViewCtrls in 2.9 should be better.

In your opinion, should new development be targeting to use the DVC
classes instead of Grid?

Michael

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Andrea Gavana
Hi Michael,

On 8 March 2012 01:21, Michael Hipp wrote:
> On 2012-03-07 4:42 PM, Robin Dunn wrote:
>>
>> Probably not with the current design of the wxGrid class, but the
>> DataViewCtrls in 2.9 should be better.
>
>
> In your opinion, should new development be targeting to use the DVC classes
> instead of Grid?

I had the same issues while I was writing the AGW widget XLSGrid,
which heavily uses the virtual grid with PyGridTableBase. I found
wxPython 2.9 to be much, *much* better in terms of refreshing. You can
see the whole discussion here, with the relevant thread in the middle
of the page:

http://groups.google.com/group/wxpython-users/browse_thread/thread/471a46bd442a2aef

Basically, it appears that in 2.9 wx.grid.Grid doesnt use too much
aggressive repainting anymore.

Andrea.

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

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Robin Dunn
In reply to this post by Michael Hipp-3
On 3/7/12 4:21 PM, Michael Hipp wrote:
> On 2012-03-07 4:42 PM, Robin Dunn wrote:
>> Probably not with the current design of the wxGrid class, but the
>> DataViewCtrls in 2.9 should be better.
>
> In your opinion, should new development be targeting to use the DVC
> classes instead of Grid?

It depends on what your application needs, their feature sets do
overlap, but there are some things that one can do that the other can't.


--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Dietmar Schwertberger-2
In reply to this post by Andrea Gavana
Hi Andrea, Robin!

Am 08.03.2012 08:42, schrieb Andrea Gavana:
> Basically, it appears that in 2.9 wx.grid.Grid doesnt use too much
> aggressive repainting anymore.


Thanks a lot.
I've tried 2.9, but for me it does not make too much difference, as
the slow redrawing is mainly a problem when going a complete page
down or up.


Given the speed difference between a grid with a data table and a
simple grid, my feeling is that the main problem is the high number
of callbacks from C++ to Python code.

Anyway I have been thinking whether it would be possible to use
Cython with wxPython.
My data table takes the data from numpy arrays, so if I could implement
this in Cython, there would be no overhead from any Python calls.

Also, I have some plotting code where I would like to try to implement
the inner redraw loop in Cython.

Has anybody successfully tried Cython with wxPython/wxWidgets?


Regards,

Dietmar

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Mike Driscoll


On Thursday, March 8, 2012 3:50:21 PM UTC-6, Dietmar Schwertberger wrote:
Hi Andrea, Robin!

Am 08.03.2012 08:42, schrieb Andrea Gavana:
> Basically, it appears that in 2.9 wx.grid.Grid doesnt use too much
> aggressive repainting anymore.


Thanks a lot.
I've tried 2.9, but for me it does not make too much difference, as
the slow redrawing is mainly a problem when going a complete page
down or up.


Given the speed difference between a grid with a data table and a
simple grid, my feeling is that the main problem is the high number
of callbacks from C++ to Python code.

Anyway I have been thinking whether it would be possible to use
Cython with wxPython.
My data table takes the data from numpy arrays, so if I could implement
this in Cython, there would be no overhead from any Python calls.

Also, I have some plotting code where I would like to try to implement
the inner redraw loop in Cython.

Has anybody successfully tried Cython with wxPython/wxWidgets?


Regards,

Dietmar


I haven't heard of anyone using Cython with wx, but there was an article last year about the PyPy guys using wxPython as a proof of concept.

- Mike

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en
Reply | Threaded
Open this post in threaded view
|

Re: Grid Redraw

Chris Barker - NOAA Federal
On Fri, Mar 9, 2012 at 6:22 AM, Mike Driscoll
>> Has anybody successfully tried Cython with wxPython/wxWidgets?

> I haven't heard of anyone using Cython with wx,

Neither have I, but I have thought about it.

it shuld be possible -- you'd need to figure out how to grab a pointer
to the wxObjects you need -- they shodl be burried in the SWIG objects
used -- I've heard them called "swigified pointers" -- I think there
is a pointer stored as a python integer in there somewhere. If you can
find that, the Cython part could be pretty straightforward.

You would have to make sure that your Cython code is built against the
right version of wx, also.

Good luck, and let us know how it goes!

-Chris


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wxPython-users?hl=en