#!/usr/bin/python# why don't I see selection event after delete on Win?import wximport sysapp = wx.App()frame = wx.Frame(None, title='tree test')sizer = wx.BoxSizer(wx.VERTICAL)frame.SetSizer(sizer)# ------------------------------------------------------------# Tree with some nodes; print out selection changestree = wx.TreeCtrl(frame)sizer.Add(tree, proportion=1, flag=wx.EXPAND)rootTr= tree.AddRoot("Root")for i in range(10):tree.AppendItem(rootTr, "node %d" % i)tree.ExpandAllChildren(rootTr)def onSelChanged(event):print "selchanged!" + tree.GetItemText(event.GetItem())sys.stdout.flush()tree.Bind(wx.EVT_TREE_SEL_CHANGED, onSelChanged)# ------------------------------------------------------------# delete button deletes current nodebutton = wx.Button(frame, label="delete")sizer.Add(button)def onDelete(event):tree.Delete(tree.GetSelection())# seems necessary on windows, or I won't see anything selectedtree.SetFocus()button.Bind(wx.EVT_BUTTON, onDelete)frame.Show()app.MainLoop()
Thanks for trying it out. Given that the behavior changed even between versions of wxPython - should this be filed as a bug?
Sorry I totally missed the guideline about attaching code instead of inlining - same snippet attached here, too.My next question is -- say this is just a quirk of the platform I need to work around -- what is the best way to do that?I can't just call tree.SelectItem() -- it does nothing, because as noted below, the selection is in fact correctly set, so that call is a no-op.Is it on me to call my handler directly for Windows in this case?Suggestions appreciated.