By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,496 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,496 IT Pros & Developers. It's quick & easy.

Some issue with right click in TreeCtrl

P: n/a
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_ITEM_RIGHT_CLICK. And in this function, I say
self.tree.SelectItem(evt.GetItem(),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","test03","test04"],
"test05",
],
["Suite3",
"test06",
"test07"
],
["Suite4",
"test08",
"test09"
],
"test10",
"test11",
]
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Simple Tree", size=(400,500))
# Create the tree
self.tree = wx.TreeCtrl(self)
# Add a root node
root = self.tree.AddRoot(tests[0])
# Add nodes from our data set
self.AddTreeNodes(root, tests, 0)
# Bind some interesting events
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnRightClick,
self.tree)
# Expand the first level
self.tree.Expand(root)

def AddTreeNodes(self, father, aTestList,count):
if type(aTestList) == type([]):
l = len(aTestList)
i = 0
while i < l:
if i == 0:
if count ==1:
father = self.tree.AppendItem(father, aTestList[i])
else:
self.AddTreeNodes(father, aTestList[i],
1)
i = i + 1
if type(aTestList) == type(""):
self.tree.AppendItem(father, aTestList)

def OnRightClick(self, evt):
self.tree.SelectItem(evt.GetItem(),True)
print 'In OnRightClick Function...',self.GetItemText(evt.GetItem())

def GetItemText(self, item):
if item:
return self.tree.GetItemText(item)
else:
return ""

def OnSelChanged(self, evt):
print "OnSelChanged: ", self.GetItemText(evt.GetItem())

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

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.