how identify which item is selected in the wxTreeCtrl

i want show a diferent menu in diferent item selected when i make
right click for example how identify when i make right click in the
root or if i select child or child-root show a diferent menu for each
how use GetSelection() method or GetRootItem()

i want use the switch cases for send each selection to diferent
function of each menui know how do that but i dont know how get the
selected item

Hi,

i want show a diferent menu in diferent item selected when i make
right click for example how identify when i make right click in the
root or if i select child or child-root show a diferent menu for each
how use GetSelection() method or GetRootItem()

Did you try to read the docs or search the web?

item = treectlr.GetSelection()
if treectrl.ItemHasChildren(item):
    print "Its a root node"
else:
    print "Its a child node"

Cody

···

On Fri, Jan 28, 2011 at 3:24 PM, iozk_Live <iozk117@gmail.com> wrote:

nope i using thies

  def OnRightDown(self, event):
        root = self.GetRootItem()
        pt = event.GetPosition()
        pos = self.HitTest(pt)
        item = self.ItemHasChildren(pos)

        if item:
            self.SelectItem(root)
            menupp = wx.Menu()
            menupp.Append(-1, "Child")
            self.PopupMenu(menupp)
        elif self.IsSelected(root):
            menupp = wx.Menu()
            menupp.Append(-1, "Root")
            self.PopupMenu(menupp)

in the log give this

Traceback (most recent call last):
  File "C:\Users\Inazuma\Desktop\myfolders\DVD10\python\wxpyide\sourc
\Explorer.py", line 35, in OnRightDown
    item = self.ItemHasChildren(pos)
  File "c:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx
\_controls.py", line 5377, in ItemHasChildren
    return _controls_.TreeCtrl_ItemHasChildren(*args, **kwargs)
TypeError: in method 'TreeCtrl_ItemHasChildren', expected argument 2
of type 'wxTreeItemId const &'

this muust be works isn't?
in the docs says the the HitTest Return the item slected so

Hi,

nope i using thies

def OnRightDown(self, event):
root = self.GetRootItem()
pt = event.GetPosition()
pos = self.HitTest(pt)
item = self.ItemHasChildren(pos)

   if item:
       self\.SelectItem\(root\)
       menupp = wx\.Menu\(\)
       menupp\.Append\(\-1, &quot;Child&quot;\)
       self\.PopupMenu\(menupp\)
   elif self\.IsSelected\(root\):
       menupp = wx\.Menu\(\)
       menupp\.Append\(\-1, &quot;Root&quot;\)
       self\.PopupMenu\(menupp\)

in the log give this

Traceback (most recent call last):
File "C:\Users\Inazuma\Desktop\myfolders\DVD10\python\wxpyide\sourc
\Explorer.py", line 35, in OnRightDown
item = self.ItemHasChildren(pos)
File "c:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx
\_controls.py", line 5377, in ItemHasChildren
return _controls_.TreeCtrl_ItemHasChildren(*args, **kwargs)
TypeError: in method 'TreeCtrl_ItemHasChildren', expected argument 2
of type 'wxTreeItemId const &'

this muust be works isn't?
in the docs says the the HitTest Return the item slected so

Did you check if the returned value was valid before using it?

But anyway not really sure why your trying to do it this way. If you
just want to show a menu on an item there is an easier way.

self.Bind(wx.EVT_TREE_ITEM_MENU, self.OnShowMenu)

def OnShowMenu(self, event):
    item = event.GetItem()
    menu = wx.Menu()
    if self._tree.ItemHasChildren(item):
        menu.Append(wx.NewId(), "Parent Node Menu")
    else:
        menu.Append(wx.NewId(), "Child Node Menu")
    self.PopupMenu(menu)

Cody

···

On Sat, Jan 29, 2011 at 11:41 AM, iozk_Live <iozk117@gmail.com> wrote:

$ pydoc wx.TreeCtrl.HitTest
Help on method HitTest in wx.TreeCtrl:

wx.TreeCtrl.HitTest = HitTest(*args, **kwargs) unbound wx._controls.TreeCtrl method
     HitTest(Point point) -> (item, where)

     Determine which item (if any) belongs the given point. The coordinates
     specified are relative to the client area of tree ctrl and the where return
     value is set to a bitmask of wxTREE_HITTEST_xxx constants.

···

On 1/29/11 9:41 AM, iozk_Live wrote:

Traceback (most recent call last):
   File "C:\Users\Inazuma\Desktop\myfolders\DVD10\python\wxpyide\sourc
\Explorer.py", line 35, in OnRightDown
     item = self.ItemHasChildren(pos)
   File "c:\Python26\lib\site-packages\wx-2.8-msw-ansi\wx
\_controls.py", line 5377, in ItemHasChildren
     return _controls_.TreeCtrl_ItemHasChildren(*args, **kwargs)
TypeError: in method 'TreeCtrl_ItemHasChildren', expected argument 2
of type 'wxTreeItemId const&'

this muust be works isn't?
in the docs says the the HitTest Return the item slected so

--
Robin Dunn
Software Craftsman

thanks i thing that i need a little rest of all of programming
thanks for all. I excuse me if i've done questions that can solve
easyly by my own, but lately I'm feeling without idea (and headaches
trying to solve this)

i'll back to programming in the next 2 months :slight_smile:

thanks for all...