Add ability to sort compare list
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user