[wxPython-users] Re: wx.Grid.SetDefaultRenderer doesn't seem
to be working
Robin Dunn
robin at alldunn.com
Mon Jan 29 12:20:59 PST 2007
Grzegorz Adam Hankiewicz wrote:
> Christian Kristukat wrote:
>>> So far I've copied the grid examples from the demo where the cell
>>> renderer is set for individual cells. Since I actually have one
>>> type of cell, I loop over all of them setting it. It is however
>>> annoying when I try to add new rows, because I have to go again
>>> setting their cell renderer.
>>
>> If you are using a custom TableBase you can override its GetAttr
>> method and and let it return a GridCellAttr with a renderer of your
>> choice, e.g.:
>>
>> def GetAttr(self, *args): attr = wx.grid.GridCellAttr()
>> attr.SetReadOnly() attr.SetRenderer(FloatRenderer()) return attr
>
> Yes, this works.
>
>> I have not tried it but according to what the the docs say I would
>> expect it to work. Can you send your code?
>
> Here it is. If you uncomment the lines which set the renderer explicitly
> it will work as expected. I'm using 2.8.0.1 under MSW. I wonder if the
> memory leak fixed in 2.8.1.0 (patch 1629949) makes SetDefaultRenderer()
> work.
There is a precedence order in place for how to get the attributes,
editor, renderer, etc. for a cell. There is also a data type registry
for providing the editor and renderer based on the data type of the
cell. Since the type registry has a higher precedence than the default
cell attr then it's not really possible for the editor/renderer set in
the default cell attribute to have any effect. So to compensate for
this the SetDefaultRenderer and SetDefaultEditor functions were changed
a few years ago to instead register a new editor/renderer for the
default cell data type (string) instead of putting it into the default
cell attr.
However in your example your table is telling the grid that every cell
is a float type, so that registration of your default renderer for
strings is not being used. Instead it is using the default registration
for floats. So you can just override that instead of using
SetDefaultCellRenderer:
self.RegisterDataType(wx.grid.GRID_VALUE_FLOAT,
StupidRenderer(),
self.GetDefaultEditorForType(wx.grid.GRID_VALUE_FLOAT))
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list