TreeCtrl, Delete and Selection - mac vs win

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

TreeCtrl, Delete and Selection - mac vs win

Charley Khan
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()



--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/63d1ee02-e9a0-4878-9817-667f8452d92e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: TreeCtrl, Delete and Selection - mac vs win

Tim Roberts
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, [hidden email]
Providenza & Boekelheide, Inc.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/d4dd7f2e-e405-c0a3-32e7-819e2b202f7e%40probo.com.
For more options, visit https://groups.google.com/d/optout.

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TreeCtrl, Delete and Selection - mac vs win

Charley Khan
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. 

On Wednesday, June 19, 2019 at 10:24:48 AM UTC-7, Tim Roberts wrote:
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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="pfo1ChWaBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/42cd0379-17b8-4529-8172-42549ec5d1d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tree-delete-select-win.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TreeCtrl, Delete and Selection - mac vs win

Robin Dunn
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

 

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/c7f1025e-e476-4fbf-ae66-13925b6c64bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.