In our application we have a bunch of objects that we would like to be
able to display in a grid. We are working on using the
wxPyGridTableBase class as the repository for the grid data.
Since our grid can be quite large, we didn't want to hide the columns
by setting the column width to 0. As per the wxPython docs..."wxGrid
sets up arrays to store individual row and column sizes when non-default
sizes are used. The memory requirements for this could become
prohibitive if your grid is very large. "
My question then is, is there an easy way to effectively hide a column?
Below is one of the tests I tried while looking for a solution.
[Note: the sample code used here is from Lucs Heimatseite's web page on
using wxGrid. It can be found at http://www.saffre.f2s.com/941.htm ]
class Column:
"metadata for each column in the table"
def __init__(self,name):
self.name = name
self.visible = true #added
self.cellattr = wxGridCellAttr()
def GetCellValue(self,row):
if self.visible:
return getattr(row,self.name)
else:
return None
def SetCellValue(self,row,value):
return setattr(row,self.name,value)
class FloatColumn(Column):
def __init__(self,name,len,dec):
Column.__init__(self,name)
self.visible = false ##override parent visible
self.cellattr.SetEditor(wxGridCellFloatEditor())
self.cellattr.SetRenderer(wxGridCellFloatRenderer(len,dec))
##additional classes snipped
class MyDataTable(wxPyGridTableBase):
def __init__(self, cols, rows):
wxPyGridTableBase.__init__(self)
self.columns = cols # data
self.rows = rows
##snip extra code...
def GetValue(self, rowIndex, colIndex):
"required"
ret = ''
## looking for a way to skip the paint of the column if
attribute if set
if self.columns[rowIndex].visible == false:
return ret
else:
try:
row = self.rows[rowIndex]
ret = self.columns[colIndex].GetCellValue(row)
except IndexError:
ret = ''
print "GetValue(%d,%d) -> %s" % (rowIndex, colIndex, ret)
return ret
As expected, when the grid is rendered, the column appears in the grid,
but the value is empty. What I would like is a way to hide the column
from even being displayed in the grid. I would like to still have the
column in the PyGridTableBase though so that it can be referenced
easily.
Most of the time this mechanism will be used to hide data that the user
doesn't need to see, such as the ID of an item. Eventually though, I
would like to be able to allow the users to set the visible flag
themselves as a means of configuring their preferences.
Has anyone done anything similar? or anyone have any ideas?