wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.31k stars 518 forks source link

HyperTreeList should no longer set wx.ListEvent m_ properties #1899

Closed JillHolliday closed 3 years ago

JillHolliday commented 3 years ago

Operating system: Windows 10 wxPython version & source: 4.1.0 and 4.1.1 PyPI Python version & source: 3.8.3 installer downloaded from Python website

Description: The Phoenix migation guide has the following about wx.ListCtrl: “In wx.ListItem and wx.ListEvent the “m_” properties are no longer public. Instead use the associated getter/setter methods or the auto-generated properties that are using them.”

When sending a wx.ListEvent though (for EVT_COMMAND_LIST_COL_DRAGGING, EVT_COMMAND_LIST_COL_BEGIN_DRAG, EVT_COMMAND_LIST_COL_END_DRAG or EVT_COMMAND_LIST_COL_CLICK), wx.lib.agw.hypertreelist.HyperTreeList still sets m_pointDrag and m_col. Presumably these settings should be replaced with calls to evt.SetColumn(…) and evt.SetPoint(…)? This causes a problem where evt.GetColumn() does not return the correct event column index (for me it returns 0 or -1), while using evt.m_col does.

To test with the code below for a small sample app, drag different column headers to resize the columns; the values of event.GetColumn() and event.m_col will be reported.

#!/usr/bin/env python
""" Test app """
import wx
import wx.lib.agw.hypertreelist as HTL

class MainFrame(wx.Frame):
    def __init__(self):

        wx.Frame.__init__(self, None, wx.ID_ANY)

        # Contains a HyperTreeList
        tree = HTL.HyperTreeList(self, wx.ID_ANY)

        for icol in range(4):
            tree.AddColumn(f"Column {icol}")
        tree.SetMainColumn(0)

        root = tree.AddRoot("The root item")

        tree.Bind(wx.EVT_LIST_COL_END_DRAG, self.OnColResize)

    def OnColResize(self, evt):
        try:
            print("event.GetColumn() = ", evt.GetColumn())
        except AttributeError:
            print("event has no GetColumn method")

        try:
            print("event.m_col = ", evt.m_col)
        except AttributeError:
            print("event has no m_col property")
        print("")

# Application loop
print(wx.version())
app = wx.App(False)
mainwin = MainFrame()
mainwin.Show(True)
app.MainLoop()
JillHolliday commented 3 years ago

I have a fix and will submit a PR.

JillHolliday commented 3 years ago

I have closed PR #1900 as I found that this issue is already covered by PR #1128 (and #1900 didn't pass all the checks either)

RobinD42 commented 3 years ago

Fixed by #1128