[wxPython] Problems with wxTreeItemData and wxTreeItemId

(This is similar to, but not the same as a problem I reported a few weeks
ago.)

For a wxTreeItemData object, I use SetId() to set it to a wxTreeItemId, but
when I call GetId() on it I get back a different wxTreeItemId object.

    NewTreeItemData = wx.wxTreeItemData( iRID );
    NewItemId = self.AddRoot( "string", -1, -1, NewTreeItemData );
    NewTreeItemData.SetId( NewItemId );
    print "NewItemId = " + str(NewItemId);
    print "ItemData.GetId() =" + str(NewTreeItemData.GetId());

These print statements yield (I expected them to be the same):

NewItemId = <C wxTreeItemId instance at _842fe8_wxTreeItemId_p>
ItemData.GetId() =<C wxTreeItemId instance at _12f8cc_wxTreeItemId_p>

I've included the whole method at the bottom in case I haven't included
enough here. I realize that there are Python-specific shortcut methods for
doing these things, but I want to do it the C++ way since I might need to
convert this to C++ later.

BTW, I'm also confused by the idea that wxTreeItemData is both associated
with (through the call to SetId()) and inherits from wxTreeItemId.

Thanks for any suggestions,

Tom.

    def __init__(self, parent, id ):
        wx.wxTreeCtrl.__init__(self, parent, id);
        self.SetImageList( TypeImages );
        self.ObjMap = CNsiTree.CObjMap();

        # Add Root Item
        RootPyObj = ns.ObjStore.GetRoot();
        assert RootPyObj; # ObjStore must have a root.
        iRID = CNsiTree.CItemData( "Nametree Root", RootPyObj );

        NewTreeItemData = wx.wxTreeItemData( iRID ); # temp

        NewItemId = self.AddRoot( iRID.GetDispStr(), -1, -1,
NewTreeItemData );

# NewTreeItemData = iRID.SetId( NewItemId );

        NewTreeItemData.SetId( NewItemId ); # temp

        print "NewItemId = " + str(NewItemId);
        print "ItemData.GetId() =" + str(NewTreeItemData.GetId());
        # NewItemId = <C wxTreeItemId instance at _842fe8_wxTreeItemId_p>
        # ItemData.GetId() =<C wxTreeItemId instance at
_12f8cc_wxTreeItemId_p>
        assert NewItemId == NewTreeItemData.GetId();
            # Fails

        self.SetItemData( NewItemId, NewTreeItemData );
        self.RootItemId = NewItemId;
        self.ObjMap.Add( iRID );
        self.SetItemHasChildren( NewItemId, iRID.HasChildren() );
        # End of add root item.

        print "Root ItemId is " + str(NewItemId);

        # Test going from ItemId to PyObj
        assert self.GetPyObj( NewItemId ) == RootPyObj;

        # Test going from PyObj to ItemId.
        ItemDataList = self.ObjMap.get( RootPyObj.Id );
        assert len( ItemDataList ) == 1;
        ItemData = ItemDataList[0];
        assert ItemData == NewTreeItemData;
        ItemId = ItemData.GetId();
        assert ItemId == NewItemId;

        wx.EVT_TREE_ITEM_EXPANDING(self, self.GetId(),
self.OnItemExpanding);
        wx.EVT_TREE_ITEM_COLLAPSING(self, self.GetId(),
self.OnItemCollapsing);
        wx.EVT_TREE_DELETE_ITEM(self, self.GetId(), self.OnItemDeleted);
        EventMan.Subscribe( self.EventReceptor );

For a wxTreeItemData object, I use SetId() to set it to a wxTreeItemId,

but

when I call GetId() on it I get back a different wxTreeItemId object.

    NewTreeItemData = wx.wxTreeItemData( iRID );
    NewItemId = self.AddRoot( "string", -1, -1, NewTreeItemData );
    NewTreeItemData.SetId( NewItemId );
    print "NewItemId = " + str(NewItemId);
    print "ItemData.GetId() =" + str(NewTreeItemData.GetId());

These print statements yield (I expected them to be the same):

NewItemId = <C wxTreeItemId instance at _842fe8_wxTreeItemId_p>
ItemData.GetId() =<C wxTreeItemId instance at _12f8cc_wxTreeItemId_p>

It looks like there might be a bug in the wxMSW version of GetId(), but even
if it is fixed to behave like the one in wxGTK you will still see similar
behaviour in wxPython. This is because wxTreeItemData is actully storing
the internal (platform specific) handle of the tree item and GetId() is
constructing and returning a new wxTreeItemId around that handle.

BTW, I'm also confused by the idea that wxTreeItemData is both associated
with (through the call to SetId()) and inherits from wxTreeItemId.

I've never understood this either...

···

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

Robin,

Yes, thanks - that seems to be it. Now I'm storing the TreeItemId in my own
ItemData class and this seems to work.

BTW, I sent an E-mail to sales@wxpros this morning that - since you seem to
be the one answering all my questions - I should perhaps have sent to you.
Please comment when you get a chance.

Thanks,

Tom.

"Robin Dunn" <robin@alldunn.com> wrote in message
news:02df01c01c4a$1ea03f70$0b01a8c0@ARES...

> For a wxTreeItemData object, I use SetId() to set it to a wxTreeItemId,
but
> when I call GetId() on it I get back a different wxTreeItemId object.
>
> NewTreeItemData = wx.wxTreeItemData( iRID );
> NewItemId = self.AddRoot( "string", -1, -1, NewTreeItemData );
> NewTreeItemData.SetId( NewItemId );
> print "NewItemId = " + str(NewItemId);
> print "ItemData.GetId() =" + str(NewTreeItemData.GetId());
>
> These print statements yield (I expected them to be the same):
>
> NewItemId = <C wxTreeItemId instance at _842fe8_wxTreeItemId_p>
> ItemData.GetId() =<C wxTreeItemId instance at _12f8cc_wxTreeItemId_p>
>

It looks like there might be a bug in the wxMSW version of GetId(), but

even

if it is fixed to behave like the one in wxGTK you will still see similar
behaviour in wxPython. This is because wxTreeItemData is actully storing
the internal (platform specific) handle of the tree item and GetId() is
constructing and returning a new wxTreeItemId around that handle.

>
> BTW, I'm also confused by the idea that wxTreeItemData is both

associated

···

> with (through the call to SetId()) and inherits from wxTreeItemId.
>

I've never understood this either...

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