From 97f72f6df501a58eabaa0aa6f7665503651d4f7c Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Sun, 27 Nov 2016 12:06:41 -0800 Subject: [PATCH 1/2] Add ability to sort compare list --- gui/itemStats.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/gui/itemStats.py b/gui/itemStats.py index 63e4ce67d..580065f10 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -599,6 +599,13 @@ class ItemCompare(wx.Panel): self.PopulateList() self.toggleViewBtn.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleViewMode) + self.Bind(wx.EVT_LIST_COL_CLICK, self.SortCompareCols) + + def SortCompareCols(self,event): + self.Freeze() + self.paramList.ClearAll() + self.PopulateList(event.Column) + self.Thaw() def UpdateList(self): self.Freeze() @@ -620,7 +627,26 @@ class ItemCompare(wx.Panel): for i, price in enumerate(prices): self.paramList.SetStringItem(i, len(self.attrs)+1, formatAmount(price.price, 3, 3, 9, currency=True)) - def PopulateList(self): + def PopulateList(self, sort=None): + if sort: + if isinstance(sort, basestring): + # Do nothing to the string + pass + if not isinstance(sort, basestring): + try: + # Remember to reduce by 1, because the attrs array + # starts at 0 while the list has the item name as column 0. + sort = str(self.attrs.keys()[sort - 1]) + except IndexError: + # Clicked on a column that's not part of our array (price most likely) + sort = None + else: + sort = None + else: + sort = None + + self.items = sorted(self.items,key=lambda x: x.attributes[sort].value if sort in x.attributes else None) + self.paramList.InsertColumn(0, "Item") self.paramList.SetColumnWidth(0, 200) From 1854a21a50322d8f53da5869eb609a2c494babc3 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Wed, 30 Nov 2016 13:17:50 -0800 Subject: [PATCH 2/2] Clicking on the name column now reverts back to default sorting --- gui/itemStats.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/gui/itemStats.py b/gui/itemStats.py index 580065f10..d95e31839 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -628,11 +628,23 @@ class ItemCompare(wx.Panel): self.paramList.SetStringItem(i, len(self.attrs)+1, formatAmount(price.price, 3, 3, 9, currency=True)) def PopulateList(self, sort=None): - if sort: + if sort is not None: if isinstance(sort, basestring): - # Do nothing to the string - pass - if not isinstance(sort, basestring): + # A string was passed in, see if we can sort by that attribute name + try: + sort = str(self.attrs.keys()[sort]) + except IndexError: + # attribute must not exist + sort = None + elif isinstance(sort, int) and sort == 0: + try: + # Column 0 is the name. We can't sort by name (it's not an attribute), + # BUT we CAN default back to the metaLevel sorting + sort = 'metaLevel' + except IndexError: + # Clicked on a column that's not part of our array (price most likely) + sort = None + elif isinstance(sort, int): try: # Remember to reduce by 1, because the attrs array # starts at 0 while the list has the item name as column 0. @@ -640,10 +652,7 @@ class ItemCompare(wx.Panel): except IndexError: # Clicked on a column that's not part of our array (price most likely) sort = None - else: - sort = None - else: - sort = None + self.items = sorted(self.items,key=lambda x: x.attributes[sort].value if sort in x.attributes else None)