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
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
GetValue 1 1
GetAttr 1 0
GetValue 1 0
GetAttr 0 1
GetValue 0 1
GetAttr 0 0
GetValue 0 0
GetAttr 0 0
GetAttr 0 1
GetAttr 1 0
GetAttr 1 1
GetAttr 0 0
Redraw Done