[wxPython-users] Grid Cell Renderer
Mark Erbaugh
mark at microenh.com
Tue Feb 5 07:03:56 PST 2008
On Wed, 2008-01-02 at 17:00 -0800, Robin Dunn wrote:
> Mark Erbaugh wrote:
> > On Wed, 2008-01-02 at 06:58 +0100, Raffaello Barella wrote:
> >> Could you please tell what kinds of data you want to convert to a
> >> string?
> >>
>
> >
> > The data is an integer that corresponds to the string. I have a dict
> > that has the integer as the key and the string as the value.
> >
> > wxPython has a GridCellEnumRenderer but I can't seem to get that working
> > and other than it's existence, I can't find any documentation on it.
> > It's not listed in the wxWidgets documentation, although it is there in
> > the C++ code.
>
> If you really want to keep the integer values all the way through then
> try implementing GetValueAsLong(self, row, col) in the table, and also
> CanGetValueAs(self, row, col, typeName) and return true for that cell
> for typeName == "long". Otherwise the grid, editors, and renderers
> should translate the value to/from strings as needed.
I'm having no luck implementing GetValueAsLong. I added CanGetValueAs
and GetValueAsLong methods to my grid table. I placed a print
statement in it so I can see that it is being called and it returns a
Python True. However, the table's GetValueAsLong is not being called.
Instead, the table's GetValue is called. I've looked at the C++ code:
wxGridTableBase *table = grid->GetTable();
if ( table->CanGetValueAs(row, col, wxGRID_VALUE_NUMBER) )
{
m_startint = table->GetValueAsLong(row, col);
}
else
{
wxString startValue = table->GetValue(row, col);
And it sure looks like it should work. Here are the relevant methods
from the table:
def CanGetValueAs(self, row, col, typeName):
col_name = self.col_fields[col]
if (col_name == 'category_rsn') and (typeName ==
wx.grid.GRID_VALUE_NUMBER):
print 'can get value as long'
return True
else:
return False
def GetValueAsLong(self, row, col):
print 'get value as long'
col_name = self.col_fields[col]
r = self.data[row][col_name]
return r
Suggestions?
Mark
More information about the wxpython-users
mailing list