How to override PyGridTableBase.SetColLabelValue()?

F

fckuen

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?

my code,
#===========================================
class MegaTable(wx.grid.PyGridTableBase):
def __init__(...)
......
wx.grid.PyGridTableBase.__init__(self)

def SetColLabelValue(self, col, value):
value = self.coltags[col]
-->how to ???

class MegaGrid(wx.grid.Grid):
def __init__(...)
......
wx.grid.Grid.__init__(self, parent, id)
self._table = MegaTable(self, .....)
self.SetTable(self._table)
......
#===========================================


thanks!
 
A

ajaksu

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 :)

(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
 
F

Frank Millman

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?

my code,
#===========================================
class MegaTable(wx.grid.PyGridTableBase):
def __init__(...)
.....
wx.grid.PyGridTableBase.__init__(self)

def SetColLabelValue(self, col, value):
value = self.coltags[col]
-->how to ???

class MegaGrid(wx.grid.Grid):
def __init__(...)
.....
wx.grid.Grid.__init__(self, parent, id)
self._table = MegaTable(self, .....)
self.SetTable(self._table)
.....
#===========================================

thanks!

You are not supposed to override SetColLabel(), you are supposed to
override GetColLabelValue().

When you use PyGridTableBase, there could potentially be thousands of
columns, and wxPython does not want to keep track of thousands of
column labels.

Therefore, when wxPython needs to display a column label, it calls
GetColLabelValue(self,col). It is up to you to return the value to use
for that column.

HTH

Frank Millman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top