New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overriden method OnCompareItems of wx.TreeCtrl not called #774

Closed
jensgoe opened this Issue Mar 1, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@jensgoe
Contributor

jensgoe commented Mar 1, 2018

Operating system: Win7
wxPython version: (4, 0, 2, 'a1')
Stock or custom build: custom (official source)
Python version: 2.7.14
Stock or custom build: stock

Description of the problem:
If i derive from wx.TreeCtrl and override OnCompareItems it is not called after calling SortChildren.
Click the right mouse button to sort the children of an item. The output of OnCompareItem is not shown out log. The items are not sorted in numerical order like expected (implemented in OnCompareItems).

import wx
print(wx.VERSION)

class MyTreeCtrl(wx.TreeCtrl):

    def __init__(self, parent):
        wx.TreeCtrl.__init__(self, parent, style=wx.TR_HAS_BUTTONS)  # | wx.TR_HIDE_ROOT)

        root = self.AddRoot("Root")
        for i in range(20):
            item = self.AppendItem(root, str(i))
            for i in range(20):
                self.AppendItem(item, str(i))

        self.Expand(root)
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)

    def OnRightDown(self, event):
        pt = event.GetPosition();
        item, flags = self.HitTest(pt)
        if item:
            print("OnRightClick")
            self.SortChildren(item)

    def OnCompareItems(self, item1, item2):
        print('OnCompareItems')
        t1 = int(self.GetItemText(item1))
        t2 = int(self.GetItemText(item2))

        if t1 < t2: return -1
        if t1 == t2: return 0
        return 1

class MyApp(wx.App):

    def OnInit(self):
        f = wx.Frame(None)
        tc = MyTreeCtrl(f)
        f.Show()
        self.SetTopWindow(f)
        return True

if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()
@jensgoe

This comment has been minimized.

Contributor

jensgoe commented Mar 8, 2018

i fixed this by modifying the sip generated cpp code like in the attached patch. but i don't know how to tweak this modification within the etg scripts.
0001-modified-generated_patch.txt

@RobinD42 RobinD42 self-assigned this Mar 9, 2018

@RobinD42

This comment has been minimized.

Member

RobinD42 commented Mar 9, 2018

Unfortunately there isn't a good way to inject code into that class so I think I'm going to have to be more creative...

@jensgoe

This comment has been minimized.

Contributor

jensgoe commented Mar 12, 2018

Are you planning to merge this into the 4.0.x branch?

@RobinD42

This comment has been minimized.

Member

RobinD42 commented Mar 12, 2018

It already has been.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment