4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

Allan Cheong
Hi. I have the tree event binded:

class MyFrame(...)
    def __init__(...)
        ...
        self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.on_tree_item_activated, self.tree_ctrl)
        ...

    def on_tree_item_activated(self, event):
        LOGGER.info(event.GetItem())
        LOGGER.info(event.GetItem().GetID())
        LOGGER.info(type(event.GetItem().GetID()))
        LOGGER.info(self.tree_ctrl_side_menu.GetSelection())

Every nodes when on double clicked/activated returns the same object in the memory space. "event.GetItem().GetID()" returns a "sip.voidptr object" type. Is there a way to know which tree item is activated?

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

Tim Roberts
Allan C. wrote:

> Hi. I have the tree event binded:
>
> class MyFrame(...)
>     def __init__(...)
>         ...
>         self.Bind(wx.EVT_TREE_ITEM_ACTIVATED,
> self.on_tree_item_activated, self.tree_ctrl)
>         ...
>
>     def on_tree_item_activated(self, event):
>         LOGGER.info(event.GetItem())
>         LOGGER.info(event.GetItem().GetID())
>         LOGGER.info(type(event.GetItem().GetID()))
>         LOGGER.info(self.tree_ctrl_side_menu.GetSelection())
>
> Every nodes when on double clicked/activated returns the same object
> in the memory space. "event.GetItem().GetID()" returns a "sip.voidptr
> object" type. Is there a way to know which tree item is activated?

What you have there is a "TreeItemId", like a handle for the item.  To
get the text for the item, use:
    text =  self.tree_ctrl.GetItemText( event.GetItem() )

--
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

Allan Cheong
Tim Roberts wrote:
> What you have there is a "TreeItemId", like a handle for the item.  To
> get the text for the item, use:
>     text =  self.tree_ctrl.GetItemText( event.GetItem() )

This works! I thought I have tried this. Thanks. Nonetheless, just
wondering if I can do something like this as well?

UI:
self.tree_ctrl = wx.TreeCtrl(self.panel, wx.ID_ANY, style=wx.TR_HIDE_ROOT)
self.tree_root = self.tree_ctrl.AddRoot('ROOT')
self.tree_leaf = self.tree_ctrl.AppendItem(self.tree_root, 'LEAF')

Event:
if event.GetItem().GetID() == self.tree_leaf.GetID()

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

Allan Cheong
Allan C. wrote:

> Tim Roberts wrote:
>> What you have there is a "TreeItemId", like a handle for the item.  To
>> get the text for the item, use:
>>     text =  self.tree_ctrl.GetItemText( event.GetItem() )
>
> This works! I thought I have tried this. Thanks. Nonetheless, just
> wondering if I can do something like this as well?
>
> UI:
> self.tree_ctrl = wx.TreeCtrl(self.panel, wx.ID_ANY, style=wx.TR_HIDE_ROOT)
> self.tree_root = self.tree_ctrl.AddRoot('ROOT')
> self.tree_leaf = self.tree_ctrl.AppendItem(self.tree_root, 'LEAF')
>
> Event:
> if event.GetItem().GetID() == self.tree_leaf.GetID()

I think comparing the ID could be a better approach, since string
comparison will not let me know which item is activated if there are
items with the same text but on different branches in the TreeCtrl. I
could format the text to make it unique on each leaf nodes - just
exploring some options. Appreciate your help. Cheers.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 4.0.0a3 wx.EVT_TREE_ITEM_ACTIVATED event not getting TreeItemID

Allan Cheong
Allan C. wrote:

> Allan C. wrote:
>> Tim Roberts wrote:
>>> What you have there is a "TreeItemId", like a handle for the item.  To
>>> get the text for the item, use:
>>>     text =  self.tree_ctrl.GetItemText( event.GetItem() )
>>
>> This works! I thought I have tried this. Thanks. Nonetheless, just
>> wondering if I can do something like this as well?
>>
>> UI:
>> self.tree_ctrl = wx.TreeCtrl(self.panel, wx.ID_ANY, style=wx.TR_HIDE_ROOT)
>> self.tree_root = self.tree_ctrl.AddRoot('ROOT')
>> self.tree_leaf = self.tree_ctrl.AppendItem(self.tree_root, 'LEAF')
>>
>> Event:
>> if event.GetItem().GetID() == self.tree_leaf.GetID()
>
> I think comparing the ID could be a better approach, since string
> comparison will not let me know which item is activated if there are
> items with the same text but on different branches in the TreeCtrl. I
> could format the text to make it unique on each leaf nodes - just
> exploring some options. Appreciate your help. Cheers.

Please ignore the spam. Got it working with the following:

        selection = self.tree_ctrl.GetSelection()
        if selection == self.tree_node_id:

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...