From 080b0043e331414b09ba73a6ddfc9b28aff4e3eb Mon Sep 17 00:00:00 2001 From: Joe R Date: Sun, 13 Jun 2021 19:08:14 -0400 Subject: [PATCH] Updated compatible cardset check to run when selecting cardsets. --- pysollib/app.py | 62 ++++++++++++++++++---------------- pysollib/tile/selectcardset.py | 13 +++++++ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/pysollib/app.py b/pysollib/app.py index 405eb76e..068c295b 100644 --- a/pysollib/app.py +++ b/pysollib/app.py @@ -773,56 +773,60 @@ class Application: t0 = t1 = "Unknown" return t0, t1 - def getCompatibleCardset(self, gi, cs): + def getCompatibleCardset(self, gi, cs, trychange=True): if gi is None: - return cs, 1 + return cs, 1, None + t = self.checkCompatibleCardsetType(gi, cs) # try current if cs: - t = self.checkCompatibleCardsetType(gi, cs) if not t[1]: - return cs, 1 - # try by gameid / category - for key, flag in (((1, gi.id), 8), (gi.category, 4)): - c = self.opt.cardset.get(key) - if not c or len(c) != 2: - continue - cs = self.cardset_manager.getByName(c[0]) - if not cs: - continue - t = self.checkCompatibleCardsetType(gi, cs) - if not t[1]: - cs.updateCardback(backname=c[1]) - return cs, flag + return cs, 1, t + if trychange: + # try by gameid / category + for key, flag in (((1, gi.id), 8), (gi.category, 4)): + c = self.opt.cardset.get(key) + if not c or len(c) != 2: + continue + cs = self.cardset_manager.getByName(c[0]) + if not cs: + continue + t = self.checkCompatibleCardsetType(gi, cs) + if not t[1]: + cs.updateCardback(backname=c[1]) + return cs, flag, t # ask - return None, 0 + return None, 0, t def requestCompatibleCardsetType(self, id): gi = self.getGameInfo(id) # - cs, cs_update_flag = self.getCompatibleCardset(gi, self.cardset) + cs, cs_update_flag, t = self.getCompatibleCardset(gi, self.cardset) if cs is self.cardset: return 0 if cs is not None: self.loadCardset(cs, update=1) return 1 - # - t = self.checkCompatibleCardsetType(gi, self.cardset) - MfxMessageDialog( - self.top, title=_("Incompatible cardset"), - bitmap="warning", - text=_('''The currently selected cardset %(cardset)s -is not compatible with the game -%(game)s -Please select a %(correct_type)s type cardset. -''') % {'cardset': self.cardset.name, 'game': gi.name, 'correct_type': t[0]}, - strings=(_("&OK"),), default=0) + self.requestCompatibleCardsetTypeDialog(self.cardset, gi, t) + cs = self.__selectCardsetDialog(t) if cs is None: return -1 self.loadCardset(cs, id=id) return 1 + def requestCompatibleCardsetTypeDialog(self, cardset, gi, t): + MfxMessageDialog( + self.top, title=_("Incompatible cardset"), + bitmap="warning", + text=_('''The currently selected cardset %(cardset)s + is not compatible with the game + %(game)s + + Please select a %(correct_type)s type cardset. + ''') % {'cardset': cardset.name, 'game': gi.name, + 'correct_type': t[0]}, strings=(_("&OK"),), default=0) + def selectCardset(self, title, key): d = SelectCardsetDialogWithPreview( self.top, title=title, app=self, diff --git a/pysollib/tile/selectcardset.py b/pysollib/tile/selectcardset.py index 9e0d197e..4b905e5b 100644 --- a/pysollib/tile/selectcardset.py +++ b/pysollib/tile/selectcardset.py @@ -354,6 +354,19 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.key = self.tree.selection_key self.tree.n_expansions = 1 # save xyview in any case + if button == 0: + cardset = self.app.cardset_manager.get(self.key) + if self.app.game is not None: + gi = self.app.getGameInfo(self.app.game.id) + else: + gi = self.app.getGameInfo(self.app.nextgame.id) + cs, cs_update_flag, t = \ + self.app.getCompatibleCardset(gi, cardset, trychange=False) + + if cs is None: + self.app.requestCompatibleCardsetTypeDialog(cardset, gi, t) + return + # save the values try: self.cardset_values = self.x_offset.get(), self.y_offset.get()