How to override PyGridTableBase.SetColLabelValue()?

ajaksu ajaksu at gmail.com
Mon Jul 9 06:42:25 CEST 2007


On Jul 9, 12:27 am, fck... at gmail.com wrote:
> Dear all,
>
> the doc is missing, and i failed to find the solution on google search.
> anyone know how to override the function SetColLabel() inside
> the class PyGridTableBase or the class GridTableBase?

Some docs to back up the old code that follows :)
http://wiki.wxpython.org/wxPyGridTableBase
http://wiki.wxpython.org/wxGrid
http://wxwidgets.org/manuals/stable/wx_wxgrid.html#wxgridsetcollabelvalue

I hope this helps, it's old and 2.6, the design had many weird
requirements plus I never got to think about whether it was a good way
to do it. Anyway, the docs are far better :)


> my code,
(snip)
Mine:
class SpeciesBase(object):
    def __init__(self, ncols=1, nrows=15, colnames=None,
rownames=None):
        self.__data = []
        self.rows = []
        self.cols = []
    def __getitem__(self, col):
        return self.__data[col][:]

class SpeciesTableBase(wx.grid.PyGridTableBase):
    def __init__(self):
        wx.grid.PyGridTableBase.__init__(self)
        self.data = SpeciesBase()
        self._rows = self.GetNumberRows()
        self._cols = self.GetNumberCols()
    def SetColLabelValue(self, col, value):
        self.data.cols[col] = str(value)
    def GetNumberRows(self):
        return len(self.data[0])

class SpeciesGrid(wx.grid.Grid):
    def __init__(self, parent):
        wx.grid.Grid.__init__(self, parent, -1)
        self.table = SpeciesTableBase()
    def rename_col(self, col, value):
        self.table.SetColLabelValue(col, value)
        self.table.ResetView(self)

Other useful links:
http://wiki.wxpython.org/UpdatingGridData
http://wiki.wxpython.org/DrawingOnGridColumnLabel




More information about the Python-list mailing list