TreeCtrl, Delete and Selection - mac vs win

70 views
Skip to first unread message

Charley Khan

unread,
Jun 19, 2019, 10:57:42 AM6/19/19
to wxPython-users
TreeCtrl with handler to print selection changes; button to delete current selection.
Works as expected on MacOS (10.12.6): deleting a node generates selection change.
On Windows (tried Win 7 and Win 10) it looks correct, and GetSelection() reports correct new value, but no change event generated.
wxPython 4.0.0b2
Is this an issue with native control, wxwidgets, wxpython, or my code?
Thanks so much!
-ck

#!/usr/bin/python

# why don't I see selection event after delete on Win?

import wx
import sys

app = wx.App()
frame = wx.Frame(None, title='tree test')

sizer = wx.BoxSizer(wx.VERTICAL)
frame.SetSizer(sizer)

# ------------------------------------------------------------
# Tree with some nodes; print out selection changes

tree = 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 node

button = 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 selected
    tree.SetFocus()
button.Bind(wx.EVT_BUTTON, onDelete)


frame.Show()
app.MainLoop()



Tim Roberts

unread,
Jun 19, 2019, 1:24:48 PM6/19/19
to wxpytho...@googlegroups.com
Charley Khan wrote:
> TreeCtrl with handler to print selection changes; button to delete
> current selection.
> Works as expected on MacOS (10.12.6): deleting a node generates
> selection change.
> On Windows (tried Win 7 and Win 10) it looks correct, and
> GetSelection() reports correct new value, but no change event generated.
> wxPython 4.0.0b2
> Is this an issue with native control, wxwidgets, wxpython, or my code?

Interesting.  It works with wxPython 2.8.12 on Windows, but not wxPython
4.0.4.

There has always been a debate over whether changes triggered by the
application should fire events.  Intuitively, it seems like this should
fire an event, but it is debatable.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.


Charley Khan

unread,
Jun 19, 2019, 7:50:26 PM6/19/19
to wxPython-users
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. 
tree-delete-select-win.py

Robin Dunn

unread,
Jun 19, 2019, 9:31:15 PM6/19/19
to wxPython-users
On Wednesday, June 19, 2019 at 4:50:26 PM UTC-7, Charley Khan wrote:
Thanks for trying it out. Given that the behavior changed even between versions of wxPython - should this be filed as a bug?

It was okay the way you did it before. As long as the code in the message is formatted properly so the lines don't wrap, and you don't lose leading whitespace, it is fine. I think the groups software and/or email applications have figured things out there now.
 

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. 


It looks like it's already been fixed in the wxWidgets master branch (which is what will be used in wxPython 4.1), with this change: https://github.com/wxWidgets/wxWidgets/commit/ae845a045e7eeebf529af86939bb8f6f0d5f1a34

It might be able to be back-ported to wx 3.0, but I don't know if there will be another wxPython 4.0.x release. Probably not, if 4.1 progresses to a release in the next couple months or so.

--
Robin

 
Reply all
Reply to author
Forward
0 new messages