|
27 | 27 | from collections import UserList |
28 | 28 |
|
29 | 29 | from pysollib.gamedb import GI |
| 30 | +from pysollib.images import Images, SubsampledImages |
30 | 31 | from pysollib.mfxutil import KwStruct, Struct, destruct |
31 | 32 | from pysollib.mfxutil import format_time |
32 | 33 | from pysollib.mygettext import _ |
@@ -329,12 +330,6 @@ def mDone(self, button): |
329 | 330 | if button == 0: # Ok or double click |
330 | 331 | self.gameid = self.tree.selection_key |
331 | 332 | self.tree.n_expansions = 1 # save xyview in any case |
332 | | - if button == 1: # Cancel button |
333 | | - # If the user cancels, revert any cardset change from the preview. |
334 | | - if self.app.cardset.name != self.cardset.name: |
335 | | - self.app.loadCardset(self.cardset, |
336 | | - id=self.game.gameinfo.category, |
337 | | - tocache=True, noprogress=True) |
338 | 333 | if button == 10: # Rules |
339 | 334 | doc = self.app.getGameRulesFilename(self.tree.selection_key) |
340 | 335 | if not doc: |
@@ -366,6 +361,7 @@ def __init__(self, parent, title, app, gameid, bookmark=None, **kw): |
366 | 361 | self.bookmark = bookmark |
367 | 362 | self.criteria = SearchCriteria() |
368 | 363 | self.cardset = self.app.cardset.copy() |
| 364 | + self.cardset_cache = {} |
369 | 365 | self.random = None |
370 | 366 | if self.TreeDataHolder_Class.data is None: |
371 | 367 | self.TreeDataHolder_Class.data = self.TreeData_Class(app) |
@@ -515,6 +511,7 @@ def initKw(self, kw): |
515 | 511 |
|
516 | 512 | def destroy(self): |
517 | 513 | self.deletePreview(destroy=1) |
| 514 | + self.cardset_cache.clear() |
518 | 515 | self.preview.unbind_all() |
519 | 516 | SelectGameDialog.destroy(self) |
520 | 517 |
|
@@ -809,34 +806,13 @@ def updatePreview(self, gameid, animations=10): |
809 | 806 | self.preview_app.opt.shade = 0 |
810 | 807 | # |
811 | 808 |
|
812 | | - c = self.app.cardsets_cache.get(gi.category) |
813 | | - c2 = None |
814 | | - if c: |
815 | | - c2 = c.get(gi.subcategory) |
816 | | - if not c2: |
817 | | - cardset = self.app.cardset_manager.getByName( |
| 809 | + cardset = self.app.cardset_manager.getByName( |
818 | 810 | self.app.opt.cardset[gi.category][gi.subcategory][0]) |
819 | | - self.app.loadCardset(cardset, id=gi.category, |
820 | | - tocache=True, noprogress=True) |
821 | | - c = self.app.cardsets_cache.get(gi.category) |
822 | | - if c: |
823 | | - c2 = c.get(gi.subcategory) |
824 | | - if not c2: |
825 | | - c = self.app.cardsets_cache.get(cardset.type) |
826 | | - if c: |
827 | | - c2 = c.get(cardset.subtype) |
828 | | - if c2: |
829 | | - if self.app.opt.auto_scale and self.app.opt.preview_scale: |
830 | | - self.preview_app.images = c2[1] |
831 | | - else: |
832 | | - self.preview_app.images = c2[2] |
833 | | - else: |
834 | | - if self.app.opt.auto_scale and self.app.opt.preview_scale: |
835 | | - self.preview_app.images = self.app.images |
836 | | - else: |
837 | | - self.preview_app.images = self.app.subsampled_images |
| 811 | + images, simages = self.loadCardsetForPreview(cardset) |
838 | 812 | if self.app.opt.auto_scale and self.app.opt.preview_scale: |
839 | | - self.preview_app.images.setNegative(self.app.opt.negative_bottom) |
| 813 | + self.preview_app.images = images |
| 814 | + else: |
| 815 | + self.preview_app.images = simages |
840 | 816 |
|
841 | 817 | self.preview_app.audio = None # turn off audio for initial dealing |
842 | 818 | if animations >= 0: |
@@ -887,6 +863,24 @@ def updatePreview(self, gameid, animations=10): |
887 | 863 | else: |
888 | 864 | rules_button.config(state="disabled") |
889 | 865 |
|
| 866 | + def loadCardsetForPreview(self, cardset): |
| 867 | + key = cardset.ident |
| 868 | + if self.app.cardset and self.app.cardset.ident == key: |
| 869 | + return self.app.images, self.app.subsampled_images |
| 870 | + if key in self.cardset_cache: |
| 871 | + return self.cardset_cache[key] |
| 872 | + images = Images(self.app.dataloader, cardset) |
| 873 | + images.cardset_bottoms = self.app.opt.use_cardset_bottoms |
| 874 | + images.load(self.app) |
| 875 | + images.setNegative(self.app.opt.negative_bottom) |
| 876 | + images.resize(self.app.opt.scale_x, self.app.opt.scale_y, |
| 877 | + resample=self.app.opt.resampling) |
| 878 | + simages = SubsampledImages(images) |
| 879 | + simages.setNegative(self.app.opt.negative_bottom) |
| 880 | + |
| 881 | + self.cardset_cache[key] = (images, simages) |
| 882 | + return images, simages |
| 883 | + |
890 | 884 | def updateInfo(self, gameid): |
891 | 885 | gi = self.app.gdb.get(gameid) |
892 | 886 | # info |
|
0 commit comments