wxGridCellChoiceEditor -howto?

I have a huge wxGrid based on database rows and columns.
Some columns are "foreign keys". I represent them via wxGridCellChoiceEditor
showing the referenced values.

Of cause, all these "choices" are equal for all columns of a row, only the
selection differs.

When I use a standard wxGridCellChoiceEditor, it seems to copy the list of
strings instead of maintaining a reference to it - wasting huge amounts of
memory and making it time consuming updating the choice list for all editors.

What would the best way be to keep a reference to a single "choice" list so
that all wxGridCellChoiceEditors show always the same options?

Horst

Hello Horst,

What would the best way be to keep a reference to a single "choice"
list so that all wxGridCellChoiceEditors show always the same
options?

I made it that way, that I selected ID and description into a Dictionary
on initiating the Class of my form, so that I have let's say
self.choiceeditor={1:'my', 2:'values', 12:'for', 27:'the',
199:'editor'}

The wxGridCellChoiceEditor can be filled with
self.choiceeditor.values()

Assuming, the choice is 'for'
When writing back to the DB, I get the value to write (the ID) by:
self.choiceeditor.keys()[self.choiceeditor.values().index('for')]

This would return 12.

I think, this is not the best of all possibilities, but for me, it
works...

hth,

Bjoern.

···

--
small office solutions
info@sosnetz.de - http://www.sosnetz.de

Thanks, but this is not what I meant.
I use a dict too. However,
1.) if a value gets added to that dict, I want it to show up in *all*
ChoiceEditors
2.) without wasting huge amounts of memory and processor time

in short, I want all wxGridCellChoiceEditors share the same string list
(reference to the same string list)

I'll probably have to write my own editor for that purpose.

Horst

···

On Mon, 10 Mar 2003 21:26, Björn Platzen wrote:

Hello Horst,

> What would the best way be to keep a reference to a single "choice"
> list so that all wxGridCellChoiceEditors show always the same
> options?

I made it that way, that I selected ID and description into a Dictionary
on initiating the Class of my form, so that I have let's say
self.choiceeditor={1:'my', 2:'values', 12:'for', 27:'the',
199:'editor'}

Thanks, but this is not what I meant.
I use a dict too. However,
1.) if a value gets added to that dict, I want it to show up in *all*
ChoiceEditors
2.) without wasting huge amounts of memory and processor time

in short, I want all wxGridCellChoiceEditors share the same string list
(reference to the same string list)

I'll probably have to write my own editor for that purpose.

<disclaimer>
I've never done anything complex with wxGrid, so what I'm saying could be
completely nonsense
</disclaimer>

Anyway... this is not exactly what you ask, but it should be enough: why
don't you fill the wxGridCellChoiceEditors dynamically, only when needed?
You start with a list of choices, not associated with any editor, and
with all editors empty. When a user selects a cell for editing, you
update the corresponding editor inside a EVT_GRID_EDITOR_SHOWN event
handler. In this way you should save the memory for all the cells that
are not modified, and you don't need to update all the editors each time
the list changes.

Makes sense?

Alberto

Horst Herb wrote:

I have a huge wxGrid based on database rows and columns.
Some columns are "foreign keys". I represent them via wxGridCellChoiceEditor showing the referenced values.

Of cause, all these "choices" are equal for all columns of a row, only the selection differs.

When I use a standard wxGridCellChoiceEditor, it seems to copy the list of strings instead of maintaining a reference to it - wasting huge amounts of memory and making it time consuming updating the choice list for all editors.

How are you setting the cell attributes that uses the wxGridCellChoiceEditor? Are you setting it for each cell or just for the column? If the latter I think it is only supposed to create the Editor once and reuse it for all cells in the column.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

How do I set it just for the column? This is actually what I wanted to do, but
couldn't find in the documentation how to do it.

Horst

···

On Tue, 11 Mar 2003 05:23, Robin Dunn wrote:

How are you setting the cell attributes that uses the
wxGridCellChoiceEditor? Are you setting it for each cell or just for
the column? If the latter I think it is only supposed to create the
Editor once and reuse it for all cells in the column.

Establish a datatype which will represent your particular "enumeration". This is just a string, so, for instance "enumeration.myParticularEumeration" would be fine.

Register your new class (grid-editor) to handle that datatype for the wxGrid.

Have your table return the datatype (string) when asked what type the items in that "column" are.

Have the initialiser for the control do the SetChoices stuff (or just check to see if the choices have already been set, and if so, don't re-set them).

You can find a general overview of the data-type-registry stuff in the wxGrid wiki.

HTH,
Mike

Horst Herb wrote:

···

On Tue, 11 Mar 2003 05:23, Robin Dunn wrote:

How are you setting the cell attributes that uses the
wxGridCellChoiceEditor? Are you setting it for each cell or just for
the column? If the latter I think it is only supposed to create the
Editor once and reuse it for all cells in the column.
   
How do I set it just for the column? This is actually what I wanted to do, but couldn't find in the documentation how to do it.

Horst

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

--
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/

Horst Herb wrote:

···

On Tue, 11 Mar 2003 05:23, Robin Dunn wrote:

How are you setting the cell attributes that uses the
wxGridCellChoiceEditor? Are you setting it for each cell or just for
the column? If the latter I think it is only supposed to create the
Editor once and reuse it for all cells in the column.

How do I set it just for the column? This is actually what I wanted to do, but couldn't find in the documentation how to do it.

If you don't want to do it by data type as Mike mentions then just usgin grid.SetColAttr is another way to do it.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!