1#!/usr/bin/env python
2# -*- mode: python; coding: utf-8; -*-
3# ---------------------------------------------------------------------------##
4#
5# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
6# Copyright (C) 2003 Mt. Hood Playing Card Co.
7# Copyright (C) 2005-2009 Skomoroh
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22# ---------------------------------------------------------------------------##
23
24from pysollib.mfxutil import KwStruct
25from pysollib.mygettext import _
26from pysollib.tile.basetilemfxdialog import BaseTileMfxDialog
27from pysollib.ui.tktile.solverdialog import BaseSolverDialog, solver_dialog
28
29from .tkwidget import PysolCombo
30
31
32# ************************************************************************
33# *
34# ************************************************************************
35
36class SolverDialog(BaseSolverDialog, BaseTileMfxDialog):
37    def _createGamesVar(self, frame, row):
38        cb = PysolCombo(frame, values=tuple(self.gamenames),
39                        selectcommand=self.gameSelected,
40                        state='readonly', width=40)
41        cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
42        return cb
43
44    def _createPresetVar(self, frame, row):
45        cb = PysolCombo(frame, values=tuple(self.presets), state='readonly',
46                        selectcommand=self._OnAssignToPreset)
47        cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
48        cb.current(0)
49        return cb
50
51    def _createShowProgressButton(self, frame):
52        return self._calcToolkit().Checkbutton(
53            frame, variable=self.progress_var,
54            text=_('Show progress'))
55
56    def initKw(self, kw):
57        strings = [_('&Start'), _('&Play'), _('&New'), 'sep', _('&Close'), ]
58        kw = KwStruct(kw,
59                      strings=strings,
60                      default=0,
61                      )
62        return self._calc_MfxDialog().initKw(self, kw)
63
64    def connectGame(self, game):
65        name = self.app.getGameTitleName(game.id)
66        if name in self.gamenames:
67            self.start_button.config(state='normal')
68            i = self.gamenames.index(name)
69            self.games_var.current(i)
70        else:
71            self.start_button.config(state='disabled')
72            self.games_var.current(0)
73        self.play_button.config(state='disabled')
74
75
76solver_dialog = solver_dialog
77
78
79def create_solver_dialog(parent, game):
80    global solver_dialog
81    try:
82        solver_dialog.top.wm_deiconify()
83        solver_dialog.top.tkraise()
84    except Exception:
85        # traceback.print_exc()
86        solver_dialog = SolverDialog(parent, game)
87