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?
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, timr@probo.com
Providenza & Boekelheide, Inc.
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()
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.
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: