[wxPython] Virtual wxListCtrl -- should there be an OnGetItemData?

I am looking at creating a virtual list control (one which can handle very large collections of objects). To be useful, it would seem necessary to be able to determine what objects are being manipulated (selected, deleted, etceteras), so I'd like to associate an ID with each item generated.

The design of a virtual list control, however, would seem to say that I should use an overridden method responding to the control's internal machinery (so that the list control can manage whether to retain the data or not). That method (OnGetItemData or the like) doesn't seem to be available.

Any suggestions?
Mike

···

_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

I am looking at creating a virtual list control (one which can handle
very large collections of objects). To be useful, it would seem
necessary to be able to determine what objects are being manipulated
(selected, deleted, etceteras), so I'd like to associate an ID with each
item generated.

The design of a virtual list control, however, would seem to say that I
should use an overridden method responding to the control's internal
machinery (so that the list control can manage whether to retain the
data or not). That method (OnGetItemData or the like) doesn't seem to
be available.

I think with the virtual listctrl you need to be able to map everything from
the item id. If there was a OnGetItemData you would have to map from the
item id to the data there anyway so why not do it in the OnGetItemText and
etc.?

···

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

Hmm, I must be missing something fundamental.

I was under the (fairly distinct) impression that what was passed to the virtual functions (and returned from search functions, etceteras) wasn't a unique itemID, such as seen in the treectrl, but an index into the current order of the control. That is, if the list control is sorted, items are removed/added, or the user drags items around within the control the indices would change.

If that's the case, then I need to be able to associate an identity tag with the item, so that search methods which return indices can be de-referenced via GetItemData to get the correct object.

If it's not, all of my list code has been needlessly complex for as long as I've been using wxPython. [Reads wxListCtrl documentation start-to-finish, discovers the key (maybe) in SetItem.] Sigh.

Apparently the internal m_itemId is just a zero-based index. No mention of whether it's updated when items are added/removed in front of the item (so it may or may not change?) Or whether the index is related to an internal list structure or the visible coordinates. I just don't know from the docs what the behaviour is.

If the ids change, then a simple mapping won't work, but a Python list of objects updated on Remove/Insert might. If they don't change, then there's something going on when you do Remove/Insert that I don't understand.

Ouch my head :slight_smile: ,
Mike

Robin Dunn wrote:

···

I am looking at creating a virtual list control (one which can handle
very large collections of objects). To be useful, it would seem
necessary to be able to determine what objects are being manipulated
(selected, deleted, etceteras), so I'd like to associate an ID with each
item generated.

The design of a virtual list control, however, would seem to say that I
should use an overridden method responding to the control's internal
machinery (so that the list control can manage whether to retain the
data or not). That method (OnGetItemData or the like) doesn't seem to
be available.

I think with the virtual listctrl you need to be able to map everything from
the item id. If there was a OnGetItemData you would have to map from the
item id to the data there anyway so why not do it in the OnGetItemText and
etc.?

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

Hmm, I must be missing something fundamental.

I was under the (fairly distinct) impression that what was passed to the
virtual functions (and returned from search functions, etceteras) wasn't
a unique itemID, such as seen in the treectrl, but an index into the
current order of the control. That is, if the list control is sorted,
items are removed/added, or the user drags items around within the
control the indices would change.

Yes, that is correct. I guess I misunderstood what you were asking before.

If that's the case, then I need to be able to associate an identity tag
with the item, so that search methods which return indices can be
de-referenced via GetItemData to get the correct object.

Not really. With a virtual list ctrl there are never any data items in the
list crtl itself that could get out of order or out of sync with your data,
(or in MVC terms, your Model.) All data comes from your Model on an
as-needed basis. If the data in the Model changes, is reordered, or has
insertions/deletions, then a refresh of the View will automatically reflect
those changes.

It's kind of an inside out way (but probably more natural) way of thinking
about and using the wxListCtrl. Once you think about it from that point of
view I think you will see that you no longer need to have an identity tag to
map list items to your actual data, just a way to get your data by index in
the current sort order (if any.)

···

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

Hmm, I get the concept, it's just surprising when you consider the ability to drag items around in the list's window (i.e. changing their physical order). I'm going to have to do a spike test to confirm what happens when you drag an item around (does it send events to the underlying model (no), or does it just do a refresh and wind up ignoring the attempt to re-order the items, or does the physical x,y coordinate not affect the order as understood by the control).

At least I don't have to go back and rewrite the old code :wink: .

Thanks Robin,
Mike

Robin Dunn wrote:

···

Hmm, I must be missing something fundamental.

I was under the (fairly distinct) impression that what was passed to the
virtual functions (and returned from search functions, etceteras) wasn't
a unique itemID, such as seen in the treectrl, but an index into the
current order of the control. That is, if the list control is sorted,
items are removed/added, or the user drags items around within the
control the indices would change.

Yes, that is correct. I guess I misunderstood what you were asking before.

If that's the case, then I need to be able to associate an identity tag
with the item, so that search methods which return indices can be
de-referenced via GetItemData to get the correct object.

Not really. With a virtual list ctrl there are never any data items in the
list crtl itself that could get out of order or out of sync with your data,
(or in MVC terms, your Model.) All data comes from your Model on an
as-needed basis. If the data in the Model changes, is reordered, or has
insertions/deletions, then a refresh of the View will automatically reflect
those changes.

It's kind of an inside out way (but probably more natural) way of thinking
about and using the wxListCtrl. Once you think about it from that point of
view I think you will see that you no longer need to have an identity tag to
map list items to your actual data, just a way to get your data by index in
the current sort order (if any.)

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

Hmm, I get the concept, it's just surprising when you consider the
ability to drag items around in the list's window (i.e. changing their
physical order). I'm going to have to do a spike test to confirm what
happens when you drag an item around (does it send events to the
underlying model (no), or does it just do a refresh and wind up ignoring
the attempt to re-order the items, or does the physical x,y coordinate
not affect the order as understood by the control).

Well, to do DnD or sorting you've got to deal with it in event handlers of
the list ctrl, so they can update your model. With a virtual list any
attempt to display items goes to the OnGetItemText to get the items so any
change in the display has to be done in the model first.

···

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