From cde9bc5fb5e2177557961f2e46e38d6bd9ecf3cd Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Fri, 19 Feb 2016 23:06:16 +0200 Subject: [PATCH] menubar: move more code to the base class. --- pysollib/tile/menubar.py | 52 ++++------------------------------- pysollib/tk/menubar.py | 46 ------------------------------- pysollib/ui/tktile/menubar.py | 48 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 93 deletions(-) diff --git a/pysollib/tile/menubar.py b/pysollib/tile/menubar.py index 498ab199..1a1101eb 100644 --- a/pysollib/tile/menubar.py +++ b/pysollib/tile/menubar.py @@ -77,6 +77,11 @@ class PysolMenubarTk(PysolMenubarTkCommon): def _connect_game_solver_dialog(self, game): return connect_game_solver_dialog(game) + + def _calcWizardDialog(self): + from wizarddialog import WizardDialog + return WizardDialog + # # create the menubar # @@ -145,50 +150,3 @@ the next time you restart """)+TITLE, submenu.add_radiobutton(label=n, variable=self.tkopt.theme, value=t, command=self.mOptTheme) - def wizardDialog(self, edit=False): - from pysollib.wizardutil import write_game, reset_wizard - from wizarddialog import WizardDialog - - if edit: - reset_wizard(self.game) - else: - reset_wizard(None) - d = WizardDialog(self.top, _('Solitaire Wizard'), self.app) - if d.status == 0 and d.button == 0: - try: - if edit: - gameid = write_game(self.app, game=self.game) - else: - gameid = write_game(self.app) - except Exception, err: - if DEBUG: - traceback.print_exc() - d = MfxMessageDialog(self.top, title=_('Save game error'), - text=_(''' -Error while saving game. - -%s -''') % str(err), - bitmap='error') - return - - if SELECT_GAME_MENU: - menu = self.menupath[".menubar.select.customgames"][2] - select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM - games = map(self.app.gdb.get, - self.app.gdb.getGamesIdSortedByName()) - games = filter(select_func, games) - self.updateGamesMenu(menu, games) - - self.tkopt.gameid.set(gameid) - self._mSelectGame(gameid, force=True) - - - def mWizard(self, *event): - if self._cancelDrag(break_pause=False): return - self.wizardDialog() - - def mWizardEdit(self, *event): - if self._cancelDrag(break_pause=False): return - self.wizardDialog(edit=True) - diff --git a/pysollib/tk/menubar.py b/pysollib/tk/menubar.py index 184dfdc9..de84e4e2 100644 --- a/pysollib/tk/menubar.py +++ b/pysollib/tk/menubar.py @@ -145,49 +145,3 @@ class PysolMenubarTk(PysolMenubarTkCommon): self.game.showStackDesc() - def wizardDialog(self, edit=False): - from pysollib.wizardutil import write_game, reset_wizard - from wizarddialog import WizardDialog - - if edit: - reset_wizard(self.game) - else: - reset_wizard(None) - d = WizardDialog(self.top, _('Solitaire Wizard'), self.app) - if d.status == 0 and d.button == 0: - try: - if edit: - gameid = write_game(self.app, game=self.game) - else: - gameid = write_game(self.app) - except Exception, err: - if DEBUG: - traceback.print_exc() - d = MfxMessageDialog(self.top, title=_('Save game error'), - text=_(''' -Error while saving game. - -%s -''') % str(err), - bitmap='error') - return - if SELECT_GAME_MENU: - menu = self.menupath[".menubar.select.customgames"][2] - select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM - games = map(self.app.gdb.get, - self.app.gdb.getGamesIdSortedByName()) - games = filter(select_func, games) - self.updateGamesMenu(menu, games) - - self.tkopt.gameid.set(gameid) - self._mSelectGame(gameid, force=True) - - - def mWizard(self, *event): - if self._cancelDrag(break_pause=False): return - self.wizardDialog() - - def mWizardEdit(self, *event): - if self._cancelDrag(break_pause=False): return - self.wizardDialog(edit=True) - diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py index b74f554d..a3d15939 100644 --- a/pysollib/ui/tktile/menubar.py +++ b/pysollib/ui/tktile/menubar.py @@ -1335,3 +1335,51 @@ Unsupported game for export. if self.app.toolbar.setCompound(compound): self.game.updateStatus(player=self.app.opt.player) self.top.update_idletasks() + + def wizardDialog(self, edit=False): + from pysollib.wizardutil import write_game, reset_wizard + WizardDialog = self._calcWizardDialog() + + if edit: + reset_wizard(self.game) + else: + reset_wizard(None) + d = WizardDialog(self.top, _('Solitaire Wizard'), self.app) + if d.status == 0 and d.button == 0: + try: + if edit: + gameid = write_game(self.app, game=self.game) + else: + gameid = write_game(self.app) + except Exception, err: + if DEBUG: + traceback.print_exc() + d = MfxMessageDialog(self.top, title=_('Save game error'), + text=_(''' +Error while saving game. + +%s +''') % str(err), + bitmap='error') + return + + if SELECT_GAME_MENU: + menu = self.menupath[".menubar.select.customgames"][2] + select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM + games = map(self.app.gdb.get, + self.app.gdb.getGamesIdSortedByName()) + games = filter(select_func, games) + self.updateGamesMenu(menu, games) + + self.tkopt.gameid.set(gameid) + self._mSelectGame(gameid, force=True) + + + def mWizard(self, *event): + if self._cancelDrag(break_pause=False): return + self.wizardDialog() + + def mWizardEdit(self, *event): + if self._cancelDrag(break_pause=False): return + self.wizardDialog(edit=True) +