Hi!
I have one strange problem. In wxTreeCtrl, if SelectItem is called right
after AppendItem, the SelectionChanged event gets fired twice. Already on
second day of tracing this problem, but no success so far.
Before reducing the application to bare minimum, SelectionChanged event
also was fired twice when left-clicking tree items with mouse, even the
ones already selected. Now this only happens after SelectItem() call.
Environment: wxPython 2.4.0.7u, Python 2.2.2, Windows2000 Professional SP2
The code to repeat the problem is given below. It messages prints to a
file whenever a node is appended or selection is changed.
Peteris underscore Martinsons reachable at exigengroup dot lv
···
#-------------------------------
from wxPython.wx import *
import time
class MainWindow(wxFrame):
def __init__(self):
wxFrame.__init__(self, None, -1, "frame", size=wxSize(400, 300),
style=wxDEFAULT_FRAME_STYLE)
self.CreateToolBar(style=wxTB_FLAT)
self._init_ToolBar(self.GetToolBar())
style =
wxNO_3D|wxTR_HAS_BUTTONS|wxTR_FULL_ROW_HIGHLIGHT|wxTR_HIDE_ROOT|wxTR_ROW_LINES|wxTR_LINES_AT_ROOT
self.t1 =t1= wxTreeCtrl(self, 7003, style=style)
EVT_MENU(self, 7004, self.OnAdd)
EVT_TREE_SEL_CHANGED(self.t1, self.t1.GetId(),
self.OnSelectionChanged)
def _init_ToolBar(self, bar):
bar.SetToolBitmapSize(wxSize(32, 32))
bmp=wxEmptyBitmap(32, 32, depth = -1)
bar.AddSeparator()
bar.AddTool(id=7004, bitmap=bmp, pushedBitmap=wxNullBitmap)#
bar.Realize()
def OnAdd(self, event):
im = self.AddNode()
print "Add node"
# Next line generates two Selection Change events
self.t1.SelectItem(im)
def AddNode(self):
parent = self.t1.GetRootItem()
newitem = self.t1.AppendItem(parent, "nodename")
return newitem
def OnSelectionChanged(self, event):
print "---- selection change event -----"
class TheApp(wxApp):
def OnInit(self):
self.main = MainWindow()
self.main.Show()
self.SetTopWindow(self.main)
return True
if __name__ == '__main__':
application = TheApp(true, "wxout.txt")
application.MainLoop()
#-------------------------------