diff --git a/pysollib/ui/tktile/__init__.py b/pysollib/ui/tktile/__init__.py
index 14ff6207..4f51198f 100644
--- a/pysollib/ui/tktile/__init__.py
+++ b/pysollib/ui/tktile/__init__.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,4 +19,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
diff --git a/pysollib/ui/tktile/card.py b/pysollib/ui/tktile/card.py
index ac803ffc..43dc5816 100644
--- a/pysollib/ui/tktile/card.py
+++ b/pysollib/ui/tktile/card.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
__all__ = ['Card']
@@ -42,12 +42,12 @@ class _HideableCard(AbstractCard):
return
self.item.config(state="hidden")
self.hide_stack = stack
- ##print "hide:", self.id, self.item.coords()
+ # print "hide:", self.id, self.item.coords()
def unhide(self):
if self.hide_stack is None:
return 0
- ##print "unhide:", self.id, self.item.coords()
+ # print "unhide:", self.id, self.item.coords()
self.item.config(state="normal")
self.hide_stack = None
return 1
@@ -70,9 +70,10 @@ class _OneImageCard(_HideableCard):
self._back_image = game.getCardBackImage(deck, suit, rank)
self._shade_image = game.getCardShadeImage()
self._active_image = self._back_image
- self.item = MfxCanvasImage(game.canvas, self.x, self.y, image=self._active_image, anchor="nw")
+ self.item = MfxCanvasImage(
+ game.canvas, self.x, self.y, image=self._active_image, anchor="nw")
self.shade_item = None
- ##self._setImage = self.item.config
+ # self._setImage = self.item.config
def _setImage(self, image):
if image is not self._active_image:
@@ -181,8 +182,12 @@ class _TwoImageCard(_HideableCard):
def __init__(self, id, deck, suit, rank, game, x=0, y=0):
_HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
self.item = MfxCanvasGroup(game.canvas)
- self.__face = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardFaceImage(deck, suit, rank), anchor="nw")
- self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardBackImage(deck, suit, rank), anchor="nw")
+ self.__face = MfxCanvasImage(
+ game.canvas, self.x, self.y, image=game.getCardFaceImage(
+ deck, suit, rank), anchor="nw")
+ self.__back = MfxCanvasImage(
+ game.canvas, self.x, self.y, image=game.getCardBackImage(
+ deck, suit, rank), anchor="nw")
self.__face.addtag(self.item)
self.__back.addtag(self.item)
@@ -216,15 +221,19 @@ class _TwoImageCardWithHideItem(_HideableCard):
def __init__(self, id, deck, suit, rank, game, x=0, y=0):
_HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
self.item = MfxCanvasGroup(game.canvas)
- self.__face = MfxCanvasImage(game.canvas, self.x, self.y + 11000, image=game.getCardFaceImage(deck, suit, rank), anchor="nw")
- self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardBackImage(deck, suit, rank), anchor="nw")
+ self.__face = MfxCanvasImage(
+ game.canvas, self.x, self.y + 11000, image=game.getCardFaceImage(
+ deck, suit, rank), anchor="nw")
+ self.__back = MfxCanvasImage(
+ game.canvas, self.x, self.y, image=game.getCardBackImage(
+ deck, suit, rank), anchor="nw")
self.__face.addtag(self.item)
self.__back.addtag(self.item)
def showFace(self, unhide=1):
if not self.face_up:
self.__back.move(0, 10000)
- ##self.__face.tkraise()
+ # self.__face.tkraise()
self.__face.move(0, -11000)
self.tkraise(unhide)
self.face_up = 1
@@ -232,7 +241,7 @@ class _TwoImageCardWithHideItem(_HideableCard):
def showBack(self, unhide=1):
if self.face_up:
self.__face.move(0, 11000)
- ##self.__back.tkraise()
+ # self.__back.tkraise()
self.__back.move(0, -10000)
self.tkraise(unhide)
self.face_up = 0
@@ -241,10 +250,8 @@ class _TwoImageCardWithHideItem(_HideableCard):
self.__back.config(image=image)
-
# choose the implementation
Card = _TwoImageCardWithHideItem
Card = _TwoImageCard
Card = _OneImageCardWithHideByConfig
Card = _OneImageCard
-
diff --git a/pysollib/ui/tktile/colorsdialog.py b/pysollib/ui/tktile/colorsdialog.py
index 95d47ee4..c0abb295 100644
--- a/pysollib/ui/tktile/colorsdialog.py
+++ b/pysollib/ui/tktile/colorsdialog.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,25 +19,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
-
-__all__ = ['ColorsDialog']
+# ---------------------------------------------------------------------------
# imports
import Tkinter
from tkColorChooser import askcolor
# PySol imports
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
from pysollib.mfxutil import KwStruct
-# Toolkit imports
-from pysollib.tk.tkwidget import MfxDialog
-
# ************************************************************************
# *
# ************************************************************************
+
class BaseColorsDialog:
def _calcFrame(self):
return self._calcToolkit().Frame
@@ -50,7 +46,8 @@ class BaseColorsDialog:
def __init__(self, parent, title, app, **kw):
kw = self.initKw(kw)
- self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
+ self._calc_MfxDialog().__init__(
+ self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
@@ -85,14 +82,16 @@ class BaseColorsDialog:
(_('Highlight same rank 2:'), self.samerank_2_var),
(_('Hint arrow:'), self.hintarrow_var),
(_('Highlight not matching:'), self.not_matching_var),
- ):
- self._calcLabel()(frame, text=title, anchor='w',
- ).grid(row=row, column=0, sticky='we')
+ ):
+ self._calcLabel()(
+ frame, text=title, anchor='w',).grid(
+ row=row, column=0, sticky='we')
l = Tkinter.Label(frame, width=10, height=2,
bg=var.get(), textvariable=var)
l.grid(row=row, column=1, padx=5)
- b = self._calcButton()(frame, text=_('Change...'), width=10,
- command=lambda l=l: self.selectColor(l))
+ b = self._calcButton()(
+ frame, text=_('Change...'), width=10,
+ command=lambda l=l: self.selectColor(l))
b.grid(row=row, column=2)
row += 1
#
@@ -117,7 +116,7 @@ class BaseColorsDialog:
else:
if c and c[1]:
label.configure(bg=c[1])
- #label.configure(text=c[1]) # don't work
+ # label.configure(text=c[1]) # don't work
label.setvar(label.cget('textvariable'), c[1])
def initKw(self, kw):
@@ -126,7 +125,3 @@ class BaseColorsDialog:
default=0,
)
return self._calc_MfxDialog().initKw(self, kw)
-
-
-
-
diff --git a/pysollib/ui/tktile/edittextdialog.py b/pysollib/ui/tktile/edittextdialog.py
index 7dfc1fb3..432e8ce4 100644
--- a/pysollib/ui/tktile/edittextdialog.py
+++ b/pysollib/ui/tktile/edittextdialog.py
@@ -1,19 +1,21 @@
import Tkinter
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
from pysollib.mfxutil import KwStruct
+
class BaseEditTextDialog:
def __init__(self, parent, title, text, **kw):
kw = self.initKw(kw)
- self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
+ self._calc_MfxDialog().__init__(
+ self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.text_w = Tkinter.Text(top_frame, bd=1, relief="sunken",
wrap="word", width=64, height=16)
self.text_w.pack(side='left', fill="both", expand=True)
- ###self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady)
+ # self.text_w.pack(side='top', padx=kw.padx, pady=kw.pady)
vbar = self._calcToolkit().Scrollbar(top_frame)
vbar.pack(side='right', fill='y')
self.text_w["yscrollcommand"] = vbar.set
@@ -49,5 +51,3 @@ class BaseEditTextDialog:
def mCancel(self, *event): # ignore
pass
-
-
diff --git a/pysollib/ui/tktile/findcarddialog.py b/pysollib/ui/tktile/findcarddialog.py
index b5cf454b..e97acb88 100644
--- a/pysollib/ui/tktile/findcarddialog.py
+++ b/pysollib/ui/tktile/findcarddialog.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
__all__ = ['create_find_card_dialog',
'connect_game_find_card_dialog',
@@ -31,12 +31,13 @@ import os
import Tkinter
# PySol imports
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
# Toolkit imports
from pysollib.ui.tktile.tkutil import after, after_cancel
from pysollib.ui.tktile.tkutil import bind, unbind_destroy, makeImage
-from pysollib.ui.tktile.tkcanvas import MfxCanvas, MfxCanvasGroup, MfxCanvasImage, MfxCanvasRectangle
+from pysollib.ui.tktile.tkcanvas import MfxCanvas, MfxCanvasGroup, \
+ MfxCanvasImage, MfxCanvasRectangle
from pysollib.settings import TITLE
@@ -48,8 +49,9 @@ from pysollib.settings import TITLE
LARGE_EMBLEMS_SIZE = (38, 34)
SMALL_EMBLEMS_SIZE = (31, 21)
+
class FindCardDialog(Tkinter.Toplevel):
- CARD_IMAGES = {} # key: (rank, suit)
+ CARD_IMAGES = {} # key: (rank, suit)
def __init__(self, parent, game, dir, size='large'):
Tkinter.Toplevel.__init__(self)
@@ -57,7 +59,7 @@ class FindCardDialog(Tkinter.Toplevel):
self.title(title)
self.wm_resizable(False, False)
#
- ##self.images_dir = dir
+ # self.images_dir = dir
if size == 'large':
self.images_dir = os.path.join(dir, 'large')
self.label_width, self.label_height = LARGE_EMBLEMS_SIZE
@@ -65,7 +67,7 @@ class FindCardDialog(Tkinter.Toplevel):
self.images_dir = os.path.join(dir, 'small')
self.label_width, self.label_height = SMALL_EMBLEMS_SIZE
self.canvas = MfxCanvas(self, bg='white')
- ##self.canvas = MfxCanvas(self, bg='black')
+ # self.canvas = MfxCanvas(self, bg='black')
self.canvas.pack(expand=True, fill='both')
#
self.groups = []
@@ -76,8 +78,9 @@ class FindCardDialog(Tkinter.Toplevel):
bind(self, "WM_DELETE_WINDOW", self.destroy)
bind(self, "", self.destroy)
#
- ##self.normal_timeout = 400 # in milliseconds
- self.normal_timeout = int(1000*game.app.opt.timeouts['highlight_samerank'])
+ # self.normal_timeout = 400 # in milliseconds
+ self.normal_timeout = int(
+ 1000*game.app.opt.timeouts['highlight_samerank'])
self.hidden_timeout = 200
self.timer = None
@@ -140,9 +143,11 @@ class FindCardDialog(Tkinter.Toplevel):
self.wm_geometry('') # cancel user-specified geometry
def enterEvent(self, suit, rank, rect, group):
- ##print 'enterEvent', suit, rank, self.busy
- if self.busy: return
- if self.game.demo: return
+ # print 'enterEvent', suit, rank, self.busy
+ if self.busy:
+ return
+ if self.game.demo:
+ return
self.busy = True
self.highlight_items = self.game.highlightCard(suit, rank)
if not self.highlight_items:
@@ -154,8 +159,9 @@ class FindCardDialog(Tkinter.Toplevel):
self.busy = False
def leaveEvent(self, suit, rank, rect, group):
- ##print 'leaveEvent', suit, rank, self.busy
- if self.busy: return
+ # print 'leaveEvent', suit, rank, self.busy
+ if self.busy:
+ return
self.busy = True
if self.highlight_items:
for i in self.highlight_items:
@@ -170,7 +176,6 @@ class FindCardDialog(Tkinter.Toplevel):
self.canvas.update_idletasks()
self.busy = False
-
def timeoutEvent(self, *event):
if self.highlight_items:
state = self.highlight_items[0].cget('state')
@@ -199,31 +204,31 @@ class FindCardDialog(Tkinter.Toplevel):
Tkinter.Toplevel.destroy(self)
-
find_card_dialog = None
+
def create_find_card_dialog(parent, game, dir):
global find_card_dialog
try:
find_card_dialog.wm_deiconify()
find_card_dialog.tkraise()
except:
- ##traceback.print_exc()
+ # traceback.print_exc()
find_card_dialog = FindCardDialog(parent, game, dir)
+
def connect_game_find_card_dialog(game):
try:
find_card_dialog.connectGame(game)
except:
pass
+
def destroy_find_card_dialog():
global find_card_dialog
try:
find_card_dialog.destroy()
except:
- ##traceback.print_exc()
+ # traceback.print_exc()
pass
find_card_dialog = None
-
-
diff --git a/pysollib/ui/tktile/gameinfodialog.py b/pysollib/ui/tktile/gameinfodialog.py
index d135c156..b1d545f3 100644
--- a/pysollib/ui/tktile/gameinfodialog.py
+++ b/pysollib/ui/tktile/gameinfodialog.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,11 +19,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
# PySol imports
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
from pysollib.mfxutil import KwStruct
from pysollib.gamedb import GI
@@ -31,10 +31,12 @@ from pysollib.gamedb import GI
# *
# ************************************************************************
+
class BaseGameInfoDialog:
def __init__(self, parent, title, app, **kw):
kw = self.initKw(kw)
- self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
+ self._calc_MfxDialog().__init__(
+ self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
@@ -46,9 +48,12 @@ class BaseGameInfoDialog:
gi = game.gameinfo
#
- if gi.redeals == -2: redeals = 'VARIABLE'
- elif gi.redeals == -1: redeals = 'UNLIMITED'
- else: redeals = str(gi.redeals)
+ if gi.redeals == -2:
+ redeals = 'VARIABLE'
+ elif gi.redeals == -1:
+ redeals = 'UNLIMITED'
+ else:
+ redeals = str(gi.redeals)
cat = ''
type = ''
flags = []
@@ -59,7 +64,7 @@ class BaseGameInfoDialog:
cat = attr
elif attr.startswith('GT_'):
t = getattr(GI, attr)
- if t < (1<<12)-1:
+ if t < (1 << 12)-1:
if gi.si.game_type == t:
type = attr
else:
@@ -102,10 +107,12 @@ class BaseGameInfoDialog:
('Hint:', hint),
):
if t:
- self._calcToolkit().Label(frame, text=n, anchor='w'
- ).grid(row=row, column=0, sticky='nw')
- self._calcToolkit().Label(frame, text=t, anchor='w', justify='left'
- ).grid(row=row, column=1, sticky='nw')
+ self._calcToolkit().Label(
+ frame, text=n, anchor='w').grid(
+ row=row, column=0, sticky='nw')
+ self._calcToolkit().Label(
+ frame, text=t, anchor='w', justify='left').grid(
+ row=row, column=1, sticky='nw')
row += 1
if game.s.talon:
@@ -118,7 +125,7 @@ class BaseGameInfoDialog:
('Foundations:', game.s.foundations,),
('Rows:', game.s.rows,),
('Reserves:', game.s.reserves,),
- ):
+ ):
if s:
self.showStacks(frame, row, t, s)
row += 1
@@ -128,8 +135,9 @@ class BaseGameInfoDialog:
self.mainloop(focus, kw.timeout)
def showStacks(self, frame, row, title, stacks):
- self._calcToolkit().Label(frame, text=title, anchor='w'
- ).grid(row=row, column=0, sticky='nw')
+ self._calcToolkit().Label(
+ frame, text=title, anchor='w').grid(
+ row=row, column=0, sticky='nw')
if isinstance(stacks, (list, tuple)):
fs = {}
for f in stacks:
@@ -141,8 +149,9 @@ class BaseGameInfoDialog:
t = '\n'.join(['%s (%d)' % (i[0], i[1]) for i in fs.items()])
else:
t = stacks.__class__.__name__
- self._calcToolkit().Label(frame, text=t, anchor='w', justify='left'
- ).grid(row=row, column=1, sticky='nw')
+ self._calcToolkit().Label(
+ frame, text=t, anchor='w', justify='left').grid(
+ row=row, column=1, sticky='nw')
def initKw(self, kw):
kw = KwStruct(kw,
diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py
index 100a5328..f5b4b0e5 100644
--- a/pysollib/ui/tktile/menubar.py
+++ b/pysollib/ui/tktile/menubar.py
@@ -14,10 +14,12 @@ from pysollib.settings import SELECT_GAME_MENU
from pysollib.gamedb import GI
from pysollib.settings import USE_FREECELL_SOLVER
-from pysollib.ui.tktile.tkconst import EVENT_HANDLED, EVENT_PROPAGATE, CURSOR_WATCH, COMPOUNDS
+from pysollib.ui.tktile.tkconst import EVENT_HANDLED, EVENT_PROPAGATE, \
+ CURSOR_WATCH, COMPOUNDS
from pysollib.ui.tktile.tkconst import TOOLBAR_BUTTONS
from pysollib.ui.tktile.tkutil import bind, after_idle
+
def createToolbarMenu(menubar, menu):
tearoff = menu.cget('tearoff')
# data_dir = os.path.join(menubar.app.dataloader.dir, 'images', 'toolbar')
@@ -26,9 +28,10 @@ def createToolbarMenu(menubar, menu):
# d = os.path.join(data_dir, f)
# if os.path.isdir(d) and os.path.exists(os.path.join(d, 'small')):
# name = f.replace('_', ' ').capitalize()
-# submenu.add_radiobutton(label=name,
-# variable=menubar.tkopt.toolbar_style,
-# value=f, command=menubar.mOptToolbarStyle)
+# submenu.add_radiobutton(
+# label=name,
+# variable=menubar.tkopt.toolbar_style,
+# value=f, command=menubar.mOptToolbarStyle)
submenu = MfxMenu(menu, label=n_('Compound'), tearoff=tearoff)
for comp, label in COMPOUNDS:
submenu.add_radiobutton(
@@ -50,17 +53,18 @@ def createToolbarMenu(menubar, menu):
menu.add_radiobutton(label=n_("Right"),
variable=menubar.tkopt.toolbar, value=4,
command=menubar.mOptToolbar)
-## menu.add_separator()
-## menu.add_radiobutton(label=n_("Small icons"),
-## variable=menubar.tkopt.toolbar_size, value=0,
-## command=menubar.mOptToolbarSize)
-## menu.add_radiobutton(label=n_("Large icons"),
-## variable=menubar.tkopt.toolbar_size, value=1,
-## command=menubar.mOptToolbarSize)
+ # menu.add_separator()
+ # menu.add_radiobutton(label=n_("Small icons"),
+ # variable=menubar.tkopt.toolbar_size, value=0,
+ # command=menubar.mOptToolbarSize)
+ # menu.add_radiobutton(label=n_("Large icons"),
+ # variable=menubar.tkopt.toolbar_size, value=1,
+ # command=menubar.mOptToolbarSize)
menu.add_separator()
submenu = MfxMenu(menu, label=n_('Visible buttons'), tearoff=tearoff)
for w in TOOLBAR_BUTTONS:
- submenu.add_checkbutton(label=_(w.capitalize()),
+ submenu.add_checkbutton(
+ label=_(w.capitalize()),
variable=menubar.tkopt.toolbar_vars[w],
command=lambda m=menubar, w=w: m.mOptToolbarConfig(w))
@@ -79,7 +83,7 @@ class MfxMenubar(Tkinter.Menu):
Tkinter.Menu.__init__(self, master, **kw)
def labeltoname(self, label):
- #print label, type(label)
+ # print label, type(label)
name = re.sub(r"[^0-9a-zA-Z]", "", label).lower()
label = _(label)
underline = label.find('&')
@@ -92,7 +96,7 @@ class MfxMenubar(Tkinter.Menu):
if label:
name = cnf.get('name')
if name:
- del cnf['name'] # TclError: unknown option "-name"
+ del cnf['name'] # TclError: unknown option "-name"
else:
name, label, underline = self.labeltoname(label)
cnf["underline"] = cnf.get("underline", underline)
@@ -115,7 +119,8 @@ class MfxMenu(MfxMenubar):
if underline is None:
underline = label_underline
if master:
- master.add_cascade(menu=self, name=name, label=label, underline=underline)
+ master.add_cascade(
+ menu=self, name=name, label=label, underline=underline)
class PysolMenubarTkCommon:
@@ -124,11 +129,11 @@ class PysolMenubarTkCommon:
self._setOptions()
# init columnbreak
self.cb_max = int(self.top.winfo_screenheight()/23)
-## sh = self.top.winfo_screenheight()
-## self.cb_max = 22
-## if sh >= 600: self.cb_max = 27
-## if sh >= 768: self.cb_max = 32
-## if sh >= 1024: self.cb_max = 40
+ # sh = self.top.winfo_screenheight()
+ # self.cb_max = 22
+ # if sh >= 600: self.cb_max = 27
+ # if sh >= 768: self.cb_max = 32
+ # if sh >= 1024: self.cb_max = 40
self.progress = progress
# create menus
self.menubar = None
@@ -137,7 +142,8 @@ class PysolMenubarTkCommon:
self._createMenubar()
self.top = top
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
# set the menubar
self.updateBackgroundImagesMenu()
@@ -146,51 +152,51 @@ class PysolMenubarTkCommon:
def _createTkOpt(self):
# structure to convert menu-options to Toolkit variables
self.tkopt = Struct(
- gameid = Tkinter.IntVar(),
- gameid_popular = Tkinter.IntVar(),
- comment = Tkinter.BooleanVar(),
- autofaceup = Tkinter.BooleanVar(),
- autodrop = Tkinter.BooleanVar(),
- autodeal = Tkinter.BooleanVar(),
- quickplay = Tkinter.BooleanVar(),
- undo = Tkinter.BooleanVar(),
- bookmarks = Tkinter.BooleanVar(),
- hint = Tkinter.BooleanVar(),
- shuffle = Tkinter.BooleanVar(),
- highlight_piles = Tkinter.BooleanVar(),
- highlight_cards = Tkinter.BooleanVar(),
- highlight_samerank = Tkinter.BooleanVar(),
- highlight_not_matching = Tkinter.BooleanVar(),
- mahjongg_show_removed = Tkinter.BooleanVar(),
- shisen_show_hint = Tkinter.BooleanVar(),
- sound = Tkinter.BooleanVar(),
- auto_scale = Tkinter.BooleanVar(),
- cardback = Tkinter.IntVar(),
- tabletile = Tkinter.IntVar(),
- animations = Tkinter.IntVar(),
- redeal_animation = Tkinter.BooleanVar(),
- win_animation = Tkinter.BooleanVar(),
- shadow = Tkinter.BooleanVar(),
- shade = Tkinter.BooleanVar(),
- shade_filled_stacks = Tkinter.BooleanVar(),
- shrink_face_down = Tkinter.BooleanVar(),
- toolbar = Tkinter.IntVar(),
- toolbar_style = Tkinter.StringVar(),
- toolbar_relief = Tkinter.StringVar(),
- toolbar_compound = Tkinter.StringVar(),
- toolbar_size = Tkinter.IntVar(),
- statusbar = Tkinter.BooleanVar(),
- num_cards = Tkinter.BooleanVar(),
- helpbar = Tkinter.BooleanVar(),
- save_games_geometry = Tkinter.BooleanVar(),
- splashscreen = Tkinter.BooleanVar(),
- demo_logo = Tkinter.BooleanVar(),
- mouse_type = Tkinter.StringVar(),
- mouse_undo = Tkinter.BooleanVar(),
- negative_bottom = Tkinter.BooleanVar(),
- pause = Tkinter.BooleanVar(),
- theme = Tkinter.StringVar(),
- toolbar_vars = {},
+ gameid=Tkinter.IntVar(),
+ gameid_popular=Tkinter.IntVar(),
+ comment=Tkinter.BooleanVar(),
+ autofaceup=Tkinter.BooleanVar(),
+ autodrop=Tkinter.BooleanVar(),
+ autodeal=Tkinter.BooleanVar(),
+ quickplay=Tkinter.BooleanVar(),
+ undo=Tkinter.BooleanVar(),
+ bookmarks=Tkinter.BooleanVar(),
+ hint=Tkinter.BooleanVar(),
+ shuffle=Tkinter.BooleanVar(),
+ highlight_piles=Tkinter.BooleanVar(),
+ highlight_cards=Tkinter.BooleanVar(),
+ highlight_samerank=Tkinter.BooleanVar(),
+ highlight_not_matching=Tkinter.BooleanVar(),
+ mahjongg_show_removed=Tkinter.BooleanVar(),
+ shisen_show_hint=Tkinter.BooleanVar(),
+ sound=Tkinter.BooleanVar(),
+ auto_scale=Tkinter.BooleanVar(),
+ cardback=Tkinter.IntVar(),
+ tabletile=Tkinter.IntVar(),
+ animations=Tkinter.IntVar(),
+ redeal_animation=Tkinter.BooleanVar(),
+ win_animation=Tkinter.BooleanVar(),
+ shadow=Tkinter.BooleanVar(),
+ shade=Tkinter.BooleanVar(),
+ shade_filled_stacks=Tkinter.BooleanVar(),
+ shrink_face_down=Tkinter.BooleanVar(),
+ toolbar=Tkinter.IntVar(),
+ toolbar_style=Tkinter.StringVar(),
+ toolbar_relief=Tkinter.StringVar(),
+ toolbar_compound=Tkinter.StringVar(),
+ toolbar_size=Tkinter.IntVar(),
+ statusbar=Tkinter.BooleanVar(),
+ num_cards=Tkinter.BooleanVar(),
+ helpbar=Tkinter.BooleanVar(),
+ save_games_geometry=Tkinter.BooleanVar(),
+ splashscreen=Tkinter.BooleanVar(),
+ demo_logo=Tkinter.BooleanVar(),
+ mouse_type=Tkinter.StringVar(),
+ mouse_undo=Tkinter.BooleanVar(),
+ negative_bottom=Tkinter.BooleanVar(),
+ pause=Tkinter.BooleanVar(),
+ theme=Tkinter.StringVar(),
+ toolbar_vars={},
)
for w in TOOLBAR_BUTTONS:
self.tkopt.toolbar_vars[w] = Tkinter.BooleanVar()
@@ -246,7 +252,7 @@ class PysolMenubarTkCommon:
if game is None:
return
assert self.app is game.app
- tkopt, opt = self.tkopt, self.app.opt
+ tkopt = self.tkopt
tkopt.gameid.set(game.id)
tkopt.gameid_popular.set(game.id)
tkopt.comment.set(bool(game.gsaveinfo.comment))
@@ -260,7 +266,7 @@ class PysolMenubarTkCommon:
# create a GTK-like path
def _addPath(self, path, menu, index, submenu):
if path not in self.menupath:
- ##print path, menu, index, submenu
+ # print path, menu, index, submenu
self.menupath[path] = (menu, index, submenu)
def _getEnabledState(self, enabled):
@@ -269,170 +275,338 @@ class PysolMenubarTkCommon:
return "disabled"
def updateProgress(self):
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
def _createMenubar(self):
MfxMenubar.addPath = self._addPath
- kw = { "name": "menubar" }
+ kw = {"name": "menubar"}
self.menubar = MfxMenubar(self.top, **kw)
# init keybindings
bind(self.top, "", self._keyPressHandler)
m = "Ctrl-"
- if sys.platform == "darwin": m = "Cmd-"
+ if sys.platform == "darwin":
+ m = "Cmd-"
if WIN_SYSTEM == "aqua":
- applemenu=MfxMenu(self.menubar, "apple")
- applemenu.add_command(label=_("&About ")+TITLE, command=self.mHelpAbout)
+ applemenu = MfxMenu(self.menubar, "apple")
+ applemenu.add_command(
+ label=_("&About ")+TITLE, command=self.mHelpAbout)
menu = MfxMenu(self.menubar, n_("&File"))
- menu.add_command(label=n_("&New game"), command=self.mNewGame, accelerator="N")
+ menu.add_command(
+ label=n_("&New game"), command=self.mNewGame, accelerator="N")
submenu = MfxMenu(menu, label=n_("R&ecent games"))
- ##menu.add_command(label=n_("Select &random game"), command=self.mSelectRandomGame, accelerator=m+"R")
+ # menu.add_command(label=n_("Select &random game"),
+ # command=self.mSelectRandomGame, accelerator=m+"R")
submenu = MfxMenu(menu, label=n_("Select &random game"))
- submenu.add_command(label=n_("&All games"), command=lambda : self.mSelectRandomGame('all'), accelerator=m+"R")
- submenu.add_command(label=n_("Games played and &won"), command=lambda : self.mSelectRandomGame('won'))
- submenu.add_command(label=n_("Games played and ¬ won"), command=lambda : self.mSelectRandomGame('not won'))
- submenu.add_command(label=n_("Games not &played"), command=lambda : self.mSelectRandomGame('not played'))
- menu.add_command(label=n_("Select game by nu&mber..."), command=self.mSelectGameById, accelerator=m+"M")
+ submenu.add_command(
+ label=n_("&All games"), command=lambda:
+ self.mSelectRandomGame('all'), accelerator=m+"R")
+ submenu.add_command(
+ label=n_("Games played and &won"),
+ command=lambda: self.mSelectRandomGame('won'))
+ submenu.add_command(
+ label=n_("Games played and ¬ won"),
+ command=lambda: self.mSelectRandomGame('not won'))
+ submenu.add_command(
+ label=n_("Games not &played"),
+ command=lambda: self.mSelectRandomGame('not played'))
+ menu.add_command(
+ label=n_("Select game by nu&mber..."),
+ command=self.mSelectGameById, accelerator=m+"M")
menu.add_separator()
submenu = MfxMenu(menu, label=n_("Fa&vorite games"))
menu.add_command(label=n_("A&dd to favorites"), command=self.mAddFavor)
- menu.add_command(label=n_("Remove &from favorites"), command=self.mDelFavor)
+ menu.add_command(
+ label=n_("Remove &from favorites"),
+ command=self.mDelFavor)
menu.add_separator()
- menu.add_command(label=n_("&Open..."), command=self.mOpen, accelerator=m+"O")
- menu.add_command(label=n_("&Save"), command=self.mSave, accelerator=m+"S")
+ menu.add_command(
+ label=n_("&Open..."),
+ command=self.mOpen, accelerator=m+"O")
+ menu.add_command(
+ label=n_("&Save"),
+ command=self.mSave, accelerator=m+"S")
menu.add_command(label=n_("Save &as..."), command=self.mSaveAs)
- menu.add_command(label=n_("E&xport current layout..."), command=self.mExportCurrentLayout)
+ menu.add_command(
+ label=n_("E&xport current layout..."),
+ command=self.mExportCurrentLayout)
menu.add_separator()
- menu.add_command(label=n_("&Hold and quit"), command=self.mHoldAndQuit, accelerator=m+"X")
+ menu.add_command(
+ label=n_("&Hold and quit"),
+ command=self.mHoldAndQuit, accelerator=m+"X")
if WIN_SYSTEM != "aqua":
- menu.add_command(label=n_("&Quit"), command=self.mQuit, accelerator=m+"Q")
+ menu.add_command(
+ label=n_("&Quit"),
+ command=self.mQuit, accelerator=m+"Q")
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
menu = MfxMenu(self.menubar, label=n_("&Select"))
self._addSelectGameMenu(menu)
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
menu = MfxMenu(self.menubar, label=n_("&Edit"))
- menu.add_command(label=n_("&Undo"), command=self.mUndo, accelerator="Z")
- menu.add_command(label=n_("&Redo"), command=self.mRedo, accelerator="R")
+ menu.add_command(
+ label=n_("&Undo"),
+ command=self.mUndo, accelerator="Z")
+ menu.add_command(
+ label=n_("&Redo"),
+ command=self.mRedo, accelerator="R")
menu.add_command(label=n_("Redo &all"), command=self.mRedoAll)
menu.add_separator()
submenu = MfxMenu(menu, label=n_("&Set bookmark"))
for i in range(9):
label = _("Bookmark %d") % (i + 1)
- submenu.add_command(label=label, command=lambda i=i: self.mSetBookmark(i))
+ submenu.add_command(
+ label=label,
+ command=lambda i=i: self.mSetBookmark(i))
submenu = MfxMenu(menu, label=n_("Go&to bookmark"))
for i in range(9):
label = _("Bookmark %d") % (i + 1)
acc = m + "%d" % (i + 1)
- submenu.add_command(label=label, command=lambda i=i: self.mGotoBookmark(i), accelerator=acc)
- menu.add_command(label=n_("&Clear bookmarks"), command=self.mClearBookmarks)
+ submenu.add_command(
+ label=label,
+ command=lambda i=i: self.mGotoBookmark(i), accelerator=acc)
+ menu.add_command(
+ label=n_("&Clear bookmarks"),
+ command=self.mClearBookmarks)
menu.add_separator()
- menu.add_command(label=n_("Restart"), command=self.mRestart, accelerator=m+"G")
+ menu.add_command(
+ label=n_("Restart"),
+ command=self.mRestart, accelerator=m+"G")
menu.add_separator()
menu.add_command(label=n_("Solitaire &Wizard"), command=self.mWizard)
- menu.add_command(label=n_("&Edit current game"), command=self.mWizardEdit)
+ menu.add_command(
+ label=n_("&Edit current game"),
+ command=self.mWizardEdit)
menu = MfxMenu(self.menubar, label=n_("&Game"))
- menu.add_command(label=n_("&Deal cards"), command=self.mDeal, accelerator="D")
- menu.add_command(label=n_("&Auto drop"), command=self.mDrop, accelerator="A")
- menu.add_command(label=n_("Shu&ffle tiles"), command=self.mShuffle, accelerator="F")
- menu.add_checkbutton(label=n_("&Pause"), variable=self.tkopt.pause, command=self.mPause, accelerator="P")
- #menu.add_command(label=n_("&Pause"), command=self.mPause, accelerator="P")
+ menu.add_command(
+ label=n_("&Deal cards"),
+ command=self.mDeal, accelerator="D")
+ menu.add_command(
+ label=n_("&Auto drop"),
+ command=self.mDrop, accelerator="A")
+ menu.add_command(
+ label=n_("Shu&ffle tiles"),
+ command=self.mShuffle, accelerator="F")
+ menu.add_checkbutton(
+ label=n_("&Pause"), variable=self.tkopt.pause,
+ command=self.mPause, accelerator="P")
+ # menu.add_command(
+ # label=n_("&Pause"), command=self.mPause, accelerator="P")
menu.add_separator()
- menu.add_command(label=n_("S&tatus..."), command=lambda : self.mPlayerStats(mode=100), accelerator=m+"Y")
- menu.add_checkbutton(label=n_("&Comments..."), variable=self.tkopt.comment, command=self.mEditGameComment)
+ menu.add_command(
+ label=n_("S&tatus..."),
+ command=lambda: self.mPlayerStats(mode=100), accelerator=m+"Y")
+ menu.add_checkbutton(
+ label=n_("&Comments..."), variable=self.tkopt.comment,
+ command=self.mEditGameComment)
menu.add_separator()
- menu.add_command(label=n_("&Statistics..."), command=self.mPlayerStats, accelerator=m+"T")
- menu.add_command(label=n_("Log..."), command=lambda : self.mPlayerStats(mode=103))
+ menu.add_command(
+ label=n_("&Statistics..."),
+ command=self.mPlayerStats, accelerator=m+"T")
+ menu.add_command(
+ label=n_("Log..."),
+ command=lambda: self.mPlayerStats(mode=103))
menu.add_separator()
- menu.add_command(label=n_("D&emo statistics"), command=lambda : self.mPlayerStats(mode=1101))
+ menu.add_command(
+ label=n_("D&emo statistics"),
+ command=lambda: self.mPlayerStats(mode=1101))
menu = MfxMenu(self.menubar, label=n_("&Assist"))
- menu.add_command(label=n_("&Hint"), command=self.mHint, accelerator="H")
- menu.add_command(label=n_("Highlight p&iles"), command=self.mHighlightPiles, accelerator="I")
- menu.add_command(label=n_("&Find card"), command=self.mFindCard, accelerator="F3")
+ menu.add_command(
+ label=n_("&Hint"),
+ command=self.mHint, accelerator="H")
+ menu.add_command(
+ label=n_("Highlight p&iles"),
+ command=self.mHighlightPiles, accelerator="I")
+ menu.add_command(
+ label=n_("&Find card"),
+ command=self.mFindCard, accelerator="F3")
menu.add_separator()
- menu.add_command(label=n_("&Demo"), command=self.mDemo, accelerator=m+"D")
- menu.add_command(label=n_("Demo (&all games)"), command=self.mMixedDemo)
+ menu.add_command(
+ label=n_("&Demo"),
+ command=self.mDemo, accelerator=m+"D")
+ menu.add_command(
+ label=n_("Demo (&all games)"),
+ command=self.mMixedDemo)
if USE_FREECELL_SOLVER:
menu.add_command(label=n_("&Solver"), command=self.mSolver)
else:
menu.add_command(label=n_("&Solver"), state='disabled')
menu.add_separator()
- menu.add_command(label=n_("&Piles description"), command=self.mStackDesk, accelerator="F2")
+ menu.add_command(
+ label=n_("&Piles description"),
+ command=self.mStackDesk, accelerator="F2")
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
menu = MfxMenu(self.menubar, label=n_("&Options"))
- menu.add_command(label=n_("&Player options..."), command=self.mOptPlayerOptions)
+ menu.add_command(
+ label=n_("&Player options..."),
+ command=self.mOptPlayerOptions)
submenu = MfxMenu(menu, label=n_("&Automatic play"))
- submenu.add_checkbutton(label=n_("Auto &face up"), variable=self.tkopt.autofaceup, command=self.mOptAutoFaceUp)
- submenu.add_checkbutton(label=n_("A&uto drop"), variable=self.tkopt.autodrop, command=self.mOptAutoDrop)
- submenu.add_checkbutton(label=n_("Auto &deal"), variable=self.tkopt.autodeal, command=self.mOptAutoDeal)
+ submenu.add_checkbutton(
+ label=n_("Auto &face up"), variable=self.tkopt.autofaceup,
+ command=self.mOptAutoFaceUp)
+ submenu.add_checkbutton(
+ label=n_("A&uto drop"), variable=self.tkopt.autodrop,
+ command=self.mOptAutoDrop)
+ submenu.add_checkbutton(
+ label=n_("Auto &deal"), variable=self.tkopt.autodeal,
+ command=self.mOptAutoDeal)
submenu.add_separator()
- submenu.add_checkbutton(label=n_("&Quick play"), variable=self.tkopt.quickplay, command=self.mOptQuickPlay)
+ submenu.add_checkbutton(
+ label=n_("&Quick play"), variable=self.tkopt.quickplay,
+ command=self.mOptQuickPlay)
submenu = MfxMenu(menu, label=n_("Assist &level"))
- submenu.add_checkbutton(label=n_("Enable &undo"), variable=self.tkopt.undo, command=self.mOptEnableUndo)
- submenu.add_checkbutton(label=n_("Enable &bookmarks"), variable=self.tkopt.bookmarks, command=self.mOptEnableBookmarks)
- submenu.add_checkbutton(label=n_("Enable &hint"), variable=self.tkopt.hint, command=self.mOptEnableHint)
- submenu.add_checkbutton(label=n_("Enable shu&ffle"), variable=self.tkopt.shuffle, command=self.mOptEnableShuffle)
- submenu.add_checkbutton(label=n_("Enable highlight p&iles"), variable=self.tkopt.highlight_piles, command=self.mOptEnableHighlightPiles)
- submenu.add_checkbutton(label=n_("Enable highlight &cards"), variable=self.tkopt.highlight_cards, command=self.mOptEnableHighlightCards)
- submenu.add_checkbutton(label=n_("Enable highlight same &rank"), variable=self.tkopt.highlight_samerank, command=self.mOptEnableHighlightSameRank)
- submenu.add_checkbutton(label=n_("Highlight &no matching"), variable=self.tkopt.highlight_not_matching, command=self.mOptEnableHighlightNotMatching)
+ submenu.add_checkbutton(
+ label=n_("Enable &undo"), variable=self.tkopt.undo,
+ command=self.mOptEnableUndo)
+ submenu.add_checkbutton(
+ label=n_("Enable &bookmarks"), variable=self.tkopt.bookmarks,
+ command=self.mOptEnableBookmarks)
+ submenu.add_checkbutton(
+ label=n_("Enable &hint"), variable=self.tkopt.hint,
+ command=self.mOptEnableHint)
+ submenu.add_checkbutton(
+ label=n_("Enable shu&ffle"), variable=self.tkopt.shuffle,
+ command=self.mOptEnableShuffle)
+ submenu.add_checkbutton(
+ label=n_("Enable highlight p&iles"),
+ variable=self.tkopt.highlight_piles,
+ command=self.mOptEnableHighlightPiles)
+ submenu.add_checkbutton(
+ label=n_("Enable highlight &cards"),
+ variable=self.tkopt.highlight_cards,
+ command=self.mOptEnableHighlightCards)
+ submenu.add_checkbutton(
+ label=n_("Enable highlight same &rank"),
+ variable=self.tkopt.highlight_samerank,
+ command=self.mOptEnableHighlightSameRank)
+ submenu.add_checkbutton(
+ label=n_("Highlight &no matching"),
+ variable=self.tkopt.highlight_not_matching,
+ command=self.mOptEnableHighlightNotMatching)
submenu.add_separator()
- submenu.add_checkbutton(label=n_("&Show removed tiles (in Mahjongg games)"), variable=self.tkopt.mahjongg_show_removed, command=self.mOptMahjonggShowRemoved)
- submenu.add_checkbutton(label=n_("Show hint &arrow (in Shisen-Sho games)"), variable=self.tkopt.shisen_show_hint, command=self.mOptShisenShowHint)
+ submenu.add_checkbutton(
+ label=n_("&Show removed tiles (in Mahjongg games)"),
+ variable=self.tkopt.mahjongg_show_removed,
+ command=self.mOptMahjonggShowRemoved)
+ submenu.add_checkbutton(
+ label=n_("Show hint &arrow (in Shisen-Sho games)"),
+ variable=self.tkopt.shisen_show_hint,
+ command=self.mOptShisenShowHint)
menu.add_separator()
label = n_("&Sound...")
if not self.app.audio.CAN_PLAY_SOUND:
- menu.add_checkbutton(label=label, variable=self.tkopt.sound, command=self.mOptSoundDialog, state='disabled')
+ menu.add_checkbutton(
+ label=label, variable=self.tkopt.sound,
+ command=self.mOptSoundDialog, state='disabled')
else:
- menu.add_checkbutton(label=label, variable=self.tkopt.sound, command=self.mOptSoundDialog)
+ menu.add_checkbutton(
+ label=label, variable=self.tkopt.sound,
+ command=self.mOptSoundDialog)
# cardsets
if USE_PIL:
submenu = MfxMenu(menu, label=n_("Card si&ze"))
- submenu.add_command(label=n_("&Increase the card size"), command=self.mIncreaseCardset, accelerator=m+"+")
- submenu.add_command(label=n_("&Decrease the card size"), command=self.mDecreaseCardset, accelerator=m+"-")
- submenu.add_checkbutton(label=n_("&Auto scaling"), variable=self.tkopt.auto_scale, command=self.mOptAutoScale, accelerator=m+'0')
- #manager = self.app.cardset_manager
- #n = manager.len()
- menu.add_command(label=n_("Cards&et..."), command=self.mSelectCardsetDialog, accelerator=m+"E")
- menu.add_command(label=n_("Table t&ile..."), command=self.mSelectTileDialog)
+ submenu.add_command(
+ label=n_("&Increase the card size"),
+ command=self.mIncreaseCardset, accelerator=m+"+")
+ submenu.add_command(
+ label=n_("&Decrease the card size"),
+ command=self.mDecreaseCardset, accelerator=m+"-")
+ submenu.add_checkbutton(
+ label=n_("&Auto scaling"), variable=self.tkopt.auto_scale,
+ command=self.mOptAutoScale, accelerator=m+'0')
+ # manager = self.app.cardset_manager
+ # n = manager.len()
+ menu.add_command(
+ label=n_("Cards&et..."),
+ command=self.mSelectCardsetDialog, accelerator=m+"E")
+ menu.add_command(
+ label=n_("Table t&ile..."),
+ command=self.mSelectTileDialog)
# this submenu will get set by updateBackgroundImagesMenu()
submenu = MfxMenu(menu, label=n_("Card &background"))
submenu = MfxMenu(menu, label=n_("Card &view"))
- submenu.add_checkbutton(label=n_("Card shado&w"), variable=self.tkopt.shadow, command=self.mOptShadow)
- submenu.add_checkbutton(label=n_("Shade &legal moves"), variable=self.tkopt.shade, command=self.mOptShade)
- submenu.add_checkbutton(label=n_("&Negative cards bottom"), variable=self.tkopt.negative_bottom, command=self.mOptNegativeBottom)
- submenu.add_checkbutton(label=n_("Shrink face-down cards"), variable=self.tkopt.shrink_face_down, command=self.mOptShrinkFaceDown)
- submenu.add_checkbutton(label=n_("Shade &filled stacks"), variable=self.tkopt.shade_filled_stacks, command=self.mOptShadeFilledStacks)
+ submenu.add_checkbutton(
+ label=n_("Card shado&w"), variable=self.tkopt.shadow,
+ command=self.mOptShadow)
+ submenu.add_checkbutton(
+ label=n_("Shade &legal moves"), variable=self.tkopt.shade,
+ command=self.mOptShade)
+ submenu.add_checkbutton(
+ label=n_("&Negative cards bottom"),
+ variable=self.tkopt.negative_bottom,
+ command=self.mOptNegativeBottom)
+ submenu.add_checkbutton(
+ label=n_("Shrink face-down cards"),
+ variable=self.tkopt.shrink_face_down,
+ command=self.mOptShrinkFaceDown)
+ submenu.add_checkbutton(
+ label=n_("Shade &filled stacks"),
+ variable=self.tkopt.shade_filled_stacks,
+ command=self.mOptShadeFilledStacks)
submenu = MfxMenu(menu, label=n_("A&nimations"))
- submenu.add_radiobutton(label=n_("&None"), variable=self.tkopt.animations, value=0, command=self.mOptAnimations)
- submenu.add_radiobutton(label=n_("&Very fast"), variable=self.tkopt.animations, value=1, command=self.mOptAnimations)
- submenu.add_radiobutton(label=n_("&Fast"), variable=self.tkopt.animations, value=2, command=self.mOptAnimations)
- submenu.add_radiobutton(label=n_("&Medium"), variable=self.tkopt.animations, value=3, command=self.mOptAnimations)
- submenu.add_radiobutton(label=n_("&Slow"), variable=self.tkopt.animations, value=4, command=self.mOptAnimations)
- submenu.add_radiobutton(label=n_("V&ery slow"), variable=self.tkopt.animations, value=5, command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("&None"), variable=self.tkopt.animations, value=0,
+ command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("&Very fast"), variable=self.tkopt.animations, value=1,
+ command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("&Fast"), variable=self.tkopt.animations, value=2,
+ command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("&Medium"), variable=self.tkopt.animations, value=3,
+ command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("&Slow"), variable=self.tkopt.animations, value=4,
+ command=self.mOptAnimations)
+ submenu.add_radiobutton(
+ label=n_("V&ery slow"), variable=self.tkopt.animations, value=5,
+ command=self.mOptAnimations)
submenu.add_separator()
- submenu.add_checkbutton(label=n_("&Redeal animation"), variable=self.tkopt.redeal_animation, command=self.mRedealAnimation)
+ submenu.add_checkbutton(
+ label=n_("&Redeal animation"),
+ variable=self.tkopt.redeal_animation,
+ command=self.mRedealAnimation)
if Image:
- submenu.add_checkbutton(label=n_("&Winning animation"), variable=self.tkopt.win_animation, command=self.mWinAnimation)
+ submenu.add_checkbutton(
+ label=n_("&Winning animation"),
+ variable=self.tkopt.win_animation,
+ command=self.mWinAnimation)
submenu = MfxMenu(menu, label=n_("&Mouse"))
- submenu.add_radiobutton(label=n_("&Drag-and-Drop"), variable=self.tkopt.mouse_type, value='drag-n-drop', command=self.mOptMouseType)
- submenu.add_radiobutton(label=n_("&Point-and-Click"), variable=self.tkopt.mouse_type, value='point-n-click', command=self.mOptMouseType)
- submenu.add_radiobutton(label=n_("&Sticky mouse"), variable=self.tkopt.mouse_type, value='sticky-mouse', command=self.mOptMouseType)
+ submenu.add_radiobutton(
+ label=n_("&Drag-and-Drop"), variable=self.tkopt.mouse_type,
+ value='drag-n-drop',
+ command=self.mOptMouseType)
+ submenu.add_radiobutton(
+ label=n_("&Point-and-Click"), variable=self.tkopt.mouse_type,
+ value='point-n-click',
+ command=self.mOptMouseType)
+ submenu.add_radiobutton(
+ label=n_("&Sticky mouse"), variable=self.tkopt.mouse_type,
+ value='sticky-mouse',
+ command=self.mOptMouseType)
submenu.add_separator()
- submenu.add_checkbutton(label=n_("Use mouse for undo/redo"), variable=self.tkopt.mouse_undo, command=self.mOptMouseUndo)
+ submenu.add_checkbutton(
+ label=n_("Use mouse for undo/redo"),
+ variable=self.tkopt.mouse_undo,
+ command=self.mOptMouseUndo)
menu.add_separator()
menu.add_command(label=n_("&Fonts..."), command=self.mOptFonts)
menu.add_command(label=n_("&Colors..."), command=self.mOptColors)
@@ -442,33 +616,59 @@ class PysolMenubarTkCommon:
submenu = MfxMenu(menu, label=n_("&Toolbar"))
createToolbarMenu(self, submenu)
submenu = MfxMenu(menu, label=n_("Stat&usbar"))
- submenu.add_checkbutton(label=n_("Show &statusbar"), variable=self.tkopt.statusbar, command=self.mOptStatusbar)
- submenu.add_checkbutton(label=n_("Show &number of cards"), variable=self.tkopt.num_cards, command=self.mOptNumCards)
- submenu.add_checkbutton(label=n_("Show &help bar"), variable=self.tkopt.helpbar, command=self.mOptHelpbar)
+ submenu.add_checkbutton(
+ label=n_("Show &statusbar"), variable=self.tkopt.statusbar,
+ command=self.mOptStatusbar)
+ submenu.add_checkbutton(
+ label=n_("Show &number of cards"), variable=self.tkopt.num_cards,
+ command=self.mOptNumCards)
+ submenu.add_checkbutton(
+ label=n_("Show &help bar"), variable=self.tkopt.helpbar,
+ command=self.mOptHelpbar)
if not USE_PIL:
- menu.add_checkbutton(label=n_("Save games &geometry"), variable=self.tkopt.save_games_geometry, command=self.mOptSaveGamesGeometry)
- menu.add_checkbutton(label=n_("&Demo logo"), variable=self.tkopt.demo_logo, command=self.mOptDemoLogo)
- menu.add_checkbutton(label=n_("Startup splash sc&reen"), variable=self.tkopt.splashscreen, command=self.mOptSplashscreen)
-### menu.add_separator()
-### menu.add_command(label="Save options", command=self.mOptSave)
+ menu.add_checkbutton(
+ label=n_("Save games &geometry"),
+ variable=self.tkopt.save_games_geometry,
+ command=self.mOptSaveGamesGeometry)
+ menu.add_checkbutton(
+ label=n_("&Demo logo"), variable=self.tkopt.demo_logo,
+ command=self.mOptDemoLogo)
+ menu.add_checkbutton(
+ label=n_("Startup splash sc&reen"),
+ variable=self.tkopt.splashscreen,
+ command=self.mOptSplashscreen)
+ # menu.add_separator()
+ # menu.add_command(label="Save options", command=self.mOptSave)
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
menu = MfxMenu(self.menubar, label=n_("&Help"))
- menu.add_command(label=n_("&Contents"), command=self.mHelp, accelerator=m+"F1")
- menu.add_command(label=n_("&How to play"), command=self.mHelpHowToPlay)
- menu.add_command(label=n_("&Rules for this game"), command=self.mHelpRules, accelerator="F1")
- menu.add_command(label=n_("&License terms"), command=self.mHelpLicense)
- ##menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews)
+ menu.add_command(
+ label=n_("&Contents"),
+ command=self.mHelp, accelerator=m+"F1")
+ menu.add_command(
+ label=n_("&How to play"),
+ command=self.mHelpHowToPlay)
+ menu.add_command(
+ label=n_("&Rules for this game"),
+ command=self.mHelpRules, accelerator="F1")
+ menu.add_command(
+ label=n_("&License terms"),
+ command=self.mHelpLicense)
+ # menu.add_command(label=n_("What's &new ?"), command=self.mHelpNews)
if WIN_SYSTEM != "aqua":
menu.add_separator()
- menu.add_command(label=n_("&About ")+TITLE+"...", command=self.mHelpAbout)
+ menu.add_command(
+ label=n_("&About ")+TITLE+"...",
+ command=self.mHelpAbout)
MfxMenubar.addPath = None
- ### FIXME: all key bindings should be *added* to keyPressHandler
+ # FIXME: all key bindings should be *added* to keyPressHandler
ctrl = "Control-"
- if sys.platform == "darwin": ctrl = "Command-"
+ if sys.platform == "darwin":
+ ctrl = "Command-"
self._bindKey("", "n", self.mNewGame)
self._bindKey(ctrl, "w", self.mSelectGameDialog)
self._bindKey(ctrl, "v", self.mSelectGameDialogWithPreview)
@@ -489,8 +689,8 @@ class PysolMenubarTkCommon:
self._bindKey(ctrl, "t", lambda e: self.mPlayerStats(mode=105))
self._bindKey("", "h", self.mHint)
self._bindKey(ctrl, "h", self.mHint1) # undocumented
- ##self._bindKey("", "Shift_L", self.mHighlightPiles)
- ##self._bindKey("", "Shift_R", self.mHighlightPiles)
+ # self._bindKey("", "Shift_L", self.mHighlightPiles)
+ # self._bindKey("", "Shift_R", self.mHighlightPiles)
self._bindKey("", "i", self.mHighlightPiles)
self._bindKey("", "F3", self.mFindCard)
self._bindKey(ctrl, "d", self.mDemo)
@@ -500,8 +700,8 @@ class PysolMenubarTkCommon:
self._bindKey(ctrl, "equal", self.mIncreaseCardset)
self._bindKey(ctrl, "minus", self.mDecreaseCardset)
self._bindKey(ctrl, "0", self.mOptAutoScale)
- self._bindKey(ctrl, "b", self.mOptChangeCardback) # undocumented
- self._bindKey(ctrl, "i", self.mOptChangeTableTile) # undocumented
+ self._bindKey(ctrl, "b", self.mOptChangeCardback) # undocumented
+ self._bindKey(ctrl, "i", self.mOptChangeTableTile) # undocumented
self._bindKey(ctrl, "p", self.mOptPlayerOptions) # undocumented
self._bindKey(ctrl, "F1", self.mHelp)
self._bindKey("", "F1", self.mHelpRules)
@@ -522,12 +722,15 @@ class PysolMenubarTkCommon:
self._bindKey("", "F2", self.mStackDesk)
#
- self._bindKey("", "slash", lambda e: self.mPlayerStats(mode=106)) # undocumented, devel
+ # undocumented, devel
+ self._bindKey("", "slash", lambda e: self.mPlayerStats(mode=106))
#
self._bindKey("", "f", self.mShuffle)
for i in range(9):
- self._bindKey(ctrl, str(i+1), lambda e, i=i: self.mGotoBookmark(i, confirm=0))
+ self._bindKey(
+ ctrl, str(i+1),
+ lambda e, i=i: self.mGotoBookmark(i, confirm=0))
# undocumented, devel
self._bindKey(ctrl, "End", self.mPlayNextMusic)
@@ -536,20 +739,20 @@ class PysolMenubarTkCommon:
self._bindKey(ctrl, "Up", self.mSelectPrevGameById)
self._bindKey(ctrl, "Down", self.mSelectNextGameById)
-
#
# key binding utility
#
def _bindKey(self, modifier, key, func):
-## if 0 and not modifier and len(key) == 1:
-## self.keybindings[key.lower()] = func
-## self.keybindings[key.upper()] = func
-## return
+ # if 0 and not modifier and len(key) == 1:
+ # self.keybindings[key.lower()] = func
+ # self.keybindings[key.upper()] = func
+ # return
if not modifier and len(key) == 1:
# ignore Ctrl/Shift/Alt
# but don't ignore NumLock (state == 16)
- func = lambda e, func=func: e.state in (0, 16) and func(e)
+ def func(e, f2=func):
+ return e.state in (0, 16) and f2(e)
sequence = "<" + modifier + "KeyPress-" + key + ">"
bind(self.top, sequence, func)
if len(key) == 1 and key != key.upper():
@@ -557,20 +760,19 @@ class PysolMenubarTkCommon:
sequence = "<" + modifier + "KeyPress-" + key + ">"
bind(self.top, sequence, func)
-
def _keyPressHandler(self, event):
r = EVENT_PROPAGATE
if event and self.game:
- ##print event.__dict__
+ # print event.__dict__
if self.game.demo:
# stop the demo by setting self.game.demo.keypress
if event.char: # ignore Ctrl/Shift/etc.
self.game.demo.keypress = event.char
r = EVENT_HANDLED
-## func = self.keybindings.get(event.char)
-## if func and (event.state & ~2) == 0:
-## func(event)
-## r = EVENT_HANDLED
+ # func = self.keybindings.get(event.char)
+ # if func and (event.state & ~2) == 0:
+ # func(event)
+ # r = EVENT_HANDLED
return r
#
@@ -578,12 +780,14 @@ class PysolMenubarTkCommon:
#
def _addSelectGameMenu(self, menu):
- #games = map(self.app.gdb.get, self.app.gdb.getGamesIdSortedByShortName())
+ # games = map(self.app.gdb.get,
+ # self.app.gdb.getGamesIdSortedByShortName())
games = map(self.app.gdb.get, self.app.gdb.getGamesIdSortedByName())
- ##games = tuple(games)
- ###menu = MfxMenu(menu, label="Select &game")
+ # games = tuple(games)
+ # menu = MfxMenu(menu, label="Select &game")
m = "Ctrl-"
- if sys.platform == "darwin": m = "Cmd-"
+ if sys.platform == "darwin":
+ m = "Cmd-"
menu.add_command(label=n_("All &games..."), accelerator=m+"W",
command=self.mSelectGameDialog)
menu.add_command(label=n_("Playable pre&view..."), accelerator=m+"V",
@@ -595,7 +799,8 @@ class PysolMenubarTkCommon:
self.tkopt.gameid)
self._addSelectFrenchGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
self._addSelectMahjonggGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
self._addSelectOrientalGameSubMenu(games, menu, self.mSelectGame,
@@ -605,14 +810,14 @@ class PysolMenubarTkCommon:
self._addSelectCustomGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
menu.add_separator()
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
self._addSelectAllGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
-
def _addSelectGameSubMenu(self, games, menu, select_data,
command, variable):
- ##print select_data
+ # print select_data
need_sep = 0
for label, select_func in select_data:
if label is None:
@@ -634,7 +839,8 @@ class PysolMenubarTkCommon:
return ngames
def _addSelectMahjonggGameSubMenu(self, games, menu, command, variable):
- select_func = lambda gi: gi.si.game_type == GI.GT_MAHJONGG
+ def select_func(gi):
+ return gi.si.game_type == GI.GT_MAHJONGG
mahjongg_games = filter(select_func, games)
if len(mahjongg_games) == 0:
return
@@ -674,7 +880,8 @@ class PysolMenubarTkCommon:
add_menu(g0, c0, c1)
def _addSelectPopularGameSubMenu(self, games, menu, command, variable):
- select_func = lambda gi: gi.si.game_flags & GI.GT_POPULAR
+ def select_func(gi):
+ return gi.si.game_flags & GI.GT_POPULAR
if len(filter(select_func, games)) == 0:
return
data = (n_("&Popular games"), select_func)
@@ -707,7 +914,9 @@ class PysolMenubarTkCommon:
def _addSelectCustomGameSubMenu(self, games, menu, command, variable):
submenu = MfxMenu(menu, label=n_("&Custom games"))
- select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM
+
+ def select_func(gi):
+ return gi.si.game_type == GI.GT_CUSTOM
games = filter(select_func, games)
self.updateGamesMenu(submenu, games)
@@ -716,7 +925,8 @@ class PysolMenubarTkCommon:
n, d = 0, self.cb_max
i = 0
while True:
- if self.progress: self.progress.update(step=1)
+ if self.progress:
+ self.progress.update(step=1)
columnbreak = i > 0 and (i % d) == 0
i += 1
if not games[n:n+d]:
@@ -732,8 +942,8 @@ class PysolMenubarTkCommon:
def _addSelectGameSubSubMenu(self, games, menu, command, variable,
short_name=False):
- ##cb = (25, self.cb_max) [ len(g) > 4 * 25 ]
- ##cb = min(cb, self.cb_max)
+ # cb = (25, self.cb_max) [ len(g) > 4 * 25 ]
+ # cb = min(cb, self.cb_max)
cb = self.cb_max
for i in range(len(games)):
gi = games[i]
@@ -755,7 +965,7 @@ class PysolMenubarTkCommon:
if len(games) == 0:
menu.add_radiobutton(label='', name=None, state='disabled')
elif len(games) > self.cb_max*4:
- games.sort(lambda a, b: cmp(a.name, b.name))
+ games.sort(key=lambda x: x.name)
self._addSelectAllGameSubMenu(games, menu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
@@ -791,15 +1001,18 @@ class PysolMenubarTkCommon:
self.game.setCursor(cursor=self.app.top_cursor)
def mSelectGameDialog(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.game.setCursor(cursor=CURSOR_WATCH)
after_idle(self.top, self.__restoreCursor)
- d = self._calcSelectGameDialog()(self.top, title=_("Select game"),
- app=self.app, gameid=self.game.id)
+ d = self._calcSelectGameDialog()(
+ self.top, title=_("Select game"),
+ app=self.app, gameid=self.game.id)
return self._mSelectGameDialog(d)
def mSelectGameDialogWithPreview(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.game.setCursor(cursor=CURSOR_WATCH)
bookmark = None
if 0:
@@ -808,12 +1021,12 @@ class PysolMenubarTkCommon:
bookmark = self.game.gsaveinfo.bookmarks[-2][0]
del self.game.gsaveinfo.bookmarks[-2]
after_idle(self.top, self.__restoreCursor)
- d = self._calcSelectGameDialogWithPreview()(self.top, title=_("Select game"),
- app=self.app, gameid=self.game.id,
- bookmark=bookmark)
+ d = self._calcSelectGameDialogWithPreview()(
+ self.top, title=_("Select game"),
+ app=self.app, gameid=self.game.id,
+ bookmark=bookmark)
return self._mSelectGameDialog(d)
-
#
# menubar overrides
#
@@ -831,10 +1044,10 @@ class PysolMenubarTkCommon:
in_favor = self.app.game.id in gameids
menu, index, submenu = self.menupath[".menubar.file.addtofavorites"]
menu.entryconfig(index, state=state(not in_favor))
- menu, index, submenu = self.menupath[".menubar.file.removefromfavorites"]
+ menu, index, submenu = \
+ self.menupath[".menubar.file.removefromfavorites"]
menu.entryconfig(index, state=state(in_favor))
-
def updateRecentGamesMenu(self, gameids):
submenu = self.menupath[".menubar.file.recentgames"][2]
games = []
@@ -879,16 +1092,18 @@ class PysolMenubarTkCommon:
cb = int(math.ceil(math.sqrt(len(mbacks))))
for i in range(len(mbacks)):
columnbreak = i > 0 and (i % cb) == 0
- submenu.add_radiobutton(label=mbacks[i].name, image=mbacks[i].menu_image, variable=self.tkopt.cardback, value=i,
- command=self.mOptCardback, columnbreak=columnbreak, indicatoron=0, hidemargin=0)
-
+ submenu.add_radiobutton(
+ label=mbacks[i].name, image=mbacks[i].menu_image,
+ variable=self.tkopt.cardback, value=i,
+ command=self.mOptCardback, columnbreak=columnbreak,
+ indicatoron=0, hidemargin=0)
#
# menu updates
#
def setMenuState(self, state, path):
- #print state, path
+ # print state, path
path = ".menubar." + path
mp = self.menupath.get(path)
menu, index, submenu = mp
@@ -896,7 +1111,7 @@ class PysolMenubarTkCommon:
menu.entryconfig(index, state=s)
def setToolbarState(self, state, path):
- #print state, path
+ # print state, path
s = self._getEnabledState(state)
w = getattr(self.app.toolbar, path + "_button")
w["state"] = s
@@ -907,7 +1122,6 @@ class PysolMenubarTkCommon:
def _setPauseMenu(self, v):
self.tkopt.pause.set(v)
-
#
# menu actions
#
@@ -928,7 +1142,8 @@ class PysolMenubarTkCommon:
self.updateFavoriteGamesMenu()
def mOpen(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
filename = self.game.filename
if filename:
idir, ifile = os.path.split(os.path.normpath(filename))
@@ -942,21 +1157,23 @@ class PysolMenubarTkCommon:
initialdir=idir, initialfile=ifile)
if filename:
filename = os.path.normpath(filename)
- ##filename = os.path.normcase(filename)
+ # filename = os.path.normcase(filename)
if os.path.isfile(filename):
self.game.loadGame(filename)
def mExportCurrentLayout(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
game = self.game
if not self.menustate.save_as:
return
if not game.Solver_Class:
- d = self._calc_MfxMessageDialog()(self.top, title=_('Export game error'),
- text=_('''
+ d = self._calc_MfxMessageDialog()(
+ self.top, title=_('Export game error'),
+ text=_('''
Unsupported game for export.
'''),
- bitmap='error')
+ bitmap='error')
return
filename = game.filename
@@ -970,21 +1187,22 @@ Unsupported game for export.
idir, ifile = os.path.split(os.path.normpath(filename))
if not idir:
idir = self.app.dn.savegames
- ##print self.game.filename, ifile
+ # print self.game.filename, ifile
d = tkFileDialog.SaveAs()
filename = d.show(filetypes=self.FILETYPES,
defaultextension=self.DEFAULTEXTENSION,
initialdir=idir, initialfile=ifile)
if filename:
filename = os.path.normpath(filename)
- ##filename = os.path.normcase(filename)
+ # filename = os.path.normcase(filename)
with open(filename, 'w') as fh:
game = self.game
fh.write(game.Solver_Class(game, self).calcBoardString())
self.updateMenus()
def mSaveAs(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
if not self.menustate.save_as:
return
filename = self.game.filename
@@ -992,7 +1210,7 @@ Unsupported game for export.
filename = self.app.getGameSaveName(self.game.id)
if os.name == "posix":
filename = filename + "-" + self.game.getGameNumber(format=0)
- elif os.path.supports_unicode_filenames: # new in python 2.3
+ elif os.path.supports_unicode_filenames: # new in python 2.3
filename = filename + "-" + self.game.getGameNumber(format=0)
else:
filename = filename + "-01"
@@ -1000,14 +1218,14 @@ Unsupported game for export.
idir, ifile = os.path.split(os.path.normpath(filename))
if not idir:
idir = self.app.dn.savegames
- ##print self.game.filename, ifile
+ # print self.game.filename, ifile
d = tkFileDialog.SaveAs()
filename = d.show(filetypes=self.FILETYPES,
defaultextension=self.DEFAULTEXTENSION,
initialdir=idir, initialfile=ifile)
if filename:
filename = os.path.normpath(filename)
- ##filename = os.path.normcase(filename)
+ # filename = os.path.normcase(filename)
self.game.saveGame(filename)
self.updateMenus()
@@ -1015,120 +1233,146 @@ Unsupported game for export.
if not self.game:
return
if not self.game.pause:
- if self._cancelDrag(): return
+ if self._cancelDrag():
+ return
self.game.doPause()
self.tkopt.pause.set(self.game.pause)
def mOptSoundDialog(self, *args):
- if self._cancelDrag(break_pause=False): return
- d = self._calcSoundOptionsDialog()(self.top, _("Sound settings"), self.app)
+ if self._cancelDrag(break_pause=False):
+ return
+ self._calcSoundOptionsDialog()(
+ self.top, _("Sound settings"), self.app)
self.tkopt.sound.set(self.app.opt.sound)
def mOptAutoFaceUp(self, *args):
- if self._cancelDrag(): return
+ if self._cancelDrag():
+ return
self.app.opt.autofaceup = self.tkopt.autofaceup.get()
if self.app.opt.autofaceup:
self.game.autoPlay()
def mOptAutoDrop(self, *args):
- if self._cancelDrag(): return
+ if self._cancelDrag():
+ return
self.app.opt.autodrop = self.tkopt.autodrop.get()
if self.app.opt.autodrop:
self.game.autoPlay()
def mOptAutoDeal(self, *args):
- if self._cancelDrag(): return
+ if self._cancelDrag():
+ return
self.app.opt.autodeal = self.tkopt.autodeal.get()
if self.app.opt.autodeal:
self.game.autoPlay()
def mOptQuickPlay(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.quickplay = self.tkopt.quickplay.get()
def mOptEnableUndo(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.undo = self.tkopt.undo.get()
self.game.updateMenus()
def mOptEnableBookmarks(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.bookmarks = self.tkopt.bookmarks.get()
self.game.updateMenus()
def mOptEnableHint(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.hint = self.tkopt.hint.get()
self.game.updateMenus()
def mOptEnableShuffle(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shuffle = self.tkopt.shuffle.get()
self.game.updateMenus()
def mOptEnableHighlightPiles(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.highlight_piles = self.tkopt.highlight_piles.get()
self.game.updateMenus()
def mOptEnableHighlightCards(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.highlight_cards = self.tkopt.highlight_cards.get()
self.game.updateMenus()
def mOptEnableHighlightSameRank(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.highlight_samerank = self.tkopt.highlight_samerank.get()
- ##self.game.updateMenus()
+ # self.game.updateMenus()
def mOptEnableHighlightNotMatching(self, *args):
- if self._cancelDrag(break_pause=False): return
- self.app.opt.highlight_not_matching = self.tkopt.highlight_not_matching.get()
- ##self.game.updateMenus()
+ if self._cancelDrag(break_pause=False):
+ return
+ self.app.opt.highlight_not_matching = \
+ self.tkopt.highlight_not_matching.get()
+ # self.game.updateMenus()
def mOptAnimations(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.animations = self.tkopt.animations.get()
def mRedealAnimation(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.redeal_animation = self.tkopt.redeal_animation.get()
def mWinAnimation(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.win_animation = self.tkopt.win_animation.get()
def mOptShadow(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shadow = self.tkopt.shadow.get()
def mOptShade(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shade = self.tkopt.shade.get()
def mOptShrinkFaceDown(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shrink_face_down = self.tkopt.shrink_face_down.get()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
def mOptShadeFilledStacks(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shade_filled_stacks = self.tkopt.shade_filled_stacks.get()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
def mOptMahjonggShowRemoved(self, *args):
- if self._cancelDrag(): return
- self.app.opt.mahjongg_show_removed = self.tkopt.mahjongg_show_removed.get()
- ##self.game.updateMenus()
+ if self._cancelDrag():
+ return
+ self.app.opt.mahjongg_show_removed = \
+ self.tkopt.mahjongg_show_removed.get()
+ # self.game.updateMenus()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
def mOptShisenShowHint(self, *args):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.shisen_show_hint = self.tkopt.shisen_show_hint.get()
- ##self.game.updateMenus()
+ # self.game.updateMenus()
def _updateCardSize(self):
geom = (self.app.canvas.winfo_width(),
@@ -1143,10 +1387,11 @@ Unsupported game for export.
h = int(round(self.app.game.height * self.app.opt.scale_y))
self.app.canvas.setInitialSize(w, h)
self.app.top.wm_geometry("") # cancel user-specified geometry
- ##self.app.top.update_idletasks()
+ # self.app.top.update_idletasks()
def mIncreaseCardset(self, *event):
- if self._cancelDrag(break_pause=True): return
+ if self._cancelDrag(break_pause=True):
+ return
if self.app.opt.scale_x < 4:
self.app.opt.scale_x += 0.1
else:
@@ -1160,7 +1405,8 @@ Unsupported game for export.
self._updateCardSize()
def mDecreaseCardset(self, *event):
- if self._cancelDrag(break_pause=True): return
+ if self._cancelDrag(break_pause=True):
+ return
if self.app.opt.scale_x > 0.5:
self.app.opt.scale_x -= 0.1
else:
@@ -1174,14 +1420,16 @@ Unsupported game for export.
self._updateCardSize()
def mOptAutoScale(self, *event):
- if self._cancelDrag(break_pause=True): return
+ if self._cancelDrag(break_pause=True):
+ return
auto_scale = not self.app.opt.auto_scale
self.app.opt.auto_scale = auto_scale
self.tkopt.auto_scale.set(auto_scale)
self._updateCardSize()
def _mOptCardback(self, index):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
cs = self.app.cardset
old_index = cs.backindex
cs.updateCardback(backindex=index)
@@ -1201,7 +1449,8 @@ Unsupported game for export.
self._mOptCardback(self.app.cardset.backindex + 1)
def mOptChangeTableTile(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
n = self.app.tabletile_manager.len()
if n >= 2:
i = (self.tkopt.tabletile.get() + 1) % n
@@ -1209,14 +1458,16 @@ Unsupported game for export.
self.tkopt.tabletile.set(i)
def mSelectTileDialog(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
key = self.app.tabletile_index
if key <= 0:
- key = self.app.opt.colors['table'] ##.lower()
- d = self._calcSelectTileDialogWithPreview()(self.top, app=self.app,
- title=_("Select table background"),
- manager=self.app.tabletile_manager,
- key=key)
+ key = self.app.opt.colors['table'] # .lower()
+ d = self._calcSelectTileDialogWithPreview()(
+ self.top, app=self.app,
+ title=_("Select table background"),
+ manager=self.app.tabletile_manager,
+ key=key)
if d.status == 0 and d.button == 0:
if isinstance(d.key, str):
tile = self.app.tabletile_manager.get(0)
@@ -1228,27 +1479,29 @@ Unsupported game for export.
self.tkopt.tabletile.set(d.key)
def mOptToolbar(self, *event):
- ##if self._cancelDrag(break_pause=False): return
+ # if self._cancelDrag(break_pause=False): return
self.setToolbarSide(self.tkopt.toolbar.get())
def mOptToolbarStyle(self, *event):
- ##if self._cancelDrag(break_pause=False): return
+ # if self._cancelDrag(break_pause=False): return
self.setToolbarStyle(self.tkopt.toolbar_style.get())
def mOptToolbarCompound(self, *event):
- ##if self._cancelDrag(break_pause=False): return
+ # if self._cancelDrag(break_pause=False): return
self.setToolbarCompound(self.tkopt.toolbar_compound.get())
def mOptToolbarSize(self, *event):
- ##if self._cancelDrag(break_pause=False): return
+ # if self._cancelDrag(break_pause=False): return
self.setToolbarSize(self.tkopt.toolbar_size.get())
def mOptToolbarConfig(self, w):
self.toolbarConfig(w, self.tkopt.toolbar_vars[w].get())
def mOptStatusbar(self, *event):
- if self._cancelDrag(break_pause=False): return
- if not self.app.statusbar: return
+ if self._cancelDrag(break_pause=False):
+ return
+ if not self.app.statusbar:
+ return
side = self.tkopt.statusbar.get()
self.app.opt.statusbar = side
resize = not self.app.opt.save_games_geometry
@@ -1256,12 +1509,15 @@ Unsupported game for export.
self.top.update_idletasks()
def mOptNumCards(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.num_cards = self.tkopt.num_cards.get()
def mOptHelpbar(self, *event):
- if self._cancelDrag(break_pause=False): return
- if not self.app.helpbar: return
+ if self._cancelDrag(break_pause=False):
+ return
+ if not self.app.helpbar:
+ return
show = self.tkopt.helpbar.get()
self.app.opt.helpbar = show
resize = not self.app.opt.save_games_geometry
@@ -1269,39 +1525,45 @@ Unsupported game for export.
self.top.update_idletasks()
def mOptSaveGamesGeometry(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.save_games_geometry = self.tkopt.save_games_geometry.get()
def mOptDemoLogo(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.demo_logo = self.tkopt.demo_logo.get()
def mOptSplashscreen(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.splashscreen = self.tkopt.splashscreen.get()
def mOptMouseType(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.mouse_type = self.tkopt.mouse_type.get()
def mOptMouseUndo(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.mouse_undo = self.tkopt.mouse_undo.get()
def mOptNegativeBottom(self, *event):
- if self._cancelDrag(): return
+ if self._cancelDrag():
+ return
self.app.opt.negative_bottom = self.tkopt.negative_bottom.get()
self.app.updateCardset()
self.game.endGame(bookmark=1)
self.game.quitGame(bookmark=1)
-
#
# toolbar support
#
def setToolbarSide(self, side):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.toolbar = side
self.tkopt.toolbar.set(side) # update radiobutton
resize = not self.app.opt.save_games_geometry
@@ -1309,7 +1571,8 @@ Unsupported game for export.
self.top.update_idletasks()
def setToolbarSize(self, size):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.toolbar_size = size
self.tkopt.toolbar_size.set(size) # update radiobutton
dir = self.app.getToolbarImagesDir()
@@ -1318,17 +1581,19 @@ Unsupported game for export.
self.top.update_idletasks()
def setToolbarStyle(self, style):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.toolbar_style = style
self.tkopt.toolbar_style.set(style) # update radiobutton
dir = self.app.getToolbarImagesDir()
size = self.app.opt.toolbar_size
if self.app.toolbar.updateImages(dir, size):
- ##self.game.updateStatus(player=self.app.opt.player)
+ # self.game.updateStatus(player=self.app.opt.player)
self.top.update_idletasks()
def setToolbarCompound(self, compound):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.toolbar_compound = compound
self.tkopt.toolbar_compound.set(compound) # update radiobutton
if self.app.toolbar.setCompound(compound):
@@ -1350,21 +1615,24 @@ Unsupported game for export.
gameid = write_game(self.app, game=self.game)
else:
gameid = write_game(self.app)
- except Exception, err:
- if DEBUG:
- traceback.print_exc()
- d = self._calc_MfxMessageDialog()(self.top, title=_('Save game error'),
- text=_('''
+ except Exception as err:
+ # if False:
+ # traceback.print_exc()
+ self._calc_MfxMessageDialog()(
+ self.top, title=_('Save game error'),
+ text=_('''
Error while saving game.
%s
''') % str(err),
- bitmap='error')
+ 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
+
+ def select_func(gi):
+ return gi.si.game_type == GI.GT_CUSTOM
games = map(self.app.gdb.get,
self.app.gdb.getGamesIdSortedByName())
games = filter(select_func, games)
@@ -1373,17 +1641,19 @@ Error while saving game.
self.tkopt.gameid.set(gameid)
self._mSelectGame(gameid, force=True)
-
def mWizard(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.wizardDialog()
def mWizardEdit(self, *event):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.wizardDialog(edit=True)
def toolbarConfig(self, w, v):
- if self._cancelDrag(break_pause=False): return
+ if self._cancelDrag(break_pause=False):
+ return
self.app.opt.toolbar_vars[w] = v
self.app.toolbar.config(w, v)
self.top.update_idletasks()
@@ -1396,5 +1666,6 @@ Error while saving game.
if self.game.stackdesc_list:
self.game.deleteStackDesc()
else:
- if self._cancelDrag(break_pause=True): return
+ if self._cancelDrag(break_pause=True):
+ return
self.game.showStackDesc()
diff --git a/pysollib/ui/tktile/selecttree.py b/pysollib/ui/tktile/selecttree.py
index 1943f543..7db11252 100644
--- a/pysollib/ui/tktile/selecttree.py
+++ b/pysollib/ui/tktile/selecttree.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
# ************************************************************************
# * Nodes
@@ -28,23 +28,27 @@
# imports
import tkFont
+
class BaseSelectDialogTreeLeaf:
def drawSymbol(self, x, y, **kw):
if self.tree.nodes.get(self.symbol_id) is not self:
- self.symbol_id = self.tree.canvas.create_image(x, y,
+ self.symbol_id = self.tree.canvas.create_image(
+ x, y,
image=self.tree.data.img[2+(self.key is None)], anchor="nw")
self.tree.nodes[self.symbol_id] = self
class BaseSelectDialogTreeNode:
def __init__(self, tree, text, select_func, expanded=0, parent_node=None):
- self._calc_MfxTreeNode().__init__(self, tree, parent_node, text, key=None, expanded=expanded)
+ self._calc_MfxTreeNode().__init__(
+ self, tree, parent_node, text, key=None, expanded=expanded)
# callable or a tuple/list of MfxTreeNodes
self.select_func = select_func
def drawSymbol(self, x, y, **kw):
if self.tree.nodes.get(self.symbol_id) is not self:
- self.symbol_id = self.tree.canvas.create_image(x, y,
+ self.symbol_id = self.tree.canvas.create_image(
+ x, y,
image=self.tree.data.img[self.expanded], anchor="nw")
self.tree.nodes[self.symbol_id] = self
@@ -52,7 +56,7 @@ class BaseSelectDialogTreeNode:
# cached values
if self.subnodes is not None:
return self.subnodes
- ##print self.whoami()
+ # print self.whoami()
if isinstance(self.select_func, (tuple, list)):
return self.select_func
return self._getContents()
@@ -68,6 +72,7 @@ class BaseSelectDialogTreeNode:
class SelectDialogTreeData:
img = [] # loaded in Application.loadImages3
+
def __init__(self):
self.tree_xview = (0.0, 1.0)
self.tree_yview = (0.0, 1.0)
@@ -95,9 +100,10 @@ class BaseSelectDialogTreeCanvas:
if parent and parent.winfo_screenheight() >= 800:
height = 30 * disty
self.lines = height / disty
- self._calc_MfxTreeInCanvas().__init__(self, parent, self.data.rootnodes,
- width=width, height=height,
- hbar=hbar, vbar=vbar)
+ self._calc_MfxTreeInCanvas().__init__(
+ self, parent, self.data.rootnodes,
+ width=width, height=height,
+ hbar=hbar, vbar=vbar)
self.style.distx = 20
self.style.disty = disty
self.style.width = 16 # width of symbol
@@ -111,12 +117,12 @@ class BaseSelectDialogTreeCanvas:
self.draw()
self.updateSelection(key)
if self.hbar:
- ##print self.data.tree_yview
- ##print self.canvas.xview()
+ # print self.data.tree_yview
+ # print self.canvas.xview()
self.canvas.xview_moveto(self.data.tree_xview[0])
if self.vbar:
- ##print self.data.tree_yview
- ##print self.canvas.yview()
+ # print self.data.tree_yview
+ # print self.canvas.yview()
self.canvas.yview_moveto(self.data.tree_yview[0])
def destroy(self):
@@ -157,4 +163,3 @@ class BaseSelectDialogTreeCanvas:
node.expanded = not node.expanded
self.redraw()
return "break"
-
diff --git a/pysollib/ui/tktile/solverdialog.py b/pysollib/ui/tktile/solverdialog.py
index 8d19f8c6..517c746d 100644
--- a/pysollib/ui/tktile/solverdialog.py
+++ b/pysollib/ui/tktile/solverdialog.py
@@ -1,25 +1,27 @@
import Tkinter
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
from pysollib.ui.tktile.tkconst import EVENT_HANDLED
from pysollib.settings import TITLE
+
class BaseSolverDialog:
def __init__(self, parent, app, **kw):
self.parent = parent
self.app = app
title = TITLE+' - FreeCell Solver'
kw = self.initKw(kw)
- self._calc_MfxDialog().__init__(self, parent, title, kw.resizable, kw.default)
+ self._calc_MfxDialog().__init__(
+ self, parent, title, kw.resizable, kw.default)
top_frame, bottom_frame = self.createFrames(kw)
self.createBitmaps(top_frame, kw)
#
self.solving_methods = {
'A*': 'a-star',
'Breadth-First Search': 'bfs',
- 'Depth-First Search': 'soft-dfs', # default
+ 'Depth-First Search': 'soft-dfs', # default
'A randomized DFS': 'random-dfs',
- ##'"Soft" DFS': 'soft-dfs',
+ # '"Soft" DFS': 'soft-dfs',
}
self.games = {} # key: gamename; value: gameid
@@ -30,8 +32,9 @@ class BaseSolverDialog:
#
row = 0
- self._calcToolkit().Label(frame, text=_('Game:'), anchor='w'
- ).grid(row=row, column=0, sticky='ew', padx=2, pady=2)
+ self._calcToolkit().Label(
+ frame, text=_('Game:'), anchor='w').grid(
+ row=row, column=0, sticky='ew', padx=2, pady=2)
games = app.getGamesForSolver()
gamenames = ['']
for id in games:
@@ -44,8 +47,9 @@ class BaseSolverDialog:
#
row += 1
- self._calcToolkit().Label(frame, text=_('Preset:'), anchor='w'
- ).grid(row=row, column=0, sticky='ew', padx=2, pady=2)
+ self._calcToolkit().Label(
+ frame, text=_('Preset:'), anchor='w').grid(
+ row=row, column=0, sticky='ew', padx=2, pady=2)
presets = app.opt.solver_presets
self.presets = presets
self.preset_var = self._createPresetVar(frame, row)
@@ -54,8 +58,9 @@ class BaseSolverDialog:
row += 1
self.max_iters_var = Tkinter.IntVar()
self.max_iters_var.set(10e4)
- self._calcToolkit().Label(frame, text=_('Max iterations:'), anchor='w'
- ).grid(row=row, column=0, sticky='ew', padx=2, pady=2)
+ self._calcToolkit().Label(
+ frame, text=_('Max iterations:'), anchor='w').grid(
+ row=row, column=0, sticky='ew', padx=2, pady=2)
spin = Tkinter.Spinbox(frame, bg='white', from_=1000, to=10e6,
increment=1000, textvariable=self.max_iters_var)
spin.grid(row=row, column=1, sticky='w', padx=2, pady=2)
@@ -68,27 +73,31 @@ class BaseSolverDialog:
w.grid(row=row, column=0, columnspan=2, sticky='ew', padx=2, pady=2)
#
- label_frame = self._calcToolkit().LabelFrame(top_frame, text=_('Progress'))
+ label_frame = self._calcToolkit().LabelFrame(
+ top_frame, text=_('Progress'))
label_frame.pack(expand=True, fill='both', padx=6, pady=2)
- #label_frame.columnconfigure(0, weight=1)
+ # label_frame.columnconfigure(0, weight=1)
label_frame.columnconfigure(1, weight=1)
#
frow = 0
- self._calcToolkit().Label(label_frame, text=_('Iteration:'), anchor='w'
- ).grid(row=frow, column=0, sticky='ew', padx=4, pady=2)
+ self._calcToolkit().Label(
+ label_frame, text=_('Iteration:'), anchor='w').grid(
+ row=frow, column=0, sticky='ew', padx=4, pady=2)
lb = self._calcToolkit().Label(label_frame, anchor='w')
lb.grid(row=frow, column=1, sticky='ew', padx=4, pady=2)
self.iter_label = lb
frow += 1
- self._calcToolkit().Label(label_frame, text=_('Depth:'), anchor='w'
- ).grid(row=frow, column=0, sticky='ew', padx=4, pady=2)
+ self._calcToolkit().Label(
+ label_frame, text=_('Depth:'), anchor='w').grid(
+ row=frow, column=0, sticky='ew', padx=4, pady=2)
lb = self._calcToolkit().Label(label_frame, anchor='w')
lb.grid(row=frow, column=1, sticky='ew', padx=4, pady=2)
self.depth_label = lb
frow += 1
- self._calcToolkit().Label(label_frame, text=_('Stored-States:'), anchor='w'
- ).grid(row=frow, column=0, sticky='ew', padx=4, pady=2)
+ self._calcToolkit().Label(
+ label_frame, text=_('Stored-States:'), anchor='w').grid(
+ row=frow, column=0, sticky='ew', padx=4, pady=2)
lb = self._calcToolkit().Label(label_frame, anchor='w')
lb.grid(row=frow, column=1, sticky='ew', padx=4, pady=2)
self.states_label = lb
@@ -106,7 +115,6 @@ class BaseSolverDialog:
self.connectGame(self.app.game)
self.mainloop(focus, kw.timeout, transient=False)
-
def mDone(self, button):
if button == 0:
self.startSolving()
@@ -147,7 +155,7 @@ class BaseSolverDialog:
self._reset()
game = self.app.game
- solver = game.Solver_Class(game, self) # create solver instance
+ solver = game.Solver_Class(game, self) # create solver instance
game.solver = solver
preset = self.preset_var.get()
max_iters = self.max_iters_var.get()
@@ -162,7 +170,10 @@ class BaseSolverDialog:
self.result_label['text'] = t
self.play_button.config(state='normal')
else:
- self.result_label['text'] = (_('I could not solve this game.') if solver.solver_state == 'unsolved' else _('Iterations count exceeded (Intractable)'))
+ self.result_label['text'] = \
+ (_('I could not solve this game.')
+ if solver.solver_state == 'unsolved'
+ else _('Iterations count exceeded (Intractable)'))
self.play_button.config(state='disabled')
def startPlay(self):
@@ -185,20 +196,23 @@ class BaseSolverDialog:
self.states_label['text'] = kw['states']
self.top.update_idletasks()
+
solver_dialog = None
+
def connect_game_solver_dialog(game):
try:
solver_dialog.connectGame(game)
except:
pass
+
def destroy_solver_dialog():
global solver_dialog
try:
solver_dialog.destroy()
except:
- ##traceback.print_exc()
+ # traceback.print_exc()
pass
solver_dialog = None
@@ -208,6 +222,5 @@ def reset_solver_dialog():
try:
solver_dialog.reset()
except:
- ##traceback.print_exc()
+ # traceback.print_exc()
pass
-
diff --git a/pysollib/ui/tktile/tkcanvas.py b/pysollib/ui/tktile/tkcanvas.py
index 3ddf7650..c6dc5238 100644
--- a/pysollib/ui/tktile/tkcanvas.py
+++ b/pysollib/ui/tktile/tkcanvas.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,7 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
__all__ = ['MfxCanvasGroup',
'MfxCanvasImage',
@@ -36,7 +36,7 @@ import Canvas
from pysollib.mfxutil import Image, ImageTk
# Toolkit imports
-from pysollib.ui.tktile.tkutil import bind, unbind_destroy, loadImage
+from pysollib.ui.tktile.tkutil import unbind_destroy, loadImage
# ************************************************************************
@@ -49,14 +49,18 @@ class MfxCanvasGroup(Canvas.Group):
# register ourself so that we can unbind from the canvas
assert self.id not in self.canvas.items
self.canvas.items[self.id] = self
+
def addtag(self, tag, option="withtag"):
self.canvas.addtag(tag, option, self.id)
+
def delete(self):
del self.canvas.items[self.id]
Canvas.Group.delete(self)
+
def gettags(self):
return self.canvas.tk.splitlist(self._do("gettags"))
+
class MfxCanvasImage(Canvas.ImageItem):
def __init__(self, canvas, x, y, **kwargs):
self.init_coord = x, y
@@ -69,16 +73,21 @@ class MfxCanvasImage(Canvas.ImageItem):
Canvas.ImageItem.__init__(self, canvas, x, y, **kwargs)
if group:
self.addtag(group)
+
def moveTo(self, x, y):
c = self.coords()
self.move(x - int(c[0]), y - int(c[1]))
+
def show(self):
self.config(state='normal')
+
def hide(self):
self.config(state='hidden')
+
MfxCanvasLine = Canvas.Line
+
class MfxCanvasRectangle(Canvas.Rectangle):
def __init__(self, canvas, *args, **kwargs):
group = None
@@ -89,6 +98,7 @@ class MfxCanvasRectangle(Canvas.Rectangle):
if group:
self.addtag(group)
+
class MfxCanvasText(Canvas.CanvasText):
def __init__(self, canvas, x, y, preview=-1, **kwargs):
self.init_coord = x, y
@@ -108,6 +118,7 @@ class MfxCanvasText(Canvas.CanvasText):
canvas._text_items.append(self)
if group:
self.addtag(group)
+
def moveTo(self, x, y):
dx, dy = x - self.x, y - self.y
self.x, self.y = x, y
@@ -141,10 +152,10 @@ class MfxCanvas(Tkinter.Canvas):
self.bind('', self.setBackgroundImage)
def setBackgroundImage(self, event=None):
- ##print 'setBackgroundImage', self._bg_img
+ # print 'setBackgroundImage', self._bg_img
if not hasattr(self, '_bg_img'):
return
- if not self._bg_img: # solid color
+ if not self._bg_img: # solid color
return
stretch = self._stretch_bg_image
save_aspect = self._save_aspect_bg_image
@@ -161,7 +172,7 @@ class MfxCanvas(Tkinter.Canvas):
image = ImageTk.PhotoImage(im)
else:
image = ImageTk.PhotoImage(self._bg_img)
- else: # not Image
+ else: # not Image
stretch = 0
image = self._bg_img
for id in self.__tiles:
@@ -184,7 +195,8 @@ class MfxCanvas(Tkinter.Canvas):
sw, sh = self._geometry()
for x in range(-self.xmargin, sw, iw):
for y in range(-self.ymargin, sh, ih):
- id = self._x_create("image", x, y, image=image, anchor="nw")
+ id = self._x_create(
+ "image", x, y, image=image, anchor="nw")
self.tag_lower(id) # also see tag_lower above
self.__tiles.append(id)
return 1
@@ -202,7 +214,6 @@ class MfxCanvas(Tkinter.Canvas):
h = max(h, sh)
return w, h
-
#
# top-image support
#
@@ -211,33 +222,28 @@ class MfxCanvas(Tkinter.Canvas):
return Tkinter.Canvas._create(self, itemType, args, kw)
def _create(self, itemType, args, kw):
- ##print "_create:", itemType, args, kw
+ # print "_create:", itemType, args, kw
id = Tkinter.Canvas._create(self, itemType, args, kw)
if self.__tops:
self.tk.call(self._w, "lower", id, self.__tops[0])
return id
def tag_raise(self, id, aboveThis=None):
- ##print "tag_raise:", id, aboveThis
+ # print "tag_raise:", id, aboveThis
if aboveThis is None and self.__tops:
self.tk.call(self._w, "lower", id, self.__tops[0])
else:
self.tk.call(self._w, "raise", id, aboveThis)
def tag_lower(self, id, belowThis=None):
- ##print "tag_lower:", id, belowThis
+ # print "tag_lower:", id, belowThis
if belowThis is None and self.__tiles:
self.tk.call(self._w, "raise", id, self.__tiles[-1])
else:
self.tk.call(self._w, "lower", id, belowThis)
-
- #
- #
- #
-
def setInitialSize(self, width, height, margins=True, scrollregion=True):
- #print 'Canvas.setInitialSize:', width, height, scrollregion
+ # print 'Canvas.setInitialSize:', width, height, scrollregion
if self.preview:
self.config(width=width, height=height,
scrollregion=(0, 0, width, height))
@@ -255,11 +261,6 @@ class MfxCanvas(Tkinter.Canvas):
# no scrolls
self.config(scrollregion=(-dx, -dy, dx, dy))
-
- #
- #
- #
-
# delete all CanvasItems, but keep the background and top tiles
def deleteAllItems(self):
self._text_items = []
@@ -276,18 +277,18 @@ class MfxCanvas(Tkinter.Canvas):
if stack.cards[i].item.tag in current:
return i
else:
-## current = self.find("withtag", "current") # get item ids
-## for i in range(len(stack.cards)):
-## if stack.cards[i].item.id in current:
-## return i
+ # current = self.find("withtag", "current") # get item ids
+ # for i in range(len(stack.cards)):
+ # if stack.cards[i].item.id in current:
+ # return i
if self.preview:
dx, dy = 0, 0
else:
dx, dy = -self.xmargin, -self.ymargin
x = event.x+dx+self.xview()[0]*int(self.cget('width'))
y = event.y+dy+self.yview()[0]*int(self.cget('height'))
- ##x, y = event.x, event.y
- items = list(self.find_overlapping(x,y,x,y))
+ # x, y = event.x, event.y
+ items = list(self.find_overlapping(x, y, x, y))
items.reverse()
for item in items:
for i in range(len(stack.cards)):
@@ -303,16 +304,17 @@ class MfxCanvas(Tkinter.Canvas):
v = []
for i in (1, 3, 5):
v.append(int(c[i:i+2], 16))
- luminance = (0.212671 * v[0] + 0.715160 * v[1] + 0.072169 * v[2]) / 255
- ##print c, ":", v, "luminance", luminance
- color = ("#000000", "#ffffff") [luminance < 0.3]
+ luminance = (0.212671 * v[0] + 0.715160 * v[1] + 0.072169 * v[2]) \
+ / 255
+ # print c, ":", v, "luminance", luminance
+ color = ("#000000", "#ffffff")[luminance < 0.3]
if self._text_color != color:
self._text_color = color
for item in self._text_items:
item.config(fill=self._text_color)
def setTile(self, image, stretch=0, save_aspect=0):
- ##print 'setTile:', image, stretch
+ # print 'setTile:', image, stretch
if image:
if Image:
try:
@@ -352,12 +354,12 @@ class MfxCanvas(Tkinter.Canvas):
return 1
iw, ih = image.width(), image.height()
if cw <= 0:
- ##cw = max(int(self.cget("width")), self.winfo_width())
+ # cw = max(int(self.cget("width")), self.winfo_width())
cw = self.winfo_width()
if ch <= 0:
- ##ch = max(int(self.cget("height")), self.winfo_height())
+ # ch = max(int(self.cget("height")), self.winfo_height())
ch = self.winfo_height()
- ###print iw, ih, cw, ch
+ # print iw, ih, cw, ch
x = (cw-iw)/2-self.xmargin+self.xview()[0]*int(self.cget('width'))
y = (ch-ih)/2-self.ymargin+self.yview()[0]*int(self.cget('height'))
id = self._x_create("image", x, y, image=image, anchor="nw")
@@ -377,7 +379,6 @@ class MfxCanvas(Tkinter.Canvas):
for item in self.items.values():
item.config(state='normal')
-
#
# restricted but fast _bind and _substitute
#
@@ -385,7 +386,7 @@ class MfxCanvas(Tkinter.Canvas):
def _bind(self, what, sequence, func, add, needcleanup=1):
funcid = self._register(func, self._substitute, needcleanup)
cmd = ('%sif {"[%s %s]" == "break"} break\n' %
- (add and '+' or '', funcid, "%x %y"))
+ (add and '+' or '', funcid, "%x %y"))
self.tk.call(what + (sequence, cmd))
return funcid
@@ -401,4 +402,3 @@ class MfxCanvas(Tkinter.Canvas):
except ValueError:
e.y = args[1]
return (e,)
-
diff --git a/pysollib/ui/tktile/tkconst.py b/pysollib/ui/tktile/tkconst.py
index a8790e39..c4bdb490 100644
--- a/pysollib/ui/tktile/tkconst.py
+++ b/pysollib/ui/tktile/tkconst.py
@@ -41,33 +41,33 @@ __all__ = ['EVENT_HANDLED',
# imports
import Tkinter
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import n_
# ************************************************************************
# * constants
# ************************************************************************
-EVENT_HANDLED = "break"
+EVENT_HANDLED = "break"
EVENT_PROPAGATE = None
-CURSOR_DRAG = "hand1"
-CURSOR_WATCH = "watch"
+CURSOR_DRAG = "hand1"
+CURSOR_WATCH = "watch"
CURSOR_DOWN_ARROW = 'sb_down_arrow'
ANCHOR_CENTER = Tkinter.CENTER
-ANCHOR_N = Tkinter.N
-ANCHOR_NW = Tkinter.NW
-ANCHOR_NE = Tkinter.NE
-ANCHOR_S = Tkinter.S
-ANCHOR_SW = Tkinter.SW
-ANCHOR_SE = Tkinter.SE
-ANCHOR_W = Tkinter.W
-ANCHOR_E = Tkinter.E
+ANCHOR_N = Tkinter.N
+ANCHOR_NW = Tkinter.NW
+ANCHOR_NE = Tkinter.NE
+ANCHOR_S = Tkinter.S
+ANCHOR_SW = Tkinter.SW
+ANCHOR_SE = Tkinter.SE
+ANCHOR_W = Tkinter.W
+ANCHOR_E = Tkinter.E
COMPOUNDS = (
- ##(Tkinter.BOTTOM, 'bottom'),
- ##(Tkinter.CENTER, 'center'),
- ##(Tkinter.RIGHT, 'right'),
+ # (Tkinter.BOTTOM, 'bottom'),
+ # (Tkinter.CENTER, 'center'),
+ # (Tkinter.RIGHT, 'right'),
(Tkinter.NONE, n_('Icons only')),
(Tkinter.TOP, n_('Text below icons')),
(Tkinter.LEFT, n_('Text beside icons')),
@@ -89,4 +89,3 @@ TOOLBAR_BUTTONS = (
"quit",
"player",
)
-
diff --git a/pysollib/ui/tktile/tkhtml.py b/pysollib/ui/tktile/tkhtml.py
index bafb331e..f7270082 100644
--- a/pysollib/ui/tktile/tkhtml.py
+++ b/pysollib/ui/tktile/tkhtml.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,10 +19,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
import os
-import htmllib, formatter
+import htmllib
+import formatter
import Tkinter
from pysollib.ui.tktile.tkutil import bind, unbind_destroy
@@ -36,6 +37,7 @@ REMOTE_PROTOCOLS = ("ftp:", "gopher:", "http:", "mailto:", "news:", "telnet:")
# *
# ************************************************************************
+
class tkHTMLWriter(formatter.NullWriter):
def __init__(self, text, viewer, app):
formatter.NullWriter.__init__(self)
@@ -43,7 +45,6 @@ class tkHTMLWriter(formatter.NullWriter):
self.text = text
self.viewer = viewer
- ##
if app:
font = app.getFont("sans")
fixed = app.getFont("fixed")
@@ -52,17 +53,18 @@ class tkHTMLWriter(formatter.NullWriter):
fixed = ('courier', 12)
size = font[1]
sign = 1
- if size < 0: sign = -1
+ if size < 0:
+ sign = -1
self.fontmap = {
- "h1" : (font[0], size + 12*sign, "bold"),
- "h2" : (font[0], size + 8*sign, "bold"),
- "h3" : (font[0], size + 6*sign, "bold"),
- "h4" : (font[0], size + 4*sign, "bold"),
- "h5" : (font[0], size + 2*sign, "bold"),
- "h6" : (font[0], size + 1*sign, "bold"),
- "bold" : (font[0], size, "bold"),
- "italic" : (font[0], size, "italic"),
- "pre" : fixed,
+ "h1": (font[0], size + 12*sign, "bold"),
+ "h2": (font[0], size + 8*sign, "bold"),
+ "h3": (font[0], size + 6*sign, "bold"),
+ "h4": (font[0], size + 4*sign, "bold"),
+ "h5": (font[0], size + 2*sign, "bold"),
+ "h6": (font[0], size + 1*sign, "bold"),
+ "bold": (font[0], size, "bold"),
+ "italic": (font[0], size, "italic"),
+ "pre": fixed,
}
self.text.config(cursor=self.viewer.defcursor, font=font)
@@ -80,6 +82,7 @@ class tkHTMLWriter(formatter.NullWriter):
def __init__(self, viewer, arg):
self.viewer = viewer
self.arg = arg
+
def __call__(self, *args):
self.viewer.updateHistoryXYView()
return self.viewer.display(self.arg)
@@ -90,7 +93,7 @@ class tkHTMLWriter(formatter.NullWriter):
def anchor_bgn(self, href, name, type):
if href:
- ##self.text.update_idletasks() # update display during parsing
+ # self.text.update_idletasks() # update display during parsing
self.anchor = (href, name, type)
self.anchor_mark = self.text.index("insert")
@@ -100,7 +103,8 @@ class tkHTMLWriter(formatter.NullWriter):
tag = "href_" + url
self.text.tag_add(tag, self.anchor_mark, "insert")
self.text.tag_bind(tag, "<1>", self.createCallback(url))
- self.text.tag_bind(tag, "", lambda e: self.anchor_enter(url))
+ self.text.tag_bind(
+ tag, "", lambda e: self.anchor_enter(url))
self.text.tag_bind(tag, "", self.anchor_leave)
fg = 'blue'
u = self.viewer.normurl(url, with_protocol=False)
@@ -121,12 +125,12 @@ class tkHTMLWriter(formatter.NullWriter):
def new_font(self, font):
# end the current font
if self.font:
- ##print "end_font(%s)" % `self.font`
+ # print "end_font(%s)" % `self.font`
self.text.tag_add(self.font, self.font_mark, "insert")
self.font = None
# start the new font
if font:
- ##print "start_font(%s)" % `font`
+ # print "start_font(%s)" % `font`
self.font_mark = self.text.index("insert")
if font[0] in self.fontmap:
self.font = font[0]
@@ -143,9 +147,9 @@ class tkHTMLWriter(formatter.NullWriter):
self.indent = " " * level
def send_label_data(self, data):
- ##self.write(self.indent + data + " ")
+ # self.write(self.indent + data + " ")
self.write(self.indent)
- if data == '*': #
+ if data == '*': #
img = self.viewer.symbols_img.get('disk')
if img:
self.text.image_create(index='insert', image=img,
@@ -194,7 +198,9 @@ class tkHTMLParser(htmllib.HTMLParser):
self.ddpop()
def handle_image(self, src, alt, ismap, align, width, height):
- self.formatter.writer.viewer.showImage(src, alt, ismap, align, width, height)
+ self.formatter.writer.viewer.showImage(
+ src, alt, ismap, align, width, height)
+
class Base_HTMLViewer:
def initBindings(self):
@@ -214,10 +220,12 @@ class Base_HTMLViewer:
unbind_destroy(self.parent)
try:
self.parent.wm_withdraw()
- except: pass
+ except:
+ pass
try:
self.parent.destroy()
- except: pass
+ except:
+ pass
self.parent = None
def _yview(self, *args):
@@ -226,14 +234,19 @@ class Base_HTMLViewer:
def page_up(self, *event):
return self._yview('scroll', -1, 'page')
+
def page_down(self, *event):
return self._yview('scroll', 1, 'page')
+
def unit_up(self, *event):
return self._yview('scroll', -1, 'unit')
+
def unit_down(self, *event):
return self._yview('scroll', 1, 'unit')
+
def scroll_top(self, *event):
return self._yview('moveto', 0)
+
def scroll_bottom(self, *event):
return self._yview('moveto', 1)
@@ -251,7 +264,7 @@ class Base_HTMLViewer:
if relpath and baseurl and not os.path.isabs(url):
h1, t1 = os.path.split(url)
h2, t2 = os.path.split(baseurl)
- if cmp(h1, h2) != 0:
+ if h1 != h2:
url = os.path.join(h2, h1, t1)
url = os.path.normpath(url)
return url
@@ -279,8 +292,8 @@ class Base_HTMLViewer:
# (is this a multithread problem with Tkinter ?)
if self.app and self.app.game:
self.app.game.stopDemo()
- ##self.app.game._cancelDrag()
- ##pass
+ # self.app.game._cancelDrag()
+ # pass
# ftp: and http: would work if we use urllib, but this widget is
# far too limited to display anything but our documentation...
@@ -310,12 +323,15 @@ to open the following URL:
data = file.read()
file.close()
file = None
- except Exception, ex:
- if file: file.close()
- self.errorDialog(_("Unable to service request:\n") + url + "\n\n" + str(ex))
+ except Exception as ex:
+ if file:
+ file.close()
+ self.errorDialog(_("Unable to service request:\n") + url +
+ "\n\n" + str(ex))
return
except:
- if file: file.close()
+ if file:
+ file.close()
self.errorDialog(_("Unable to service request:\n") + url)
return
@@ -325,7 +341,7 @@ to open the following URL:
if add:
self.addHistory(self.url, xview=xview, yview=yview)
- ##print self.history.index, self.history.list
+ # print self.history.index, self.history.list
if self.history.index > 1:
self.backButton.config(state="normal")
else:
@@ -339,11 +355,11 @@ to open the following URL:
self.defcursor = self.handcursor = "watch"
self.text.config(cursor=self.defcursor)
self.text.update_idletasks()
- ##self.frame.config(cursor=self.defcursor)
- ##self.frame.update_idletasks()
+ # self.frame.config(cursor=self.defcursor)
+ # self.frame.update_idletasks()
self.text.config(state="normal")
self.text.delete("1.0", "end")
- ##self.images = {}
+ # self.images = {}
writer = tkHTMLWriter(self.text, self, self.app)
fmt = formatter.AbstractFormatter(writer)
parser = tkHTMLParser(fmt)
@@ -358,17 +374,17 @@ to open the following URL:
self.parent.wm_iconname(parser.title)
self.defcursor, self.handcursor = old_c1, old_c2
self.text.config(cursor=self.defcursor)
- ##self.frame.config(cursor=self.defcursor)
+ # self.frame.config(cursor=self.defcursor)
def addHistory(self, url, xview=0, yview=0):
if url not in self.visited_urls:
self.visited_urls.append(url)
if self.history.index > 0:
u, xv, yv = self.history.list[self.history.index-1]
- if cmp(u, url) == 0:
+ if u == url:
self.updateHistoryXYView()
return
- del self.history.list[self.history.index : ]
+ del self.history.list[self.history.index:]
self.history.list.append((url, xview, yview))
self.history.index = self.history.index + 1
@@ -394,15 +410,16 @@ to open the following URL:
self.display(url, add=0, relpath=0, xview=xview, yview=yview)
def goHome(self, *event):
- if self.home and cmp(self.home, self.url) != 0:
+ if self.home and self.home != self.url:
self.updateHistoryXYView()
self.display(self.home, relpath=0)
def errorDialog(self, msg):
- d = self._calc_MfxMessageDialog()(self.parent, title=TITLE+" HTML Problem",
- text=msg,
- ##bitmap="warning", # FIXME: this interp don't have images
- strings=(_("&OK"),), default=0)
+ self._calc_MfxMessageDialog()(
+ self.parent, title=TITLE+" HTML Problem",
+ text=msg,
+ # bitmap="warning", # FIXME: this interp don't have images
+ strings=(_("&OK"),), default=0)
def getImage(self, fn):
if fn in self.images:
diff --git a/pysollib/ui/tktile/tkutil.py b/pysollib/ui/tktile/tkutil.py
index b2518cd3..2c54a48b 100644
--- a/pysollib/ui/tktile/tkutil.py
+++ b/pysollib/ui/tktile/tkutil.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,24 +19,24 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
__all__ = ['wm_withdraw',
'wm_deiconify',
'wm_map',
'wm_get_geometry',
- #'setTransient',
- #'makeToplevel',
+ # 'setTransient',
+ # 'makeToplevel',
'make_help_toplevel',
'bind',
'unbind_destroy',
'after',
'after_idle',
'after_cancel',
- #'makeImage',
+ # 'makeImage',
'copyImage',
'loadImage',
- #'fillImage',
+ # 'fillImage',
'createImage',
'shadowImage',
'markImage',
@@ -62,9 +62,11 @@ from pysollib.settings import TITLE, WIN_SYSTEM
def wm_withdraw(window):
window.wm_withdraw()
+
def wm_deiconify(window):
window.wm_deiconify()
+
def wm_map(window, maximized=0):
if window.wm_state() != "iconic":
if maximized and WIN_SYSTEM == "win32":
@@ -72,8 +74,10 @@ def wm_map(window, maximized=0):
else:
wm_deiconify(window)
+
__wm_get_geometry_re = re.compile(r"^(\d+)x(\d+)\+([\-]?\d+)\+([\-]?\d+)$")
+
def wm_get_geometry(window):
g = window.wm_geometry()
m = __wm_get_geometry_re.search(g)
@@ -110,22 +114,24 @@ def setTransient(window, parent, relx=None, rely=None, expose=1):
if expose:
window.wm_deiconify()
+
def makeToplevel(parent, title=None):
# Create a Toplevel window.
#
# This is a shortcut for a Toplevel() instantiation plus calls to
# set the title and icon name of the window.
- window = Tkinter.Toplevel(parent) #, class_=TITLE)
- ##window.wm_group(parent)
- ##window.wm_command("")
+ window = Tkinter.Toplevel(parent) # , class_=TITLE)
+ # window.wm_group(parent)
+ # window.wm_command("")
if WIN_SYSTEM == "x11":
window.wm_command("/bin/true")
- ##window.wm_protocol("WM_SAVE_YOURSELF", None)
+ # window.wm_protocol("WM_SAVE_YOURSELF", None)
if title:
window.wm_title(title)
window.wm_iconname(title)
return window
+
def make_help_toplevel(app, title=None):
# Create an independent Toplevel window.
from pysollib.winsystems import init_root_window
@@ -145,8 +151,10 @@ def __getWidgetXY(widget, parent, relx=None, rely=None,
m_x = m_y = 0
m_width, m_height = s_width, s_height
if parent and parent.winfo_ismapped():
- ##print parent.wm_geometry()
- ##print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(), parent.winfo_vrooty()
+ # print parent.wm_geometry()
+ # print parent.winfo_geometry(), parent.winfo_x(), parent.winfo_y(), \
+ # parent.winfo_rootx(), parent.winfo_rooty(), parent.winfo_vrootx(),\
+ # parent.winfo_vrooty()
m_x = m_y = None
if WIN_SYSTEM == "win32":
try:
@@ -158,24 +166,34 @@ def __getWidgetXY(widget, parent, relx=None, rely=None,
m_y = parent.winfo_y()
m_width = parent.winfo_width()
m_height = parent.winfo_height()
- if relx is None: relx = 0.5
- if rely is None: rely = 0.3
+ if relx is None:
+ relx = 0.5
+ if rely is None:
+ rely = 0.3
else:
- if relx is None: relx = 0.5
- if rely is None: rely = 0.5
+ if relx is None:
+ relx = 0.5
+ if rely is None:
+ rely = 0.5
m_x = max(m_x, 0)
m_y = max(m_y, 0)
else:
- if relx is None: relx = 0.5
- if rely is None: rely = 0.3
+ if relx is None:
+ relx = 0.5
+ if rely is None:
+ rely = 0.3
x = m_x + int((m_width - w_width) * relx)
y = m_y + int((m_height - w_height) * rely)
- ##print x, y, w_width, w_height, m_x, m_y, m_width, m_height
+ # print x, y, w_width, w_height, m_x, m_y, m_width, m_height
# make sure the widget is fully on screen
- if x < 0: x = 0
- elif x + w_width + 32 > s_width: x = max(0, (s_width - w_width) / 2)
- if y < 0: y = 0
- elif y + w_height + 32 > s_height: y = max(0, (s_height - w_height) / 2)
+ if x < 0:
+ x = 0
+ elif x + w_width + 32 > s_width:
+ x = max(0, (s_width - w_width) / 2)
+ if y < 0:
+ y = 0
+ elif y + w_height + 32 > s_height:
+ y = max(0, (s_height - w_height) / 2)
return x, y
@@ -186,15 +204,16 @@ def __getWidgetXY(widget, parent, relx=None, rely=None,
__mfx_bindings = {}
__mfx_wm_protocols = ("WM_DELETE_WINDOW", "WM_TAKE_FOCUS", "WM_SAVE_YOURSELF")
+
def bind(widget, sequence, func, add=None):
- ##assert callable(func) # XXX: removed in py3k
+ # assert callable(func) # XXX: removed in py3k
if sequence in __mfx_wm_protocols:
funcid = widget._register(func)
widget.tk.call("wm", "protocol", widget._w, sequence, funcid)
elif add is None:
funcid = widget.bind(sequence, func)
else:
- ##add = add and "+" or ""
+ # add = add and "+" or ""
funcid = widget.bind(sequence, func, add)
k = id(widget)
if k in __mfx_bindings:
@@ -202,24 +221,25 @@ def bind(widget, sequence, func, add=None):
else:
__mfx_bindings[k] = [(sequence, funcid)]
+
def unbind_destroy(widget):
if widget is None:
return
k = id(widget)
if k in __mfx_bindings:
for sequence, funcid in __mfx_bindings[k]:
- ##print widget, sequence, funcid
+ # print widget, sequence, funcid
try:
if sequence in __mfx_wm_protocols:
widget.tk.call("wm", "protocol", widget._w, sequence, "")
- ##widget.deletecommand(funcid)
+ # widget.deletecommand(funcid)
else:
widget.unbind(sequence, funcid)
except Tkinter.TclError:
pass
del __mfx_bindings[k]
- ##for k in __mfx_bindings.keys(): print __mfx_bindings[k]
- ##print len(__mfx_bindings.keys())
+ # for k in __mfx_bindings.keys(): print __mfx_bindings[k]
+ # print len(__mfx_bindings.keys())
# ************************************************************************
@@ -231,9 +251,11 @@ def after(widget, ms, func, *args):
command = widget._tclCommands[-1]
return (timer, command, widget)
+
def after_idle(widget, func, *args):
return after(widget, "idle", func, *args)
+
def after_cancel(t):
if t is not None:
t[2].after_cancel(t[0])
@@ -258,6 +280,7 @@ if Image:
self._pil_image_orig = pil_image_orig
else:
self._pil_image_orig = image
+
def subsample(self, r):
im = self._pil_image
w, h = im.size
@@ -265,10 +288,11 @@ if Image:
im = im.resize((w, h))
im = PIL_Image(image=im)
return im
+
def resize(self, xf, yf):
w, h = self._pil_image_orig.size
w0, h0 = int(w*xf), int(h*yf)
- im = self._pil_image_orig.resize((w0,h0), Image.ANTIALIAS)
+ im = self._pil_image_orig.resize((w0, h0), Image.ANTIALIAS)
return PIL_Image(image=im, pil_image_orig=self._pil_image_orig)
@@ -278,7 +302,7 @@ def makeImage(file=None, data=None, dither=None, alpha=None):
assert file is not None
kw["file"] = file
else:
- #assert data is not None
+ # assert data is not None
kw["data"] = data
if Image:
# use PIL
@@ -290,12 +314,15 @@ def makeImage(file=None, data=None, dither=None, alpha=None):
return Tkinter.PhotoImage(data=data)
return Tkinter.PhotoImage(**kw)
+
loadImage = makeImage
+
def copyImage(image, x, y, width, height):
if Image:
if isinstance(image, PIL_Image):
- return ImageTk.PhotoImage(image._pil_image.crop((x, y, x+width, y+height)))
+ return ImageTk.PhotoImage(
+ image._pil_image.crop((x, y, x+width, y+height)))
dest = Tkinter.PhotoImage(width=width, height=height)
assert dest.width() == width
assert dest.height() == height
@@ -305,6 +332,7 @@ def copyImage(image, x, y, width, height):
assert dest.height() == height
return dest
+
def fillImage(image, fill, outline=None):
if not fill and not outline:
return
@@ -336,6 +364,7 @@ def fillImage(image, fill, outline=None):
assert len(f) == height
image.put(f)
+
def createImage(width, height, fill, outline=None):
image = Tkinter.PhotoImage(width=width, height=height)
assert image.width() == width
@@ -344,6 +373,7 @@ def createImage(width, height, fill, outline=None):
fillImage(image, fill, outline)
return image
+
def shadowImage(image, color='#3896f8', factor=0.3):
if not hasattr(image, '_pil_image'):
return None
@@ -359,6 +389,7 @@ def shadowImage(image, color='#3896f8', factor=0.3):
out = Image.composite(tmp, im, im)
return PIL_Image(image=out)
+
def markImage(image):
assert Image
if 1: # shadow
@@ -370,6 +401,7 @@ def markImage(image):
out = Image.composite(tmp, image, image)
return out
+
def _createBottomImage(image, color='white', backfile=None):
th = 1 # thickness
sh = Image.new('RGBA', image.size, color)
@@ -379,7 +411,7 @@ def _createBottomImage(image, color='white', backfile=None):
tmp = Image.new('RGBA', size, color)
tmp.putalpha(60)
mask = out.resize(size, Image.ANTIALIAS)
- out.paste(tmp, (th,th), mask)
+ out.paste(tmp, (th, th), mask)
if backfile:
back = Image.open(backfile).convert('RGBA')
w0, h0 = back.size
@@ -387,11 +419,12 @@ def _createBottomImage(image, color='white', backfile=None):
a = min(float(w1)/w0, float(h1)/h0)
a = a*0.9
w0, h0 = int(w0*a), int(h0*a)
- back = back.resize((w0,h0), Image.ANTIALIAS)
+ back = back.resize((w0, h0), Image.ANTIALIAS)
x, y = (w1 - w0) / 2, (h1 - h0) / 2
- out.paste(back, (x,y), back)
+ out.paste(back, (x, y), back)
return out
+
def createBottom(maskimage, color='white', backfile=None):
if not hasattr(maskimage, '_pil_image'):
return None
@@ -399,6 +432,7 @@ def createBottom(maskimage, color='white', backfile=None):
out = _createBottomImage(maskimage, color, backfile)
return PIL_Image(image=out)
+
def resizeBottom(image, maskimage, color='white', backfile=None):
maskimage = maskimage._pil_image
out = _createBottomImage(maskimage, color, backfile)
@@ -411,4 +445,3 @@ def resizeBottom(image, maskimage, color='white', backfile=None):
def get_text_width(text, font, root=None):
return Font(root=root, font=font).measure(text)
-
diff --git a/pysollib/ui/tktile/tkwrap.py b/pysollib/ui/tktile/tkwrap.py
index bf6f6141..ab51e9f5 100644
--- a/pysollib/ui/tktile/tkwrap.py
+++ b/pysollib/ui/tktile/tkwrap.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
#
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
@@ -19,17 +19,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
-# ---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------
__all__ = ['TclError',
'MfxRoot']
# imports
import Tkinter
+from pysollib.ui.tktile.tkconst import EVENT_PROPAGATE
TclError = Tkinter.TclError
# PySol imports
-from pysollib.ui.tktile.tkconst import EVENT_PROPAGATE
# ************************************************************************
@@ -43,11 +43,11 @@ class MfxRoot(Tkinter.Tk):
self.app = None
self.wm_protocol('WM_DELETE_WINDOW', self.wmDeleteWindow)
# for interruptible sleep
- #self.sleep_var = Tkinter.IntVar(self)
- #self.sleep_var.set(0)
+ # self.sleep_var = Tkinter.IntVar(self)
+ # self.sleep_var.set(0)
self.sleep_var = 0
self.after_id = None
- ##self.bind('', self._sleepEvent, add=True)
+ # self.bind('', self._sleepEvent, add=True)
def connectApp(self, app):
self.app = app
@@ -56,7 +56,8 @@ class MfxRoot(Tkinter.Tk):
# under Unix an update_idletasks() would be enough...
def busyUpdate(self):
game = None
- if self.app: game = self.app.game
+ if self.app:
+ game = self.app.game
if not game:
self.update()
else:
@@ -71,16 +72,16 @@ class MfxRoot(Tkinter.Tk):
self.after_idle(self.quit)
def screenshot(self, filename):
- ##print 'MfxRoot.screenshot not yet implemented'
+ # print 'MfxRoot.screenshot not yet implemented'
pass
def setCursor(self, cursor):
if 0:
- ## FIXME: this causes ugly resizes !
+ # FIXME: this causes ugly resizes !
Tkinter.Tk.config(self, cursor=cursor)
elif 0:
- ## and this is even worse
- ##print self.children
+ # and this is even worse
+ # print self.children
for v in self.children.values():
v.config(cursor=cursor)
else:
@@ -91,10 +92,10 @@ class MfxRoot(Tkinter.Tk):
#
def sleep(self, seconds):
- #time.sleep(seconds)
+ # time.sleep(seconds)
self.after(int(seconds*1000))
return
- print 'sleep', seconds
+ print('sleep', seconds)
timeout = int(seconds*1000)
self.sleep_var = 0
while timeout > 0:
@@ -104,7 +105,7 @@ class MfxRoot(Tkinter.Tk):
break
self.after(100)
timeout -= 100
- print 'finish sleep'
+ print('finish sleep')
return
if self.after_id:
self.after_cancel(self.after_id)
@@ -115,22 +116,22 @@ class MfxRoot(Tkinter.Tk):
if self.after_id:
self.after_cancel(self.after_id)
self.after_id = None
- print 'finish sleep'
+ print('finish sleep')
def _sleepEvent(self, *args):
return
- print '_sleepEvent', args
+ print('_sleepEvent', args)
self.interruptSleep()
return EVENT_PROPAGATE
def interruptSleep(self):
return
- print 'interruptSleep'
+ print('interruptSleep')
self.update()
self.update_idletasks()
self.sleep_var = 1
- #self.sleep_var.set(0)
- #self.after_idle(self.sleep_var.set, 0)
+ # self.sleep_var.set(0)
+ # self.after_idle(self.sleep_var.set, 0)
#
#
@@ -143,5 +144,5 @@ class MfxRoot(Tkinter.Tk):
if self.app and self.app.menubar:
self.app.menubar.mQuit()
else:
- ##self.after_idle(self.quit)
+ # self.after_idle(self.quit)
pass
diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t
index e6c8c152..2170dcd7 100644
--- a/tests/style/py-flake8.t
+++ b/tests/style/py-flake8.t
@@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /;
# my $cmd = shell_quote( 'flake8', '.' );
my $cmd = shell_quote( 'flake8',
- grep { not($_ eq './pysollib/pysoltk.py' or $_ eq './pysollib/tile/ttk.py') } glob('./pysollib/*.py ./pysollib/[cmpw]*/*.py ./pysollib/tile/*.py') );
+ grep { not($_ eq './pysollib/pysoltk.py' or $_ eq './pysollib/tile/ttk.py') } glob('./pysollib/*.py ./pysollib/[cmpuw]*/*.py ./pysollib/tile/*.py ./pysollib/ui/tktile/*.py') );
# TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );