[wxPython] Bug? wxTreeCtrl's SelectItem fires TREE_SEL_CHANGED event twice?

We are using wxPython 2.3.2.1 with Python 2.2 on win32.

When a button is clicked, a new item is appended to the wxTreeCtrl and
selected programmatically. Very strangely, however, the SelectItem call

fires

two TREE_SEL_CHANGED events. That is, the callback function for that event

is

called twice in a row.

Which version of windows? Do you have a small sample that shows this?

Win2000, and 98.

···

=============================
from wxPython.wx import *

ID_BUTTON=10000

class MyTree(wxTreeCtrl):
    def __init__(self, parent, id, root):
        wxTreeCtrl.__init__(self, parent, id)
        self.root = self.AddRoot(str(root), -1, -1)
        EVT_TREE_SEL_CHANGED(self, self.GetId(), self.OnSelChanged)
        self.addedItems=0

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

    def OnButton(self,event):
        self.addedItems+=1
        newItem = self.AppendItem( self.root,
"foobar%d"%self.addedItems, -1, -1)
        self.SelectItem(newItem)

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, "SelectItem Test")
        split = wxSplitterWindow(self, -1)
        tree = MyTree(split, -1,"root")
        text = wxTextCtrl(split, -1, "test")
        split.SplitVertically(tree, text, 200)
        self.button = wxButton(text, ID_BUTTON, "add a new one and select it",
pos=(100,100), size=(200,50))
        EVT_BUTTON(self, ID_BUTTON, tree.OnButton)

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame()
        frame.Show(TRUE)
        self.SetTopWindow(frame)
        return TRUE

if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()

p.s. Thank you for this wonderful library. We are developing a software

with

wxPython which is more than $77K a copy.

Cool! (Hmm... maybe I should start thinking about royalties... <wink!>)

Thank you again!

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

>> We are using wxPython 2.3.2.1 with Python 2.2 on win32.
>>
>> When a button is clicked, a new item is appended to the wxTreeCtrl and
>> selected programmatically. Very strangely, however, the SelectItem call
>fires
>> two TREE_SEL_CHANGED events. That is, the callback function for that

event

>is
>> called twice in a row.
>

Apparently some versions of the MS common controls does not send the events
when a tree item is selected programatically, so wxWindows sends it. Other
versions of the common controls do send the events and so you get it twice.
I'm not sure if this can be detected at runtime, but probably not.

You may want to bring this up on wx-dev and/or enter a bug report abotu it
to see if anybody else has any ideas about it.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!