wxTreeCtrl.InsertItemBefore?

def GetItemPosition(self, item):
        pos = 0
        item = self.GetPrevSibling(item)
        while item.IsOk():
             item = self.GetPrevSibling(item)
             pos += 1
        return pos

Is there a simpler way? If not, is the above code sound?

This looks okay but why not just get the itemId of
the previous and then do a regular Insert after that item?

That requires special-case processing when there is no previous item,
unless I'm missing a trick?

Since there is a method which has a "position" parameter, do you think it
would be worthwhile adding a means of getting the position into the API?
That seems to fit nicely into the "Principle of Least Surprise". :slight_smile:

--
Robin Dunn

Cheers,

Jon.

Jonathan Bills wrote:

def GetItemPosition(self, item):
       pos = 0
       item = self.GetPrevSibling(item)
       while item.IsOk():
            item = self.GetPrevSibling(item)
            pos += 1
       return pos

Is there a simpler way? If not, is the above code sound?

This looks okay but why not just get the itemId of the previous and then do a regular Insert after that item?

That requires special-case processing when there is no previous item, unless I'm missing a trick?

You're right, but if there are lots of items it may be more efficient to have and check for the special case rather than traverse all the items...

Since there is a method which has a "position" parameter, do you think it would be worthwhile adding a means of getting the position into the API? That seems to fit nicely into the "Principle of Least Surprise". :slight_smile:

Makes sense. You should add a feature request for it.

···

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