hello ML, I'm using wx.grid to view a database table (50k records). I'm setting attributes to columns and also for some rows (if a field of a record has a particular value I change the colour of the row values). I fetch the records from the
database as needed and I set cell attributes with wx.grid.PyTableBase.GetAttr because of the different
combinations of col and row attributes. It all works fine except when I click on a grid column label. In this
case the column is selected, GetAttr is called for all the 50000 cells of the column (seems to be the default behaviour of
wxpython) and the user has to wait too many seconds for the column to be selected. How can I prevent GetAttr from being called
if a cell is not visible? Now I'm doing as follows but is not the solution (it takes too much time, it would be better not to call
GetAttr at all for the hidden cells)
#in PyGridTableBase subclass' __init__
self.inactive = wx.grid.GridCellAttr()
self.inactive.SetTextColour(wx.LIGHT_GREY) #other attributes set for cols
def GetAttr(self, row, col, kind): #simplified version of my method wihtout column attributes
if self.GetView().IsVisible(row, col, False):
try:
x=getattr(self.data[row][1],'active')
except:
x=-1
if x==0:
self.inactive.IncRef()
return self.inactive
Even if your table contains 50,000 records normally it is not necessary to copy all records on the grid, and if you use wx.GridTableBase.Clear() and wx.GridTableBase.AppendRows(n), where n is the number olf records you actually call, you’ll get a reasonable number of rows that wx.Python will manage fast.
By the way, if you accept the standard cell attributes then wx.grid -whatever the number of cells- will need to read only a few general variables to redraw itself. Things become much more cumbersome if you assign different values to a lot of cells, because a very long array will have to be written and read. In that case, in my experience, it is better to subclass your own renderer and change the cell’s look in the Draw() method, that acts only when the cell is visible. (If you have Robin’s handbook, have a look at chapter 14).
hello ML, I’m using wx.grid to view a database table (50k records). I’m setting attributes to columns and also for some rows (if a field of a record has a particular value I change the colour of the row values). I fetch the records from the
database as needed and I set cell attributes with wx.grid.PyTableBase.GetAttr because of the different
combinations of col and row attributes. It all works fine except when I click on a grid column label. In this
case the column is selected, GetAttr is called for all the 50000 cells of the column (seems to be the default behaviour of
wxpython) and the user has to wait too many seconds for the column to be selected. How can I prevent GetAttr from being called
if a cell is not visible? Now I’m doing as follows but is not the solution (it takes too much time, it would be better not to call
GetAttr at all for the hidden cells)
#in PyGridTableBase subclass' __init__
self.inactive = wx.grid.GridCellAttr()
self.inactive.SetTextColour(wx.LIGHT_GREY)
#other attributes set for cols
def GetAttr(self, row, col, kind):
#simplified version of my method wihtout column attributes
if self.GetView().IsVisible(row, col, False):
try:
x=getattr(self.data[row][1],'active')
except:
x=-1
if x==0:
self.inactive.IncRef()
return self.inactive
The only reason I can think of that would cause it to fetch the attributes for all cells in the column is if you've done something like turn on autosizing, or explicitly call the autosize methods. Then it will need to fetch the attributes to get the font to use for measuring cell content.
If you're not doing anything like that then please make a small runnable sample that shows the problem so we can see exactly what you are doing.
···
m.prosperi@libero.it wrote:
hello ML, I'm using wx.grid to view a database table (50k records). I'm setting attributes to columns and also for some rows (if a field of a record has a particular value I change the colour of the row values). I fetch the records from the
database as needed and I set cell attributes with wx.grid.PyTableBase.GetAttr because of the different
combinations of col and row attributes. It all works fine except when I click on a grid column label. In this
case the column is selected, GetAttr is called for all the 50000 cells of the column (seems to be the default behaviour of
wxpython) and the user has to wait too many seconds for the column to be selected. How can I prevent GetAttr from being called
if a cell is not visible? Now I'm doing as follows but is not the solution (it takes too much time, it would be better not to call
GetAttr at all for the hidden cells)
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!