Some issue with right click in TreeCtrl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tarun

    Some issue with right click in TreeCtrl

    Hello All,

    Please find the code for a simple wx.TreeCtrl code. Whenever I right click
    on any item in the Tree, I see the function, 'OnSelChanged' gets called
    twice.

    What I've just done is that I've associated the function 'OnRightClick' with
    wx.EVT_TREE_ITE M_RIGHT_CLICK. And in this function, I say
    self.tree.Selec tItem(evt.GetIt em(),True) to select the item and then so some
    action for right click.

    Can any one help.

    Thanks & Regards,
    Tarun

    *Please find the code in the attachment and also below:-*

    import wx
    tests = ["All Tests",
    ["Suite1",
    "test01",
    "test02",
    ["suite2","test0 3","test04"],
    "test05",
    ],
    ["Suite3",
    "test06",
    "test07"
    ],
    ["Suite4",
    "test08",
    "test09"
    ],
    "test10",
    "test11",
    ]
    class TestFrame(wx.Fr ame):
    def __init__(self):
    wx.Frame.__init __(self, None, title="Simple Tree", size=(400,500))
    # Create the tree
    self.tree = wx.TreeCtrl(sel f)
    # Add a root node
    root = self.tree.AddRo ot(tests[0])
    # Add nodes from our data set
    self.AddTreeNod es(root, tests, 0)
    # Bind some interesting events
    self.Bind(wx.EV T_TREE_SEL_CHAN GED, self.OnSelChang ed, self.tree)
    self.Bind(wx.EV T_TREE_ITEM_RIG HT_CLICK, self.OnRightCli ck,
    self.tree)
    # Expand the first level
    self.tree.Expan d(root)

    def AddTreeNodes(se lf, father, aTestList,count ):
    if type(aTestList) == type([]):
    l = len(aTestList)
    i = 0
    while i < l:
    if i == 0:
    if count ==1:
    father = self.tree.Appen dItem(father, aTestList[i])
    else:
    self.AddTreeNod es(father, aTestList[i],
    1)
    i = i + 1
    if type(aTestList) == type(""):
    self.tree.Appen dItem(father, aTestList)

    def OnRightClick(se lf, evt):
    self.tree.Selec tItem(evt.GetIt em(),True)
    print 'In OnRightClick Function...',se lf.GetItemText( evt.GetItem())

    def GetItemText(sel f, item):
    if item:
    return self.tree.GetIt emText(item)
    else:
    return ""

    def OnSelChanged(se lf, evt):
    print "OnSelChang ed: ", self.GetItemTex t(evt.GetItem() )

    app = wx.PySimpleApp( redirect=True)
    frame = TestFrame()
    frame.Show()
    app.MainLoop()

Working...