Ticket #2307 (closed defect: duplicate)

Opened 5 years ago

Last modified 18 months ago

wxTreeCtrl + wxTR_MULTIPLE flag: SEL_CHANGED only fires on item focus change

Reported by: jmikulasek Owned by:
Priority: high Milestone:
Component: wxMSW Version:
Keywords: wxTreeCtrl, wxTR_MULTIPLE, wxEVT_TREE_SEL_CHANGED Cc: jmikulasek, wx@…, wxscary@…, net147@…
Blocked By: Patch: no
Blocking:

Description

When you have a wx.TreeCtrl instance with
a wx.TR_MULTIPLE style the wx.EVT_TREE_SEL_CHANGED
event is not always triggered when deselecting a node
while pressing Ctrl.

It can be demonstrated in the wxPython demo. When I
uncomment the wx.TR_MULTIPLE style flag and select
several items while pressing Ctrl (so all stay selected)
and then deselect the LAST selected item (still pressing
Ctrl), nothing gets printed in the log window.
It is interesting that when you try it on leaf nodes,
the icon changes, but the event is not triggered.

I am running Windows XP, Python 2.4, wxPython 2.5.3.1
(unicode).

Change History

Changed 2 years ago by neis

Confirmed to still be a problem with wxMSW-2.8.7 (probably C++ mode, this time), see mailing list archive of May 2008, Subject: "wxTreeCtrl with the style wxTR_MULTIPLE, missing events".

Changed 2 years ago by mspacek

  • keywords wx.TreeCtrl, wx.TR_MULTIPLE, wx.EVT_TREE_ON_SEL_CHANGED added
  • status changed from new to confirmed
  • summary changed from wx.TreeCtrl and selection changed event not triggered to wx.TreeCtrl + wx.TR_MULTIPLE flag: ON_SEL_CHANGED only triggered on item focus change

I can also confirm this in wxMSW-2.8.8.0 (WinXP SP3) from wxPython. It seems that wx.EVT_TREE_ON_SEL_CHANGED/CHANGING are only fired when the currently focused tree item (with the dotted rectangle around it) changes, and not when the actual selection changes. When wx.TR_MULTIPLE flag is not set, this doesn't matter, since the currently focused item and the currently selected item are always identical. But that's not necessarily the case when wx.TR_MULTIPLE is set. I think the original report is a symptom of this: if you try deselecting the last selected item (CTRL+left click) in the tree, you change its selection, but not its focus, and hence the event doesn't fire.

To demonstrate, uncomment wx.TR_MULTIPLE in the TreeCtrl.py demo in wxPython, run it, select an item in the tree, hold down CTRL, then move up and down with the cursor keys. SEL_CHANGED events will fire on every item focus change, even though the selection hasn't changed. Now focus some event, then try (de)selecting it with CTRL+left click or CTRL+space. In this case, SEL_CHANGED won't fire.

Changed 2 years ago by mspacek

Looks like a duplicate of #626

Changed 2 years ago by mspacek

  • cc wx@… added

Changed 2 years ago by mspacek

  • keywords TreeCtrl, TR_MULTIPLE, EVT_TREE_SEL_CHANGED added; wx.TreeCtrl, wx.TR_MULTIPLE, wx.EVT_TREE_ON_SEL_CHANGED removed
  • summary changed from wx.TreeCtrl + wx.TR_MULTIPLE flag: ON_SEL_CHANGED only triggered on item focus change to wxTreeCtrl + wxTR_MULTIPLE flag: SEL_CHANGED only fires on item focus change

Whoops. EVT_TREE_ON_SEL_CHANGED above should be EVT_TREE_SEL_CHANGED

Changed 2 years ago by mspacek

  • keywords wxTreeCtrl, wxTR_MULTIPLE, wxEVT_TREE_SEL_CHANGED added; TreeCtrl, TR_MULTIPLE, EVT_TREE_SEL_CHANGED removed

#4448 regarding EVT_LEFT_DOWN is probably related

Changed 2 years ago by neis

  • cc neis removed

Changed 2 years ago by Scary

  • cc chris.s.edwards@… added

Changed 2 years ago by Scary

  • cc chris.s.edwards@… removed

Changed 23 months ago by Scary

  • cc wxscary@… added

Changed 22 months ago by Scary

I have added a patch to #9570 which attempts to fix these issues. Please give it a try and let me know what you think. I hope it is helpful. Thanks!
-Chris Edwards

Changed 21 months ago by net147

  • cc net147@… added

Changed 18 months ago by vadz

  • status changed from confirmed to closed
  • resolution set to duplicate

I think this one doesn't add anything compared to #9570 and #626 so closing it as duplicate, please reopen if I missed something specific to this bug.

Thanks!

Note: See TracTickets for help on using tickets.