mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake8
This commit is contained in:
parent
2d3dece823
commit
491caddaee
3 changed files with 162 additions and 105 deletions
|
@ -28,7 +28,7 @@ import os
|
||||||
import Tkinter
|
import Tkinter
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mygettext import _, n_
|
from pysollib.mygettext import _
|
||||||
from pysollib.mfxutil import KwStruct, USE_PIL
|
from pysollib.mfxutil import KwStruct, USE_PIL
|
||||||
from pysollib.util import CARDSET
|
from pysollib.util import CARDSET
|
||||||
from pysollib.resource import CSI
|
from pysollib.resource import CSI
|
||||||
|
@ -54,7 +54,8 @@ class SelectCardsetNode(SelectDialogTreeNode):
|
||||||
contents = []
|
contents = []
|
||||||
for obj in self.tree.data.all_objects:
|
for obj in self.tree.data.all_objects:
|
||||||
if self.select_func(obj):
|
if self.select_func(obj):
|
||||||
node = SelectCardsetLeaf(self.tree, self, text=obj.name, key=obj.index)
|
node = SelectCardsetLeaf(
|
||||||
|
self.tree, self, text=obj.name, key=obj.index)
|
||||||
contents.append(node)
|
contents.append(node)
|
||||||
return contents or self.tree.data.no_contents
|
return contents or self.tree.data.no_contents
|
||||||
|
|
||||||
|
@ -68,59 +69,92 @@ class SelectCardsetData(SelectDialogTreeData):
|
||||||
SelectDialogTreeData.__init__(self)
|
SelectDialogTreeData.__init__(self)
|
||||||
self.all_objects = manager.getAllSortedByName()
|
self.all_objects = manager.getAllSortedByName()
|
||||||
self.all_objects = [obj for obj in self.all_objects if not obj.error]
|
self.all_objects = [obj for obj in self.all_objects if not obj.error]
|
||||||
self.no_contents = [ SelectCardsetLeaf(None, None, _("(no cardsets)"), key=None), ]
|
self.no_contents = [SelectCardsetLeaf(
|
||||||
|
None, None, _("(no cardsets)"), key=None), ]
|
||||||
#
|
#
|
||||||
select_by_type = None
|
select_by_type = None
|
||||||
items = CSI.TYPE.items()
|
items = CSI.TYPE.items()
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(key=lambda x: x[1])
|
||||||
nodes = []
|
nodes = []
|
||||||
for key, name in items:
|
for key, name in items:
|
||||||
if manager.registered_types.get(key):
|
if manager.registered_types.get(key):
|
||||||
nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key == cs.si.type))
|
nodes.append(
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, name, lambda cs, key=key: key == cs.si.type))
|
||||||
if nodes:
|
if nodes:
|
||||||
select_by_type = SelectCardsetNode(None, _("by Type"), tuple(nodes), expanded=1)
|
select_by_type = SelectCardsetNode(
|
||||||
|
None, _("by Type"), tuple(nodes), expanded=1)
|
||||||
#
|
#
|
||||||
select_by_style = None
|
select_by_style = None
|
||||||
items = CSI.STYLE.items()
|
items = CSI.STYLE.items()
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(key=lambda x: x[1])
|
||||||
nodes = []
|
nodes = []
|
||||||
for key, name in items:
|
for key, name in items:
|
||||||
if manager.registered_styles.get(key):
|
if manager.registered_styles.get(key):
|
||||||
nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key in cs.si.styles))
|
nodes.append(
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, name, lambda cs, key=key: key in cs.si.styles))
|
||||||
if nodes:
|
if nodes:
|
||||||
nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.styles))
|
nodes.append(
|
||||||
select_by_style = SelectCardsetNode(None, _("by Style"), tuple(nodes))
|
SelectCardsetNode(
|
||||||
|
None, _("Uncategorized"), lambda cs: not cs.si.styles))
|
||||||
|
select_by_style = SelectCardsetNode(
|
||||||
|
None, _("by Style"), tuple(nodes))
|
||||||
#
|
#
|
||||||
select_by_nationality = None
|
select_by_nationality = None
|
||||||
items = CSI.NATIONALITY.items()
|
items = CSI.NATIONALITY.items()
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(key=lambda x: x[1])
|
||||||
nodes = []
|
nodes = []
|
||||||
for key, name in items:
|
for key, name in items:
|
||||||
if manager.registered_nationalities.get(key):
|
if manager.registered_nationalities.get(key):
|
||||||
nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key in cs.si.nationalities))
|
nodes.append(
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, name,
|
||||||
|
lambda cs, key=key: key in cs.si.nationalities))
|
||||||
if nodes:
|
if nodes:
|
||||||
nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.nationalities))
|
nodes.append(
|
||||||
select_by_nationality = SelectCardsetNode(None, _("by Nationality"), tuple(nodes))
|
SelectCardsetNode(
|
||||||
|
None, _("Uncategorized"),
|
||||||
|
lambda cs: not cs.si.nationalities))
|
||||||
|
select_by_nationality = SelectCardsetNode(
|
||||||
|
None, _("by Nationality"), tuple(nodes))
|
||||||
#
|
#
|
||||||
select_by_date = None
|
select_by_date = None
|
||||||
items = CSI.DATE.items()
|
items = CSI.DATE.items()
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(key=lambda x: x[1])
|
||||||
nodes = []
|
nodes = []
|
||||||
for key, name in items:
|
for key, name in items:
|
||||||
if manager.registered_dates.get(key):
|
if manager.registered_dates.get(key):
|
||||||
nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key in cs.si.dates))
|
nodes.append(
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, name, lambda cs, key=key: key in cs.si.dates))
|
||||||
if nodes:
|
if nodes:
|
||||||
nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.dates))
|
nodes.append(
|
||||||
select_by_date = SelectCardsetNode(None, _("by Date"), tuple(nodes))
|
SelectCardsetNode(
|
||||||
|
None, _("Uncategorized"), lambda cs: not cs.si.dates))
|
||||||
|
select_by_date = SelectCardsetNode(
|
||||||
|
None, _("by Date"), tuple(nodes))
|
||||||
#
|
#
|
||||||
self.rootnodes = filter(None, (
|
self.rootnodes = filter(None, (
|
||||||
SelectCardsetNode(None, _("All Cardsets"), lambda cs: 1, expanded=len(self.all_objects)<=12),
|
SelectCardsetNode(
|
||||||
|
None, _("All Cardsets"),
|
||||||
|
lambda cs: 1, expanded=len(self.all_objects) <= 12),
|
||||||
SelectCardsetNode(None, _("by Size"), (
|
SelectCardsetNode(None, _("by Size"), (
|
||||||
SelectCardsetNode(None, _("Tiny cardsets"), lambda cs: cs.si.size == CSI.SIZE_TINY),
|
SelectCardsetNode(
|
||||||
SelectCardsetNode(None, _("Small cardsets"), lambda cs: cs.si.size == CSI.SIZE_SMALL),
|
None, _("Tiny cardsets"),
|
||||||
SelectCardsetNode(None, _("Medium cardsets"), lambda cs: cs.si.size == CSI.SIZE_MEDIUM),
|
lambda cs: cs.si.size == CSI.SIZE_TINY),
|
||||||
SelectCardsetNode(None, _("Large cardsets"), lambda cs: cs.si.size == CSI.SIZE_LARGE),
|
SelectCardsetNode(
|
||||||
SelectCardsetNode(None, _("XLarge cardsets"), lambda cs: cs.si.size == CSI.SIZE_XLARGE),
|
None, _("Small cardsets"),
|
||||||
|
lambda cs: cs.si.size == CSI.SIZE_SMALL),
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, _("Medium cardsets"),
|
||||||
|
lambda cs: cs.si.size == CSI.SIZE_MEDIUM),
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, _("Large cardsets"),
|
||||||
|
lambda cs: cs.si.size == CSI.SIZE_LARGE),
|
||||||
|
SelectCardsetNode(
|
||||||
|
None, _("XLarge cardsets"),
|
||||||
|
lambda cs: cs.si.size == CSI.SIZE_XLARGE),
|
||||||
), expanded=1),
|
), expanded=1),
|
||||||
select_by_type,
|
select_by_type,
|
||||||
select_by_style,
|
select_by_style,
|
||||||
|
@ -133,15 +167,18 @@ class SelectCardsetByTypeData(SelectDialogTreeData):
|
||||||
def __init__(self, manager, key):
|
def __init__(self, manager, key):
|
||||||
SelectDialogTreeData.__init__(self)
|
SelectDialogTreeData.__init__(self)
|
||||||
self.all_objects = manager.getAllSortedByName()
|
self.all_objects = manager.getAllSortedByName()
|
||||||
self.no_contents = [ SelectCardsetLeaf(None, None, _("(no cardsets)"), key=None), ]
|
self.no_contents = [SelectCardsetLeaf(
|
||||||
|
None, None, _("(no cardsets)"), key=None), ]
|
||||||
#
|
#
|
||||||
items = CSI.TYPE.items()
|
items = CSI.TYPE.items()
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(key=lambda x: x[1])
|
||||||
nodes = []
|
nodes = []
|
||||||
for key, name in items:
|
for key, name in items:
|
||||||
if manager.registered_types.get(key):
|
if manager.registered_types.get(key):
|
||||||
nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key == cs.si.type))
|
nodes.append(SelectCardsetNode(
|
||||||
select_by_type = SelectCardsetNode(None, _("by Type"), tuple(nodes), expanded=1)
|
None, name, lambda cs, key=key: key == cs.si.type))
|
||||||
|
select_by_type = SelectCardsetNode(
|
||||||
|
None, _("by Type"), tuple(nodes), expanded=1)
|
||||||
#
|
#
|
||||||
self.rootnodes = filter(None, (
|
self.rootnodes = filter(None, (
|
||||||
select_by_type,
|
select_by_type,
|
||||||
|
@ -180,7 +217,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
self.key = key
|
self.key = key
|
||||||
self.app = app
|
self.app = app
|
||||||
#padx, pady = kw.padx, kw.pady
|
# padx, pady = kw.padx, kw.pady
|
||||||
padx, pady = 5, 5
|
padx, pady = 5, 5
|
||||||
if self.TreeDataHolder_Class.data is None:
|
if self.TreeDataHolder_Class.data is None:
|
||||||
self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key)
|
self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key)
|
||||||
|
@ -211,9 +248,10 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
left_frame, label=_('Scale X:'),
|
left_frame, label=_('Scale X:'),
|
||||||
from_=0.5, to=4.0, resolution=0.1,
|
from_=0.5, to=4.0, resolution=0.1,
|
||||||
orient='horizontal', variable=var,
|
orient='horizontal', variable=var,
|
||||||
#value=app.opt.scale_x,
|
# value=app.opt.scale_x,
|
||||||
command=self._updateScale)
|
command=self._updateScale)
|
||||||
self.scale_x.grid(row=1, column=0, sticky='ew', padx=padx, pady=pady)
|
self.scale_x.grid(
|
||||||
|
row=1, column=0, sticky='ew', padx=padx, pady=pady)
|
||||||
#
|
#
|
||||||
var = Tkinter.DoubleVar()
|
var = Tkinter.DoubleVar()
|
||||||
var.set(app.opt.scale_y)
|
var.set(app.opt.scale_y)
|
||||||
|
@ -221,9 +259,10 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
left_frame, label=_('Scale Y:'),
|
left_frame, label=_('Scale Y:'),
|
||||||
from_=0.5, to=4.0, resolution=0.1,
|
from_=0.5, to=4.0, resolution=0.1,
|
||||||
orient='horizontal', variable=var,
|
orient='horizontal', variable=var,
|
||||||
#value=app.opt.scale_y,
|
# value=app.opt.scale_y,
|
||||||
command=self._updateScale)
|
command=self._updateScale)
|
||||||
self.scale_y.grid(row=2, column=0, sticky='ew', padx=padx, pady=pady)
|
self.scale_y.grid(
|
||||||
|
row=2, column=0, sticky='ew', padx=padx, pady=pady)
|
||||||
#
|
#
|
||||||
self.auto_scale = Tkinter.BooleanVar()
|
self.auto_scale = Tkinter.BooleanVar()
|
||||||
self.auto_scale.set(app.opt.auto_scale)
|
self.auto_scale.set(app.opt.auto_scale)
|
||||||
|
@ -242,7 +281,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
left_frame, text=_('Preserve aspect ratio'),
|
left_frame, text=_('Preserve aspect ratio'),
|
||||||
variable=self.preserve_aspect,
|
variable=self.preserve_aspect,
|
||||||
takefocus=False,
|
takefocus=False,
|
||||||
#command=self._updateScale
|
# command=self._updateScale
|
||||||
)
|
)
|
||||||
self.aspect_check.grid(row=4, column=0, sticky='w',
|
self.aspect_check.grid(row=4, column=0, sticky='w',
|
||||||
padx=padx, pady=pady)
|
padx=padx, pady=pady)
|
||||||
|
@ -304,9 +343,10 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
cs = self.manager.get(self.tree.selection_key)
|
cs = self.manager.get(self.tree.selection_key)
|
||||||
if not cs:
|
if not cs:
|
||||||
return
|
return
|
||||||
##title = CARDSET+" "+cs.name
|
# title = CARDSET+" "+cs.name
|
||||||
title = CARDSET.capitalize()+" "+cs.name
|
title = CARDSET.capitalize()+" "+cs.name
|
||||||
CardsetInfoDialog(self.top, title=title, cardset=cs, images=self.preview_images)
|
CardsetInfoDialog(
|
||||||
|
self.top, title=title, cardset=cs, images=self.preview_images)
|
||||||
return
|
return
|
||||||
MfxDialog.mDone(self, button)
|
MfxDialog.mDone(self, button)
|
||||||
|
|
||||||
|
@ -337,7 +377,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
return
|
return
|
||||||
names, columns = cs.getPreviewCardNames()
|
names, columns = cs.getPreviewCardNames()
|
||||||
try:
|
try:
|
||||||
#???names, columns = cs.getPreviewCardNames()
|
# ???names, columns = cs.getPreviewCardNames()
|
||||||
for n in names:
|
for n in names:
|
||||||
f = os.path.join(cs.dir, n + cs.ext)
|
f = os.path.join(cs.dir, n + cs.ext)
|
||||||
self.preview_images.append(loadImage(file=f))
|
self.preview_images.append(loadImage(file=f))
|
||||||
|
@ -365,8 +405,8 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
x = x + dx
|
x = x + dx
|
||||||
canvas.config(scrollregion=(0, 0, sx+dx, sy+dy),
|
canvas.config(scrollregion=(0, 0, sx+dx, sy+dy),
|
||||||
width=sx+dx, height=sy+dy)
|
width=sx+dx, height=sy+dy)
|
||||||
#canvas.config(xscrollincrement=dx, yscrollincrement=dy)
|
# canvas.config(xscrollincrement=dx, yscrollincrement=dy)
|
||||||
canvas.event_generate('<Configure>') # update bg image
|
canvas.event_generate('<Configure>') # update bg image
|
||||||
self.preview_key = key
|
self.preview_key = key
|
||||||
self.key = key
|
self.key = key
|
||||||
|
|
||||||
|
@ -380,6 +420,7 @@ class SelectCardsetByTypeDialogWithPreview(SelectCardsetDialogWithPreview):
|
||||||
# * Cardset Info
|
# * Cardset Info
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
|
|
||||||
class CardsetInfoDialog(MfxDialog):
|
class CardsetInfoDialog(MfxDialog):
|
||||||
def __init__(self, parent, title, cardset, images, **kw):
|
def __init__(self, parent, title, cardset, images, **kw):
|
||||||
kw = self.initKw(kw)
|
kw = self.initKw(kw)
|
||||||
|
@ -403,14 +444,14 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
year = str(cardset.year)
|
year = str(cardset.year)
|
||||||
row = 0
|
row = 0
|
||||||
for n, t in (
|
for n, t in (
|
||||||
##('Version:', str(cardset.version)),
|
# ('Version:', str(cardset.version)),
|
||||||
(_('Type:'), CSI.TYPE[cardset.type]),
|
(_('Type:'), CSI.TYPE[cardset.type]),
|
||||||
(_('Styles:'), styles),
|
(_('Styles:'), styles),
|
||||||
(_('Nationality:'), nationalities),
|
(_('Nationality:'), nationalities),
|
||||||
(_('Year:'), year),
|
(_('Year:'), year),
|
||||||
##(_('Number of cards:'), str(cardset.ncards)),
|
# (_('Number of cards:'), str(cardset.ncards)),
|
||||||
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
||||||
):
|
):
|
||||||
if t is not None:
|
if t is not None:
|
||||||
l = Tkinter.Label(info_frame, text=n,
|
l = Tkinter.Label(info_frame, text=n,
|
||||||
anchor='w', justify='left')
|
anchor='w', justify='left')
|
||||||
|
@ -436,7 +477,7 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
info_frame.rowconfigure(row, weight=1)
|
info_frame.rowconfigure(row, weight=1)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
##bg = top_frame["bg"]
|
# bg = top_frame["bg"]
|
||||||
bg = 'white'
|
bg = 'white'
|
||||||
text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word",
|
text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word",
|
||||||
padx=4, width=64, height=16, bg=bg)
|
padx=4, width=64, height=16, bg=bg)
|
||||||
|
@ -460,7 +501,7 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
text_w.config(state="disabled")
|
text_w.config(state="disabled")
|
||||||
#
|
#
|
||||||
focus = self.createButtons(bottom_frame, kw)
|
focus = self.createButtons(bottom_frame, kw)
|
||||||
#focus = text_w
|
# focus = text_w
|
||||||
self.mainloop(focus, kw.timeout)
|
self.mainloop(focus, kw.timeout)
|
||||||
|
|
||||||
def initKw(self, kw):
|
def initKw(self, kw):
|
||||||
|
@ -473,5 +514,3 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
buttonpadx=10, buttonpady=5,
|
buttonpadx=10, buttonpady=5,
|
||||||
)
|
)
|
||||||
return MfxDialog.initKw(self, kw)
|
return MfxDialog.initKw(self, kw)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- mode: python; coding: utf-8; -*-
|
# -*- mode: python; coding: utf-8; -*-
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
# Copyright (C) 2003 Mt. Hood Playing Card Co.
|
# Copyright (C) 2003 Mt. Hood Playing Card Co.
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
|
@ -28,7 +28,7 @@ import Tkinter
|
||||||
from UserList import UserList
|
from UserList import UserList
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mygettext import _, n_
|
from pysollib.mygettext import _
|
||||||
from pysollib.mfxutil import destruct, Struct, KwStruct
|
from pysollib.mfxutil import destruct, Struct, KwStruct
|
||||||
from pysollib.mfxutil import format_time
|
from pysollib.mfxutil import format_time
|
||||||
from pysollib.gamedb import GI
|
from pysollib.gamedb import GI
|
||||||
|
@ -63,7 +63,7 @@ class SelectGameNode(SelectDialogTreeNode):
|
||||||
for gi in self.tree.data.all_games_gi:
|
for gi in self.tree.data.all_games_gi:
|
||||||
if gi and self.select_func is None:
|
if gi and self.select_func is None:
|
||||||
# All games
|
# All games
|
||||||
##name = '%s (%s)' % (gi.name, CSI.TYPE_NAME[gi.category])
|
# name = '%s (%s)' % (gi.name, CSI.TYPE_NAME[gi.category])
|
||||||
name = gi.name
|
name = gi.name
|
||||||
node = SelectGameLeaf(self.tree, self, name, key=gi.id)
|
node = SelectGameLeaf(self.tree, self, name, key=gi.id)
|
||||||
contents.append(node)
|
contents.append(node)
|
||||||
|
@ -82,9 +82,10 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
SelectDialogTreeData.__init__(self)
|
SelectDialogTreeData.__init__(self)
|
||||||
self.all_games_gi = map(app.gdb.get, app.gdb.getGamesIdSortedByName())
|
self.all_games_gi = map(app.gdb.get, app.gdb.getGamesIdSortedByName())
|
||||||
self.no_games = [ SelectGameLeaf(None, None, _("(no games)"), None), ]
|
self.no_games = [SelectGameLeaf(None, None, _("(no games)"), None), ]
|
||||||
#
|
#
|
||||||
s_by_type = s_oriental = s_special = s_original = s_contrib = s_mahjongg = None
|
s_by_type = s_oriental = s_special = s_original = s_contrib = \
|
||||||
|
s_mahjongg = None
|
||||||
g = []
|
g = []
|
||||||
for data in (GI.SELECT_GAME_BY_TYPE,
|
for data in (GI.SELECT_GAME_BY_TYPE,
|
||||||
GI.SELECT_ORIENTAL_GAME_BY_TYPE,
|
GI.SELECT_ORIENTAL_GAME_BY_TYPE,
|
||||||
|
@ -98,7 +99,10 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
continue
|
continue
|
||||||
gg.append(SelectGameNode(None, _(name), select_func))
|
gg.append(SelectGameNode(None, _(name), select_func))
|
||||||
g.append(gg)
|
g.append(gg)
|
||||||
select_mahjongg_game = lambda gi: gi.si.game_type == GI.GT_MAHJONGG
|
|
||||||
|
def select_mahjongg_game(gi):
|
||||||
|
return gi.si.game_type == GI.GT_MAHJONGG
|
||||||
|
|
||||||
gg = None
|
gg = None
|
||||||
if filter(select_mahjongg_game, self.all_games_gi):
|
if filter(select_mahjongg_game, self.all_games_gi):
|
||||||
gg = SelectGameNode(None, _("Mahjongg Games"),
|
gg = SelectGameNode(None, _("Mahjongg Games"),
|
||||||
|
@ -116,14 +120,15 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
if g[3]:
|
if g[3]:
|
||||||
s_original = SelectGameNode(None, _("Original Games"),
|
s_original = SelectGameNode(None, _("Original Games"),
|
||||||
tuple(g[3]))
|
tuple(g[3]))
|
||||||
## if g[4]:
|
# if g[4]:
|
||||||
## s_contrib = SelectGameNode(None, "Contributed Games", tuple(g[4]))
|
# s_contrib = SelectGameNode(None, "Contributed Games", tuple(g[4]))
|
||||||
if g[5]:
|
if g[5]:
|
||||||
s_mahjongg = g[5]
|
s_mahjongg = g[5]
|
||||||
#
|
#
|
||||||
s_by_compatibility, gg = None, []
|
s_by_compatibility, gg = None, []
|
||||||
for name, games in GI.GAMES_BY_COMPATIBILITY:
|
for name, games in GI.GAMES_BY_COMPATIBILITY:
|
||||||
select_func = lambda gi, games=games: gi.id in games
|
def select_func(gi, games=games):
|
||||||
|
return gi.id in games
|
||||||
if name is None or not filter(select_func, self.all_games_gi):
|
if name is None or not filter(select_func, self.all_games_gi):
|
||||||
continue
|
continue
|
||||||
gg.append(SelectGameNode(None, name, select_func))
|
gg.append(SelectGameNode(None, name, select_func))
|
||||||
|
@ -134,9 +139,10 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
#
|
#
|
||||||
s_by_pysol_version, gg = None, []
|
s_by_pysol_version, gg = None, []
|
||||||
for name, games in GI.GAMES_BY_PYSOL_VERSION:
|
for name, games in GI.GAMES_BY_PYSOL_VERSION:
|
||||||
select_func = lambda gi, games=games: gi.id in games
|
def select_func(gi, games=games):
|
||||||
|
return gi.id in games
|
||||||
if name is None or not filter(select_func, self.all_games_gi):
|
if name is None or not filter(select_func, self.all_games_gi):
|
||||||
continue
|
continue
|
||||||
name = _("New games in v. ") + name
|
name = _("New games in v. ") + name
|
||||||
gg.append(SelectGameNode(None, name, select_func))
|
gg.append(SelectGameNode(None, name, select_func))
|
||||||
if 1 and gg:
|
if 1 and gg:
|
||||||
|
@ -144,15 +150,17 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
tuple(gg))
|
tuple(gg))
|
||||||
s_by_inventors, gg = None, []
|
s_by_inventors, gg = None, []
|
||||||
for name, games in GI.GAMES_BY_INVENTORS:
|
for name, games in GI.GAMES_BY_INVENTORS:
|
||||||
select_func = lambda gi, games=games: gi.id in games
|
def select_func(gi, games=games):
|
||||||
|
return gi.id in games
|
||||||
if name is None or not filter(select_func, self.all_games_gi):
|
if name is None or not filter(select_func, self.all_games_gi):
|
||||||
continue
|
continue
|
||||||
gg.append(SelectGameNode(None, name, select_func))
|
gg.append(SelectGameNode(None, name, select_func))
|
||||||
if 1 and gg:
|
if 1 and gg:
|
||||||
s_by_inventors = SelectGameNode(None, _("by Inventors"),
|
s_by_inventors = SelectGameNode(None, _("by Inventors"),
|
||||||
tuple(gg))
|
tuple(gg))
|
||||||
#
|
#
|
||||||
ul_alternate_names = UserList(list(app.gdb.getGamesTuplesSortedByAlternateName()))
|
ul_alternate_names = UserList(
|
||||||
|
list(app.gdb.getGamesTuplesSortedByAlternateName()))
|
||||||
#
|
#
|
||||||
self.rootnodes = filter(None, (
|
self.rootnodes = filter(None, (
|
||||||
SelectGameNode(None, _("All Games"), None),
|
SelectGameNode(None, _("All Games"), None),
|
||||||
|
@ -172,8 +180,9 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK),
|
lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK),
|
||||||
SelectGameNode(None, _('Balanced'),
|
SelectGameNode(None, _('Balanced'),
|
||||||
lambda gi: gi.skill_level == GI.SL_BALANCED),
|
lambda gi: gi.skill_level == GI.SL_BALANCED),
|
||||||
SelectGameNode(None, _('Mostly skill'),
|
SelectGameNode(
|
||||||
lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL),
|
None, _('Mostly skill'),
|
||||||
|
lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL),
|
||||||
SelectGameNode(None, _('Skill only'),
|
SelectGameNode(None, _('Skill only'),
|
||||||
lambda gi: gi.skill_level == GI.SL_SKILL),
|
lambda gi: gi.skill_level == GI.SL_SKILL),
|
||||||
)),
|
)),
|
||||||
|
@ -193,8 +202,10 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
lambda gi: gi.si.ncards == 104),
|
lambda gi: gi.si.ncards == 104),
|
||||||
SelectGameNode(None, _("144 cards"),
|
SelectGameNode(None, _("144 cards"),
|
||||||
lambda gi: gi.si.ncards == 144),
|
lambda gi: gi.si.ncards == 144),
|
||||||
SelectGameNode(None, _("Other number"),
|
SelectGameNode(
|
||||||
lambda gi: gi.si.ncards not in (32, 48, 52, 64, 78, 104, 144)),
|
None, _("Other number"),
|
||||||
|
lambda gi: gi.si.ncards not in (32, 48, 52,
|
||||||
|
64, 78, 104, 144)),
|
||||||
)),
|
)),
|
||||||
SelectGameNode(None, _("by Number of Decks"), (
|
SelectGameNode(None, _("by Number of Decks"), (
|
||||||
SelectGameNode(None, _("1 deck games"),
|
SelectGameNode(None, _("1 deck games"),
|
||||||
|
@ -219,8 +230,9 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
lambda gi: gi.si.redeals == -1),
|
lambda gi: gi.si.redeals == -1),
|
||||||
SelectGameNode(None, "Variable redeals",
|
SelectGameNode(None, "Variable redeals",
|
||||||
lambda gi: gi.si.redeals == -2),
|
lambda gi: gi.si.redeals == -2),
|
||||||
SelectGameNode(None, _("Other number of redeals"),
|
SelectGameNode(
|
||||||
lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)),
|
None, _("Other number of redeals"),
|
||||||
|
lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)),
|
||||||
)),
|
)),
|
||||||
s_by_compatibility,
|
s_by_compatibility,
|
||||||
)),
|
)),
|
||||||
|
@ -231,8 +243,9 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
lambda gi: gi.si.game_flags & GI.GT_CHILDREN),
|
lambda gi: gi.si.game_flags & GI.GT_CHILDREN),
|
||||||
SelectGameNode(None, _("Games with Scoring"),
|
SelectGameNode(None, _("Games with Scoring"),
|
||||||
lambda gi: gi.si.game_flags & GI.GT_SCORE),
|
lambda gi: gi.si.game_flags & GI.GT_SCORE),
|
||||||
SelectGameNode(None, _("Games with Separate Decks"),
|
SelectGameNode(
|
||||||
lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS),
|
None, _("Games with Separate Decks"),
|
||||||
|
lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS),
|
||||||
SelectGameNode(None, _("Open Games (all cards visible)"),
|
SelectGameNode(None, _("Open Games (all cards visible)"),
|
||||||
lambda gi: gi.si.game_flags & GI.GT_OPEN),
|
lambda gi: gi.si.game_flags & GI.GT_OPEN),
|
||||||
SelectGameNode(None, _("Relaxed Variants"),
|
SelectGameNode(None, _("Relaxed Variants"),
|
||||||
|
@ -348,10 +361,10 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
w1, w2 = 220, 480
|
w1, w2 = 220, 480
|
||||||
else:
|
else:
|
||||||
w1, w2 = 200, 300
|
w1, w2 = 200, 300
|
||||||
##print sw, w1, w2
|
# print sw, w1, w2
|
||||||
w2 = max(200, min(w2, 10 + 12*(app.subsampled_images.CARDW+10)))
|
w2 = max(200, min(w2, 10 + 12*(app.subsampled_images.CARDW+10)))
|
||||||
##print sw, w1, w2
|
# print sw, w1, w2
|
||||||
##padx, pady = kw.padx, kw.pady
|
# padx, pady = kw.padx, kw.pady
|
||||||
padx, pady = kw.padx/2, kw.pady/2
|
padx, pady = kw.padx/2, kw.pady/2
|
||||||
# PanedWindow
|
# PanedWindow
|
||||||
paned_window = Tkinter.PanedWindow(top_frame)
|
paned_window = Tkinter.PanedWindow(top_frame)
|
||||||
|
@ -374,7 +387,6 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
ipadx=padx, ipady=pady, sticky='nws')
|
ipadx=padx, ipady=pady, sticky='nws')
|
||||||
# Info
|
# Info
|
||||||
self.info_labels = {}
|
self.info_labels = {}
|
||||||
i = 0
|
|
||||||
for n, t, f, row in (
|
for n, t, f, row in (
|
||||||
('name', _('Name:'), info_frame, 0),
|
('name', _('Name:'), info_frame, 0),
|
||||||
('altnames', _('Alternate names:'), info_frame, 1),
|
('altnames', _('Alternate names:'), info_frame, 1),
|
||||||
|
@ -390,13 +402,13 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
('time', _('Playing time:'), stats_frame, 3),
|
('time', _('Playing time:'), stats_frame, 3),
|
||||||
('moves', _('Moves:'), stats_frame, 4),
|
('moves', _('Moves:'), stats_frame, 4),
|
||||||
('percent', _('% won:'), stats_frame, 5),
|
('percent', _('% won:'), stats_frame, 5),
|
||||||
):
|
):
|
||||||
title_label = Tkinter.Label(f, text=t, justify='left', anchor='w')
|
title_label = Tkinter.Label(f, text=t, justify='left', anchor='w')
|
||||||
title_label.grid(row=row, column=0, sticky='nw')
|
title_label.grid(row=row, column=0, sticky='nw')
|
||||||
text_label = Tkinter.Label(f, justify='left', anchor='w')
|
text_label = Tkinter.Label(f, justify='left', anchor='w')
|
||||||
text_label.grid(row=row, column=1, sticky='nw')
|
text_label.grid(row=row, column=1, sticky='nw')
|
||||||
self.info_labels[n] = (title_label, text_label)
|
self.info_labels[n] = (title_label, text_label)
|
||||||
##info_frame.columnconfigure(1, weight=1)
|
# info_frame.columnconfigure(1, weight=1)
|
||||||
info_frame.rowconfigure(6, weight=1)
|
info_frame.rowconfigure(6, weight=1)
|
||||||
stats_frame.rowconfigure(6, weight=1)
|
stats_frame.rowconfigure(6, weight=1)
|
||||||
# Canvas
|
# Canvas
|
||||||
|
@ -415,7 +427,7 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
self.preview_game = None
|
self.preview_game = None
|
||||||
self.preview_app = None
|
self.preview_app = None
|
||||||
self.updatePreview(gameid, animations=0)
|
self.updatePreview(gameid, animations=0)
|
||||||
##focus = self.tree.frame
|
# focus = self.tree.frame
|
||||||
self.mainloop(focus, kw.timeout)
|
self.mainloop(focus, kw.timeout)
|
||||||
|
|
||||||
def initKw(self, kw):
|
def initKw(self, kw):
|
||||||
|
@ -439,7 +451,7 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
if destroy:
|
if destroy:
|
||||||
self.preview.canvas.delete("all")
|
self.preview.canvas.delete("all")
|
||||||
#
|
#
|
||||||
#for l in self.info_labels.values():
|
# for l in self.info_labels.values():
|
||||||
# l.config(text='')
|
# l.config(text='')
|
||||||
# destruct the game
|
# destruct the game
|
||||||
if self.preview_game:
|
if self.preview_game:
|
||||||
|
@ -467,25 +479,25 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
if self.preview_app is None:
|
if self.preview_app is None:
|
||||||
self.preview_app = Struct(
|
self.preview_app = Struct(
|
||||||
# variables
|
# variables
|
||||||
audio = self.app.audio,
|
audio=self.app.audio,
|
||||||
canvas = canvas,
|
canvas=canvas,
|
||||||
cardset = self.app.cardset.copy(),
|
cardset=self.app.cardset.copy(),
|
||||||
comments = self.app.comments.new(),
|
comments=self.app.comments.new(),
|
||||||
gamerandom = self.app.gamerandom,
|
gamerandom=self.app.gamerandom,
|
||||||
gdb = self.app.gdb,
|
gdb=self.app.gdb,
|
||||||
gimages = self.app.gimages,
|
gimages=self.app.gimages,
|
||||||
images = self.app.subsampled_images,
|
images=self.app.subsampled_images,
|
||||||
menubar = None,
|
menubar=None,
|
||||||
miscrandom = self.app.miscrandom,
|
miscrandom=self.app.miscrandom,
|
||||||
opt = self.app.opt.copy(),
|
opt=self.app.opt.copy(),
|
||||||
startup_opt = self.app.startup_opt,
|
startup_opt=self.app.startup_opt,
|
||||||
stats = self.app.stats.new(),
|
stats=self.app.stats.new(),
|
||||||
top = None,
|
top=None,
|
||||||
top_cursor = self.app.top_cursor,
|
top_cursor=self.app.top_cursor,
|
||||||
toolbar = None,
|
toolbar=None,
|
||||||
# methods
|
# methods
|
||||||
constructGame = self.app.constructGame,
|
constructGame=self.app.constructGame,
|
||||||
getFont = self.app.getFont,
|
getFont=self.app.getFont,
|
||||||
)
|
)
|
||||||
self.preview_app.opt.shadow = 0
|
self.preview_app.opt.shadow = 0
|
||||||
self.preview_app.opt.shade = 0
|
self.preview_app.opt.shade = 0
|
||||||
|
@ -497,7 +509,8 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
if self.preview_game:
|
if self.preview_game:
|
||||||
self.preview_game.endGame()
|
self.preview_game.endGame()
|
||||||
self.preview_game.destruct()
|
self.preview_game.destruct()
|
||||||
##self.top.wm_title("Select Game - " + self.app.getGameTitleName(gameid))
|
# self.top.wm_title("Select Game - " +
|
||||||
|
# self.app.getGameTitleName(gameid))
|
||||||
title = self.app.getGameTitleName(gameid)
|
title = self.app.getGameTitleName(gameid)
|
||||||
self.top.wm_title(_("Playable Preview - ") + title)
|
self.top.wm_title(_("Playable Preview - ") + title)
|
||||||
#
|
#
|
||||||
|
@ -551,13 +564,19 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
GI.SL_SKILL: _('Skill only'),
|
GI.SL_SKILL: _('Skill only'),
|
||||||
}
|
}
|
||||||
skill_level = sl.get(gi.skill_level)
|
skill_level = sl.get(gi.skill_level)
|
||||||
if gi.redeals == -2: redeals = _('variable')
|
if gi.redeals == -2:
|
||||||
elif gi.redeals == -1: redeals = _('unlimited')
|
redeals = _('variable')
|
||||||
else: redeals = str(gi.redeals)
|
elif gi.redeals == -1:
|
||||||
|
redeals = _('unlimited')
|
||||||
|
else:
|
||||||
|
redeals = str(gi.redeals)
|
||||||
# stats
|
# stats
|
||||||
won, lost, time, moves = self.app.stats.getFullStats(self.app.opt.player, gameid)
|
won, lost, time, moves = self.app.stats.getFullStats(
|
||||||
if won+lost > 0: percent = "%.1f" % (100.0*won/(won+lost))
|
self.app.opt.player, gameid)
|
||||||
else: percent = "0.0"
|
if won+lost > 0:
|
||||||
|
percent = "%.1f" % (100.0*won/(won+lost))
|
||||||
|
else:
|
||||||
|
percent = "0.0"
|
||||||
time = format_time(time)
|
time = format_time(time)
|
||||||
moves = str(round(moves, 1))
|
moves = str(round(moves, 1))
|
||||||
for n, t in (
|
for n, t in (
|
||||||
|
@ -574,7 +593,7 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
('time', time),
|
('time', time),
|
||||||
('moves', moves),
|
('moves', moves),
|
||||||
('percent', percent),
|
('percent', percent),
|
||||||
):
|
):
|
||||||
title_label, text_label = self.info_labels[n]
|
title_label, text_label = self.info_labels[n]
|
||||||
if t in ('', None):
|
if t in ('', None):
|
||||||
title_label.grid_remove()
|
title_label.grid_remove()
|
||||||
|
@ -583,4 +602,3 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
title_label.grid()
|
title_label.grid()
|
||||||
text_label.grid()
|
text_label.grid()
|
||||||
text_label.config(text=t)
|
text_label.config(text=t)
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ my %skip =
|
||||||
|
|
||||||
# my $cmd = shell_quote( 'flake8', '.' );
|
# my $cmd = shell_quote( 'flake8', '.' );
|
||||||
my $cmd = shell_quote( 'flake8',
|
my $cmd = shell_quote( 'flake8',
|
||||||
grep { not exists $skip{$_} } glob('./*.py ./scripts/*.py ./tests/board_gen/*.py ./pysollib/*.py ./pysollib/[cmgpuw]*/{*/*.py,*.py} ./pysollib/tile/*.py ./pysollib/tk/[a-p]*.py ./pysollib/ui/tktile/*.py') );
|
grep { not exists $skip{$_} } glob('./*.py ./scripts/*.py ./tests/board_gen/*.py ./pysollib/*.py ./pysollib/[cmgpuw]*/{*/*.py,*.py} ./pysollib/tile/*.py ./pysollib/tk/{[a-p],selectcardset,selectgame}*.py ./pysollib/ui/tktile/*.py') );
|
||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
||||||
|
|
Loading…
Add table
Reference in a new issue