[wxPython-users] question on setting choice values in a grid
Robin Dunn
robin at alldunn.com
Wed May 2 13:55:53 PDT 2007
Danny Shevitz wrote:
> Howdy,
>
> I am having trouble bootstrapping my knowledge of grids. I want to use a
> choice editor in a cell, but
> to have the choices change dynamically based on contents of another cell
> (also a choice editor).
>
> I can not figure out the API for changing the choices. I do not know if
> this is the best way to do it, but I am
> basing my code on the gridCustTable.py demo
>
> class CustomDataTable(gridlib.PyGridTableBase):
> def __init__(self, log):
> gridlib.PyGridTableBase.__init__(self)
>
> self.colLabels = ['field1', 'field2']
>
> self.dataTypes = [
> gridlib.GRID_VALUE_CHOICE ,
> gridlib.GRID_VALUE_CHOICE ,
> ]
> ...
>
> notice that I have left the "+ ':a,b,c,..' " off the dataTypes with the
> intention of setting them later.
> Can anyone point out the API how I do this?
You can catch the EVT_GRID_EDITOR_SHOWN event and in the handler get
access to the editor for the row,col and then call it's GetControl
method. From there you should be able to remove or add items to the
choice control.
> Also, I find the
> self.dataTypes behavior completely
> undocumented. Can someone point out either documentation or else where
> the source code lives?
The self.dataTypes list is simply used by the table's GetTypeName
method, the list could have just as easily been defined in the method,
or custom coded in the method some other way. The grid calls that
method when it is trying to decide what kind of editor or renderer to
use for that cell by default. There are several predefined data type
names, and you can also register your own custom ones if you want.
Depending on the type the names can have some extra info appended after
a colon and the editors or renderers can use that to configure or
initialize themselves in some non-default way.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list