Skip to content

Commit 06fc775

Browse files
UtumnoSharlikran
authored andcommitted
Cache images it does speedup loading them
(although that's probably due to my using balt.Image)
1 parent 5fb3c7e commit 06fc775

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

Mopy/bash/basher/gui_fomod.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def __init__(self, parent, page):
262262

263263
sizer_extra = wx.GridSizer(2, 1, 5, 5)
264264
self.bmp_item = balt.Picture(self, 0, 0, background=None)
265+
self._img_cache = {} # creating images can be really expensive
265266
self.text_item = balt.RoTextCtrl(self, autotooltip=False)
266267
sizer_extra.Add(self.bmp_item, 1, wx.EXPAND | wx.ALL)
267268
sizer_extra.Add(self.text_item, 1, wx.EXPAND | wx.ALL)
@@ -370,11 +371,12 @@ def on_hover(self, event):
370371

371372
self.bmp_item.Freeze()
372373
img = self.parent.archive_path.join(option.image)
373-
if img.isfile():
374-
image = wx.Bitmap(img.s)
375-
self.bmp_item.SetBitmap(image)
376-
else:
377-
self.bmp_item.SetBitmap(None)
374+
try:
375+
image = self._img_cache[img]
376+
except KeyError:
377+
image = self._img_cache.setdefault(img, (
378+
img.isfile() and balt.Image(img.s).GetBitmap()) or None)
379+
self.bmp_item.SetBitmap(image)
378380
self.bmp_item.Thaw()
379381
self.text_item.SetValue(
380382
self._option_type_string[option.type] + option.description)

Mopy/bash/fomod.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# https://github.com/wrye-bash
2222
#
2323
# =============================================================================
24-
24+
"""TODO: notes on the data model here"""
2525

2626
__author__ = "Ganda"
2727

@@ -327,14 +327,13 @@ def _test_conditions(self, conditions):
327327
raise FailedCondition("\n".join(failed))
328328

329329
@staticmethod
330-
def _order_list(unordered_list, order):
330+
def _order_list(unordered_list, order, _valid_values=frozenset(
331+
("Explicit", "Ascending", "Descending"))):
331332
if order == "Explicit":
332333
return unordered_list
333-
elif order == "Ascending":
334-
return sorted(unordered_list, key=lambda x: x.name)
335-
elif order == "Descending":
336-
return sorted(unordered_list, key=lambda x: x.name, reverse=True)
337-
else:
334+
if order not in _valid_values:
338335
raise ValueError(
339336
"Arguments are incorrect: {}, {}".format(unordered_list, order)
340337
)
338+
return sorted(unordered_list, key=lambda x: x.name,
339+
reverse=order == "Descending")

0 commit comments

Comments
 (0)