<div><font color="#990000">Hello All,</font></div>
<div><font color="#990000"></font> </div>
<div><font color="#990000">Please find the code for a simple wx.TreeCtrl code. Whenever I right click on any item in the Tree, I see the function,<font color="#ffffff"> <font style="BACKGROUND-COLOR: #3333ff">'OnSelChanged'</font></font><font style="BACKGROUND-COLOR: #3333ff"> </font>gets called twice.</font></div>
<div><font color="#990000"></font> </div>
<div><font color="#990000">What I've just done is that I've associated the function<font style="BACKGROUND-COLOR: #3333ff" color="#ffffff"> 'OnRightClick'</font> with <font style="BACKGROUND-COLOR: #3333ff" color="#ffffff">wx.EVT_TREE_ITEM_RIGHT_CLICK</font>. And in this function, I say <font style="BACKGROUND-COLOR: #3333ff" color="#ffffff">self.tree.SelectItem(evt.GetItem(),True)</font> to select the item and then so some action for right click.</font></div>
<div><font color="#990000"></font> </div>
<div><font color="#990000">Can any one help.</font></div>
<div> </div>
<div>Thanks & Regards,</div>
<div>Tarun</div>
<div> </div>
<div><strong>Please find the code in the attachment and also below:-</strong></div>
<div> </div>
<div><font face="courier new,monospace" color="#000099">import wx</font></div>
<div><font face="courier new,monospace" color="#000099">tests = ["All Tests", <br> ["Suite1",<br> "test01",<br> "test02",<br> ["suite2","test03","test04"],<br>
"test05", <br> ],<br> ["Suite3",<br> "test06", <br> "test07"<br> ],<br> ["Suite4", <br> "test08",<br> "test09"<br> ], <br>
"test10",<br> "test11",<br>]</font></div>
<div><font face="courier new,monospace" color="#000099">class TestFrame(wx.Frame):<br> def __init__(self):<br> wx.Frame.__init__(self, None, title="Simple Tree", size=(400,500))</font></div>
<div><font face="courier new,monospace" color="#000099"> # Create the tree<br> self.tree = wx.TreeCtrl(self)</font></div>
<div><font face="courier new,monospace" color="#000099"> # Add a root node <br> root = self.tree.AddRoot(tests[0])</font></div>
<div><font face="courier new,monospace" color="#000099"> # Add nodes from our data set<br> self.AddTreeNodes(root, tests, 0)</font></div>
<div><font face="courier new,monospace" color="#000099"> # Bind some interesting events<br> self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)<br> self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnRightClick, self.tree)</font></div>
<div><font face="courier new,monospace" color="#000099"> # Expand the first level<br> self.tree.Expand(root)</font></div>
<div><font face="Courier New" color="#000099"></font> </div>
<div><font face="courier new,monospace" color="#000099"> def AddTreeNodes(self, father, aTestList,count):<br> if type(aTestList) == type([]): <br> l = len(aTestList)<br> i = 0<br>
while i < l:<br> if i == 0: <br> if count ==1:<br> father = self.tree.AppendItem(father, aTestList[i])<br> else:<br> self.AddTreeNodes(father, aTestList[i], 1) <br>
i = i + 1</font></div>
<div><font face="courier new,monospace" color="#000099"> if type(aTestList) == type(""):<br> self.tree.AppendItem(father, aTestList)</font></div>
<div><font face="Courier New" color="#000099"></font> </div>
<div><font face="courier new,monospace" color="#000099"> def OnRightClick(self, evt):<br> self.tree.SelectItem(evt.GetItem(),True) <br> print 'In OnRightClick Function...',self.GetItemText(evt.GetItem())<br>
<br> def GetItemText(self, item):<br> if item:<br> return self.tree.GetItemText(item)<br> else:<br> return "" <br> <br> def OnSelChanged(self, evt): <br>
print "OnSelChanged: ", self.GetItemText(evt.GetItem())</font></div>
<div><font face="Courier New" color="#000099"></font> </div>
<div><font face="courier new,monospace" color="#000099">app = wx.PySimpleApp(redirect=True)<br>frame = TestFrame()<br>frame.Show()<br>app.MainLoop()</font></div>
<div> </div>
<div> </div>