Sort a wx.lib.agw.HyperTreeList with wx.lib.mixins.listctrl.ColumnSorterMixin ?

Hello,
I am using a wx.lib.agw.HyperTreeListCtrl, and i would like to sort the list by clicking on the header of one of its columns.
I know of wx.lib.mixins.listctrl.ColumnSorterMixin, which is made to work with wx.ListCtrl.
My question is : is it worth for me to look into it, or is it just impossible to make them work together ?
Thank you !
PS: I discovered the ObjectListView**,** which seems nice (includes sorting for ex.) but doesn’t have a tree display.

I don't have a solution Tom, but I am interested in doing the exact same thing.

If find a solution, I sure would appreciate you posting back here.

g.

Hello list,

I have gone another way in order to sort the items in my HyperTreeList.
I try to override the method OnCompareItems of my subclass of HyperTreeList, so that the method SortChildren will sort the items the way i want.
However i was not successful until now, so built a small example of what i have that is not working (see below).
My problem must be that i don’t understand overriding well enough, so can someone point me in the right direction ?

The method OnCompareItems() is not even called.

Cheers.

Thomas.

···

Code example

import wx
import wx.lib.agw.hypertreelist as HTL

class mainWindow(wx.Frame):
def init(self, parent, id, title):
wx.Frame.init(self,parent,wx.ID_ANY, title=‘’, size=(800,600), pos=(200,100), style=wx.DEFAULT_FRAME_STYLE)

    self.tree = HyperTreeList(self, wx.ID_ANY)
   
    root = self.tree.AddRoot("")
   
    itemA = self.tree.AppendItem(root, 'A')
    self.tree.SetItemText(itemA, '1000', 1)
   
    itemB = self.tree.AppendItem(root, 'B')
    self.tree.SetItemText(itemB, '10', 1)
   
    itemC = self.tree.AppendItem(root, 'C')
    self.tree.SetItemText(itemC, '100', 1)
   
    self.tree.SetMainColumn(0)
    self.tree.ExpandAll()
   
    self.tree.SortChildren(root)

class HyperTreeList(HTL.HyperTreeList):
def init(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.SUNKEN_BORDER | wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT | wx.TR_FULL_ROW_HIGHLIGHT, log=None):
HTL.HyperTreeList.init(self, parent, id, pos, size, style)

    self.AddColumn("Name")
    self.AddColumn("Rank")

#-------------------------------------#
# Im trying to override this function #
#-------------------------------------#

def OnCompareItems(self, item1, item2):
    print "Comparing now!"
    return cmp(self.GetItemText(item1, 1), self.GetItemText(item2, 1))

if name == “main”:
app=wx.PySimpleApp()
frame=mainWindow(None, wx.ID_ANY, “GUI”).Show()
app.MainLoop()

On Tue, Apr 21, 2009 at 11:52 AM, geoff imageguy1206@gmail.com wrote:

I don’t have a solution Tom, but I am interested in doing the exact same thing.

If find a solution, I sure would appreciate you posting back here.

g.


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

I have gone another way in order to sort the items in my HyperTreeList.
I try to override the method OnCompareItems of my subclass of HyperTreeList,
so that the method SortChildren will sort the items the way i want.
However i was not successful until now, so built a small example of what i
have that is not working (see below).
My problem must be that i don't understand overriding well enough, so can
someone point me in the right direction ?

The method OnCompareItems() is not even called.

...

        self.tree.SortChildren(root)

...

    def OnCompareItems(self, item1, item2):
        print "Comparing now!"
        return cmp(self.GetItemText(item1, 1), self.GetItemText(item2, 1))

This is somewhat counterintuitive -- or rather to be taken
literally. SortChildren sorts *children*, not Grandchildren
or the like...

So, in effect, you need to traverse the tree and
SortChildren() manually on each node having children :frowning:

At least that works for me with a standard tree control.

Karsten

···

On Wed, Apr 22, 2009 at 03:46:54PM -0400, Thomas Coudrat wrote:
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Thanks for your reply Karsten, but sorting all the children of root
was actually what i was trying to do. Then the children of those
(grand-children of the root) would follow their parent, which are being
sorted.

Ok i found out what was the problem, and i will explain it with my limited vocabulary!
Overriding was done without a problem on the wx.gizmos.TreeListCtrl (for example), so it is just that the HyperTreeList does not allow overriding.

Actually there was another post about this by Frank Niessink who proposed a way to override the functions of HyperTreeList (i think).

So sorting the children of root in a HyperTreeList is not possible through overriding OnCompareItems(), and calling SortChildren() (Yet!).
Can anybody give me an other option for sorting a HyperTreeList ?

Thanks in advance,

Thomas.

···

On Thu, Apr 23, 2009 at 4:57 AM, Karsten Hilbert Karsten.Hilbert@gmx.net wrote:

On Wed, Apr 22, 2009 at 03:46:54PM -0400, Thomas Coudrat wrote:

I have gone another way in order to sort the items in my HyperTreeList.

I try to override the method OnCompareItems of my subclass of HyperTreeList,

so that the method SortChildren will sort the items the way i want.

However i was not successful until now, so built a small example of what i

have that is not working (see below).

My problem must be that i don’t understand overriding well enough, so can

someone point me in the right direction ?

The method OnCompareItems() is not even called.

    self.tree.SortChildren(root)

def OnCompareItems(self, item1, item2):
    print "Comparing now!"
    return cmp(self.GetItemText(item1, 1), self.GetItemText(item2, 1))

This is somewhat counterintuitive – or rather to be taken

literally. SortChildren sorts children, not Grandchildren

or the like…

So, in effect, you need to traverse the tree and

SortChildren() manually on each node having children :frowning:

At least that works for me with a standard tree control.

Karsten

GPG key ID E4071346 @ wwwkeys.pgp.net

E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users