diff --git a/gui/itemStats.py b/gui/itemStats.py index d95e31839..35fb48355 100644 --- a/gui/itemStats.py +++ b/gui/itemStats.py @@ -545,6 +545,8 @@ class ItemCompare(wx.Panel): self.toggleView = 1 self.stuff = stuff + self.currentSort = None + self.sortReverse = False self.item = item self.items = sorted(items, key=lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else None) self.attrs = {} @@ -628,33 +630,28 @@ 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 is not None and self.currentSort == sort: + self.sortReverse = not self.sortReverse + else: + self.currentSort = sort + self.sortReverse = False + if sort is not None: - if 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): + if sort == 0: # Name sort + func = lambda x: x.name + else: 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]) + attr = str(self.attrs.keys()[sort - 1]) + func = lambda x: x.attributes[attr].value if attr in x.attributes else None except IndexError: # Clicked on a column that's not part of our array (price most likely) - sort = None + self.sortReverse = False + func = lambda x: x.attributes['metaLevel'].value if 'metaLevel' in x.attributes else None - - self.items = sorted(self.items,key=lambda x: x.attributes[sort].value if sort in x.attributes else None) + self.items = sorted(self.items, key=func, reverse=self.sortReverse) self.paramList.InsertColumn(0, "Item") self.paramList.SetColumnWidth(0, 200)