MCPcopy Create free account
hub / github.com/pyfa-org/Pyfa / PopulateList

Method PopulateList

gui/builtinItemStatsViews/itemCompare.py:135–205  ·  view source on GitHub ↗
(self, sort=None)

Source from the content-addressed store, hash-verified

133 self.paramList.SetItem(i, len(self.attrs) + 1, formatAmount(price.value, 3, 3, 9, currency=True))
134
135 def PopulateList(self, sort=None):
136
137 if sort is not None and self.currentSort == sort:
138 self.sortReverse = not self.sortReverse
139 else:
140 self.currentSort = sort
141 self.sortReverse = False
142
143 if sort is not None:
144 if sort == 0: # Name sort
145 func = lambda _val: _val.name
146 else:
147 try:
148 # Remember to reduce by 1, because the attrs array
149 # starts at 0 while the list has the item name as column 0.
150 attr = str(list(self.attrs.keys())[sort - 1])
151 func = lambda _val: _val.attributes[attr].value if attr in _val.attributes else 0.0
152 # Clicked on a column that's not part of our array (price most likely)
153 except IndexError:
154 # Price
155 if sort == len(self.attrs) + 1:
156 func = lambda i: i.price.price if i.price.price != 0 else float("Inf")
157 # Something else
158 else:
159 self.sortReverse = False
160 func = defaultSort
161
162 self.items = sorted(self.items, key=func, reverse=self.sortReverse)
163
164 self.paramList.InsertColumn(0, _t("Item"))
165 self.paramList.SetColumnWidth(0, 200)
166
167 for i, attr in enumerate(self.attrs.keys()):
168 name = self.attrs[attr].displayName if self.attrs[attr].displayName else attr
169 self.paramList.InsertColumn(i + 1, name)
170 self.paramList.SetColumnWidth(i + 1, 120)
171
172 self.paramList.InsertColumn(len(self.attrs) + 1, _t("Price"))
173 self.paramList.SetColumnWidth(len(self.attrs) + 1, 60)
174
175 toHighlight = []
176
177 for item in self.items:
178 i = self.paramList.InsertItem(self.paramList.GetItemCount(), item.name)
179 for x, attr in enumerate(self.attrs.keys()):
180 if attr in item.attributes:
181 info = self.attrs[attr]
182 value = item.attributes[attr].value
183 if self.toggleView != 1:
184 valueUnit = str(value)
185 elif info and info.unit and self.toggleView == 1:
186 valueUnit = self.TranslateValueUnit(value, info.unit.displayName, info.unit.name)
187 else:
188 valueUnit = formatAmount(value, 3, 0, 0)
189
190 self.paramList.SetItem(i, x + 1, valueUnit)
191
192 # Add prices

Callers 4

__init__Method · 0.95
HighlightRowMethod · 0.95
SortCompareColsMethod · 0.95
UpdateListMethod · 0.95

Calls 6

TranslateValueUnitMethod · 0.95
formatAmountFunction · 0.90
SetBackgroundColourMethod · 0.80
_tFunction · 0.50
keysMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected