mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake8
This commit is contained in:
parent
85e604b912
commit
6eebf8729d
8 changed files with 248 additions and 159 deletions
|
@ -29,7 +29,7 @@ import Tkinter
|
||||||
import ttk
|
import ttk
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -55,7 +55,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
|
||||||
|
|
||||||
|
@ -69,60 +70,94 @@ 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(
|
||||||
SelectCardsetNode(None, _("by Size"), (
|
None, _("All Cardsets"),
|
||||||
SelectCardsetNode(None, _("Tiny cardsets"), lambda cs: cs.si.size == CSI.SIZE_TINY),
|
lambda cs: 1, expanded=len(self.all_objects) <= 12),
|
||||||
SelectCardsetNode(None, _("Small cardsets"), lambda cs: cs.si.size == CSI.SIZE_SMALL),
|
SelectCardsetNode(
|
||||||
SelectCardsetNode(None, _("Medium cardsets"), lambda cs: cs.si.size == CSI.SIZE_MEDIUM),
|
None, _("by Size"),
|
||||||
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, _("Tiny cardsets"),
|
||||||
), expanded=1),
|
lambda cs: cs.si.size == CSI.SIZE_TINY),
|
||||||
|
SelectCardsetNode(
|
||||||
|
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),
|
||||||
select_by_type,
|
select_by_type,
|
||||||
select_by_style,
|
select_by_style,
|
||||||
select_by_date,
|
select_by_date,
|
||||||
|
@ -134,15 +169,19 @@ 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(
|
||||||
select_by_type = SelectCardsetNode(None, _("by Type"), tuple(nodes), expanded=1)
|
SelectCardsetNode(
|
||||||
|
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,
|
||||||
|
@ -182,7 +221,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
self.key = key
|
self.key = key
|
||||||
self.app = app
|
self.app = app
|
||||||
self.cardset_values = None
|
self.cardset_values = None
|
||||||
#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)
|
||||||
|
@ -214,7 +253,8 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
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)
|
||||||
|
@ -224,7 +264,8 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
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)
|
||||||
|
@ -243,7 +284,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='ew',
|
self.aspect_check.grid(row=4, column=0, sticky='ew',
|
||||||
padx=padx, pady=pady)
|
padx=padx, pady=pady)
|
||||||
|
@ -279,8 +320,8 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
else:
|
else:
|
||||||
s = (_("&Info..."), 10)
|
s = (_("&Info..."), 10)
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(kw,
|
||||||
strings = (s, 'sep',
|
strings=(s, 'sep',
|
||||||
_("&OK"), _("&Cancel"),),
|
_("&OK"), _("&Cancel"),),
|
||||||
default=0,
|
default=0,
|
||||||
resizable=True,
|
resizable=True,
|
||||||
)
|
)
|
||||||
|
@ -308,7 +349,7 @@ 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
|
||||||
d = CardsetInfoDialog(self.top, title=title, cardset=cs,
|
d = CardsetInfoDialog(self.top, title=title, cardset=cs,
|
||||||
images=self.preview_images)
|
images=self.preview_images)
|
||||||
|
@ -343,7 +384,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))
|
||||||
|
@ -371,8 +412,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
|
||||||
|
|
||||||
|
@ -386,6 +427,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)
|
||||||
|
@ -411,14 +453,14 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
year = str(cardset.year)
|
year = str(cardset.year)
|
||||||
frow = 0
|
frow = 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 = ttk.Label(info_frame, text=n,
|
l = ttk.Label(info_frame, text=n,
|
||||||
anchor='w', justify='left')
|
anchor='w', justify='left')
|
||||||
|
@ -432,11 +474,11 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
from random import choice
|
from random import choice
|
||||||
im = choice(images)
|
im = choice(images)
|
||||||
f = os.path.join(cardset.dir, cardset.backname)
|
f = os.path.join(cardset.dir, cardset.backname)
|
||||||
self.back_image = loadImage(file=f) # store the image
|
self.back_image = loadImage(file=f) # store the image
|
||||||
l = ttk.Label(info_frame, image=im, padding=5)
|
l = ttk.Label(info_frame, image=im, padding=5)
|
||||||
l.grid(row=0, column=2, rowspan=frow+1, sticky='ne')
|
l.grid(row=0, column=2, rowspan=frow+1, sticky='ne')
|
||||||
l = ttk.Label(info_frame, image=self.back_image,
|
l = ttk.Label(info_frame, image=self.back_image,
|
||||||
padding=(0,5,5,5)) # left margin = 0
|
padding=(0, 5, 5, 5)) # left margin = 0
|
||||||
l.grid(row=0, column=3, rowspan=frow+1, sticky='ne')
|
l.grid(row=0, column=3, rowspan=frow+1, sticky='ne')
|
||||||
|
|
||||||
info_frame.columnconfigure(2, weight=1)
|
info_frame.columnconfigure(2, weight=1)
|
||||||
|
@ -456,7 +498,7 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
from_=5, to=40, resolution=1,
|
from_=5, to=40, resolution=1,
|
||||||
orient='horizontal', variable=var,
|
orient='horizontal', variable=var,
|
||||||
value=cardset.CARD_XOFFSET,
|
value=cardset.CARD_XOFFSET,
|
||||||
#command=self._updateScale
|
# command=self._updateScale
|
||||||
)
|
)
|
||||||
self.x_offset.grid(row=0, column=0, sticky='ew',
|
self.x_offset.grid(row=0, column=0, sticky='ew',
|
||||||
padx=padx, pady=pady)
|
padx=padx, pady=pady)
|
||||||
|
@ -466,13 +508,13 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
from_=5, to=40, resolution=1,
|
from_=5, to=40, resolution=1,
|
||||||
orient='horizontal', variable=var,
|
orient='horizontal', variable=var,
|
||||||
value=cardset.CARD_YOFFSET,
|
value=cardset.CARD_YOFFSET,
|
||||||
#command=self._updateScale
|
# command=self._updateScale
|
||||||
)
|
)
|
||||||
self.y_offset.grid(row=1, column=0, sticky='ew',
|
self.y_offset.grid(row=1, column=0, sticky='ew',
|
||||||
padx=padx, pady=pady)
|
padx=padx, pady=pady)
|
||||||
row += 1
|
row += 1
|
||||||
|
|
||||||
##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)
|
||||||
|
@ -496,12 +538,12 @@ 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):
|
||||||
if USE_PIL:
|
if USE_PIL:
|
||||||
strings = (_("&Save"),_("&Cancel"))
|
strings = (_("&Save"), _("&Cancel"))
|
||||||
else:
|
else:
|
||||||
strings = (_("&OK"),)
|
strings = (_("&OK"),)
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(kw,
|
||||||
|
@ -518,4 +560,3 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
else:
|
else:
|
||||||
self.cardset_values = None
|
self.cardset_values = None
|
||||||
MfxDialog.mDone(self, button)
|
MfxDialog.mDone(self, button)
|
||||||
|
|
||||||
|
|
|
@ -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 ttk
|
||||||
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
|
||||||
|
@ -62,7 +62,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)
|
||||||
|
@ -81,9 +81,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,
|
||||||
|
@ -97,7 +98,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"),
|
||||||
|
@ -115,14 +119,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))
|
||||||
|
@ -132,9 +137,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:
|
||||||
|
@ -142,15 +148,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, expanded=0),
|
SelectGameNode(None, _("All Games"), None, expanded=0),
|
||||||
|
@ -170,8 +178,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),
|
||||||
)),
|
)),
|
||||||
|
@ -191,8 +200,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"),
|
||||||
|
@ -215,10 +226,11 @@ class SelectGameData(SelectDialogTreeData):
|
||||||
lambda gi: gi.si.redeals == 3),
|
lambda gi: gi.si.redeals == 3),
|
||||||
SelectGameNode(None, _("Unlimited redeals"),
|
SelectGameNode(None, _("Unlimited redeals"),
|
||||||
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,
|
||||||
)),
|
)),
|
||||||
|
@ -229,8 +241,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"),
|
||||||
|
@ -345,11 +358,11 @@ 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
|
||||||
padx, pady = 4, 4
|
padx, pady = 4, 4
|
||||||
# PanedWindow
|
# PanedWindow
|
||||||
paned_window = ttk.PanedWindow(top_frame, orient='horizontal')
|
paned_window = ttk.PanedWindow(top_frame, orient='horizontal')
|
||||||
|
@ -372,7 +385,6 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
ipadx=4, ipady=4, sticky='nws')
|
ipadx=4, ipady=4, 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),
|
||||||
|
@ -388,13 +400,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 = ttk.Label(f, text=t, justify='left', anchor='w')
|
title_label = ttk.Label(f, text=t, justify='left', anchor='w')
|
||||||
title_label.grid(row=row, column=0, sticky='nw', padx=4)
|
title_label.grid(row=row, column=0, sticky='nw', padx=4)
|
||||||
text_label = ttk.Label(f, justify='left', anchor='w')
|
text_label = ttk.Label(f, justify='left', anchor='w')
|
||||||
text_label.grid(row=row, column=1, sticky='nw', padx=4)
|
text_label.grid(row=row, column=1, sticky='nw', padx=4)
|
||||||
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
|
||||||
|
@ -413,7 +425,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):
|
||||||
|
@ -438,7 +450,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:
|
||||||
|
@ -466,25 +478,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
|
||||||
|
@ -496,7 +508,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)
|
||||||
#
|
#
|
||||||
|
@ -550,13 +563,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 (
|
||||||
|
@ -573,7 +592,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()
|
||||||
|
@ -582,4 +601,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)
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,13 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
|
import sys
|
||||||
import Tkinter
|
import Tkinter
|
||||||
import ttk
|
import ttk
|
||||||
import tkColorChooser
|
import tkColorChooser
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mygettext import _, n_
|
from pysollib.mygettext import _
|
||||||
from pysollib.mfxutil import KwStruct
|
from pysollib.mfxutil import KwStruct
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
|
@ -37,6 +38,10 @@ from selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode
|
||||||
from selecttree import SelectDialogTreeData, SelectDialogTreeCanvas
|
from selecttree import SelectDialogTreeData, SelectDialogTreeCanvas
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info > (3,):
|
||||||
|
basestring = str
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * Nodes
|
# * Nodes
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
@ -50,7 +55,8 @@ class SelectTileNode(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 = SelectTileLeaf(self.tree, self, text=obj.name, key=obj.index)
|
node = SelectTileLeaf(
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -64,9 +70,11 @@ class SelectTileData(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.all_objects = [tile for tile in self.all_objects if tile.index > 0 and tile.filename]
|
self.all_objects = [tile for tile in self.all_objects
|
||||||
self.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ]
|
if tile.index > 0 and tile.filename]
|
||||||
e1 = isinstance(key, str) or len(self.all_objects) <=17
|
self.no_contents = [SelectTileLeaf(
|
||||||
|
None, None, _("(no tiles)"), key=None), ]
|
||||||
|
e1 = isinstance(key, str) or len(self.all_objects) <= 17
|
||||||
e2 = 1
|
e2 = 1
|
||||||
self.rootnodes = (
|
self.rootnodes = (
|
||||||
SelectTileNode(None, _("Solid Colors"), (
|
SelectTileNode(None, _("Solid Colors"), (
|
||||||
|
@ -77,7 +85,9 @@ class SelectTileData(SelectDialogTreeData):
|
||||||
SelectTileLeaf(None, None, _("Orange"), key="#f79600"),
|
SelectTileLeaf(None, None, _("Orange"), key="#f79600"),
|
||||||
SelectTileLeaf(None, None, _("Teal"), key="#008286"),
|
SelectTileLeaf(None, None, _("Teal"), key="#008286"),
|
||||||
), expanded=e1),
|
), expanded=e1),
|
||||||
SelectTileNode(None, _("All Backgrounds"), lambda tile: 1, expanded=e2),
|
SelectTileNode(
|
||||||
|
None, _("All Backgrounds"),
|
||||||
|
lambda tile: 1, expanded=e2),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,4 +209,3 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
if self.preview.setTile(self.app, key):
|
if self.preview.setTile(self.app, key):
|
||||||
return
|
return
|
||||||
self.preview_key = -1
|
self.preview_key = -1
|
||||||
|
|
||||||
|
|
|
@ -26,29 +26,40 @@ __all__ = ['SelectDialogTreeData']
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas
|
from tktree import MfxTreeLeaf, MfxTreeNode, MfxTreeInCanvas
|
||||||
|
|
||||||
from pysollib.ui.tktile.selecttree import BaseSelectDialogTreeLeaf, BaseSelectDialogTreeNode, SelectDialogTreeData, BaseSelectDialogTreeCanvas
|
from pysollib.ui.tktile.selecttree import BaseSelectDialogTreeLeaf, \
|
||||||
|
BaseSelectDialogTreeNode, SelectDialogTreeData, \
|
||||||
|
BaseSelectDialogTreeCanvas
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * Nodes
|
# * Nodes
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
|
|
||||||
class SelectDiagCommon:
|
class SelectDiagCommon:
|
||||||
def _calc_MfxTreeNode(self):
|
def _calc_MfxTreeNode(self):
|
||||||
return MfxTreeNode
|
return MfxTreeNode
|
||||||
|
|
||||||
def _calc_MfxTreeInCanvas(self):
|
def _calc_MfxTreeInCanvas(self):
|
||||||
return MfxTreeInCanvas
|
return MfxTreeInCanvas
|
||||||
|
|
||||||
def _calc_MfxTreeLeaf(self):
|
def _calc_MfxTreeLeaf(self):
|
||||||
return MfxTreeLeaf
|
return MfxTreeLeaf
|
||||||
|
|
||||||
class SelectDialogTreeLeaf(SelectDiagCommon, BaseSelectDialogTreeLeaf, MfxTreeLeaf):
|
|
||||||
|
class SelectDialogTreeLeaf(SelectDiagCommon,
|
||||||
|
BaseSelectDialogTreeLeaf, MfxTreeLeaf):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class SelectDialogTreeNode(SelectDiagCommon, BaseSelectDialogTreeNode, MfxTreeNode):
|
|
||||||
|
class SelectDialogTreeNode(SelectDiagCommon,
|
||||||
|
BaseSelectDialogTreeNode, MfxTreeNode):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# * Canvas that shows the tree (left side)
|
# * Canvas that shows the tree (left side)
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
class SelectDialogTreeCanvas(SelectDiagCommon, BaseSelectDialogTreeCanvas, MfxTreeInCanvas):
|
|
||||||
|
class SelectDialogTreeCanvas(SelectDiagCommon,
|
||||||
|
BaseSelectDialogTreeCanvas, MfxTreeInCanvas):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------##
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
#'SolverDialog',
|
# 'SolverDialog',
|
||||||
'create_solver_dialog',
|
'create_solver_dialog',
|
||||||
'connect_game_solver_dialog',
|
'connect_game_solver_dialog',
|
||||||
'destroy_solver_dialog',
|
'destroy_solver_dialog',
|
||||||
|
@ -30,16 +30,17 @@ __all__ = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import ttk
|
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mygettext import _, n_
|
from pysollib.mygettext import _
|
||||||
from pysollib.mfxutil import KwStruct
|
from pysollib.mfxutil import KwStruct
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from pysollib.tile.basetilemfxdialog import BaseTileMfxDialog
|
from pysollib.tile.basetilemfxdialog import BaseTileMfxDialog
|
||||||
from tkwidget import PysolCombo
|
from tkwidget import PysolCombo
|
||||||
from pysollib.ui.tktile.solverdialog import BaseSolverDialog, solver_dialog, connect_game_solver_dialog, destroy_solver_dialog, reset_solver_dialog
|
from pysollib.ui.tktile.solverdialog import BaseSolverDialog, \
|
||||||
|
connect_game_solver_dialog, destroy_solver_dialog, solver_dialog, \
|
||||||
|
reset_solver_dialog
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
@ -59,12 +60,14 @@ class SolverDialog(BaseSolverDialog, BaseTileMfxDialog):
|
||||||
cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
|
cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
|
||||||
cb.current(0)
|
cb.current(0)
|
||||||
return cb
|
return cb
|
||||||
|
|
||||||
def _createShowProgressButton(self, frame):
|
def _createShowProgressButton(self, frame):
|
||||||
return self._calcToolkit().Checkbutton(frame, variable=self.progress_var,
|
return self._calcToolkit().Checkbutton(
|
||||||
text=_('Show progress'))
|
frame, variable=self.progress_var,
|
||||||
|
text=_('Show progress'))
|
||||||
|
|
||||||
def initKw(self, kw):
|
def initKw(self, kw):
|
||||||
strings=[_('&Start'), _('&Play'), _('&New'), 'sep', _('&Close'),]
|
strings = [_('&Start'), _('&Play'), _('&New'), 'sep', _('&Close'), ]
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(kw,
|
||||||
strings=strings,
|
strings=strings,
|
||||||
default=0,
|
default=0,
|
||||||
|
@ -83,6 +86,8 @@ class SolverDialog(BaseSolverDialog, BaseTileMfxDialog):
|
||||||
self.play_button.config(state='disabled')
|
self.play_button.config(state='disabled')
|
||||||
|
|
||||||
|
|
||||||
|
solver_dialog = solver_dialog
|
||||||
|
|
||||||
|
|
||||||
def create_solver_dialog(parent, game):
|
def create_solver_dialog(parent, game):
|
||||||
global solver_dialog
|
global solver_dialog
|
||||||
|
@ -90,6 +95,5 @@ def create_solver_dialog(parent, game):
|
||||||
solver_dialog.top.wm_deiconify()
|
solver_dialog.top.wm_deiconify()
|
||||||
solver_dialog.top.tkraise()
|
solver_dialog.top.tkraise()
|
||||||
except:
|
except:
|
||||||
##traceback.print_exc()
|
# traceback.print_exc()
|
||||||
solver_dialog = SolverDialog(parent, game)
|
solver_dialog = SolverDialog(parent, game)
|
||||||
|
|
||||||
|
|
|
@ -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/>.
|
||||||
#
|
#
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
__all__ = ['SoundOptionsDialog']
|
__all__ = ['SoundOptionsDialog']
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import Tkinter
|
||||||
import ttk
|
import ttk
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from pysollib.mygettext import _, n_
|
from pysollib.mygettext import _
|
||||||
from pysollib.mfxutil import KwStruct
|
from pysollib.mfxutil import KwStruct
|
||||||
from pysollib.settings import TITLE
|
from pysollib.settings import TITLE
|
||||||
from pysollib.pysolaudio import pysolsoundserver
|
from pysollib.pysolaudio import pysolsoundserver
|
||||||
|
@ -109,13 +109,13 @@ class SoundOptionsDialog(MfxDialog):
|
||||||
command=self.mOptSoundDirectX)
|
command=self.mOptSoundDirectX)
|
||||||
w.grid(row=row, column=0, columnspan=2, sticky='ew')
|
w.grid(row=row, column=0, columnspan=2, sticky='ew')
|
||||||
#
|
#
|
||||||
if app.audio.CAN_PLAY_MUSIC: # and app.startup_opt.sound_mode > 0:
|
if app.audio.CAN_PLAY_MUSIC: # and app.startup_opt.sound_mode > 0:
|
||||||
row += 1
|
row += 1
|
||||||
ttk.Label(frame, text=_('Sample volume:'), anchor='w'
|
ttk.Label(frame, text=_('Sample volume:'), anchor='w'
|
||||||
).grid(row=row, column=0, sticky='ew')
|
).grid(row=row, column=0, sticky='ew')
|
||||||
w = PysolScale(frame, from_=0, to=128, resolution=1,
|
w = PysolScale(frame, from_=0, to=128, resolution=1,
|
||||||
orient='horizontal', takefocus=0,
|
orient='horizontal', takefocus=0,
|
||||||
length="3i", #label=_('Sample volume'),
|
length="3i", # label=_('Sample volume'),
|
||||||
variable=self.sample_volume)
|
variable=self.sample_volume)
|
||||||
w.grid(row=row, column=1, sticky='w', padx=5)
|
w.grid(row=row, column=1, sticky='w', padx=5)
|
||||||
row += 1
|
row += 1
|
||||||
|
@ -123,7 +123,7 @@ class SoundOptionsDialog(MfxDialog):
|
||||||
).grid(row=row, column=0, sticky='ew')
|
).grid(row=row, column=0, sticky='ew')
|
||||||
w = PysolScale(frame, from_=0, to=128, resolution=1,
|
w = PysolScale(frame, from_=0, to=128, resolution=1,
|
||||||
orient='horizontal', takefocus=0,
|
orient='horizontal', takefocus=0,
|
||||||
length="3i", #label=_('Music volume'),
|
length="3i", # label=_('Music volume'),
|
||||||
variable=self.music_volume)
|
variable=self.music_volume)
|
||||||
w.grid(row=row, column=1, sticky='w', padx=5)
|
w.grid(row=row, column=1, sticky='w', padx=5)
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ class SoundOptionsDialog(MfxDialog):
|
||||||
self.mainloop(focus, kw.timeout)
|
self.mainloop(focus, kw.timeout)
|
||||||
|
|
||||||
def initKw(self, kw):
|
def initKw(self, kw):
|
||||||
strings=[_("&OK"), _("&Apply"), _("&Cancel"),]
|
strings = [_("&OK"), _("&Apply"), _("&Cancel"), ]
|
||||||
kw = KwStruct(kw,
|
kw = KwStruct(kw,
|
||||||
strings=strings,
|
strings=strings,
|
||||||
default=0,
|
default=0,
|
||||||
|
@ -186,11 +186,11 @@ class SoundOptionsDialog(MfxDialog):
|
||||||
return self.mDone(0)
|
return self.mDone(0)
|
||||||
|
|
||||||
def mOptSoundDirectX(self, *event):
|
def mOptSoundDirectX(self, *event):
|
||||||
##print self.sound_mode.get()
|
# print self.sound_mode.get()
|
||||||
d = MfxMessageDialog(self.top, title=_("Sound preferences info"),
|
MfxMessageDialog(
|
||||||
text=_("""\
|
self.top, title=_("Sound preferences info"),
|
||||||
|
text=_("""\
|
||||||
Changing DirectX settings will take effect
|
Changing DirectX settings will take effect
|
||||||
the next time you restart """)+TITLE,
|
the next time you restart """)+TITLE,
|
||||||
bitmap="warning",
|
bitmap="warning",
|
||||||
default=0, strings=(_("&OK"),))
|
default=0, strings=(_("&OK"),))
|
||||||
|
|
||||||
|
|
|
@ -25,26 +25,31 @@ __all__ = ['PysolStatusbar',
|
||||||
'HelpStatusbar']
|
'HelpStatusbar']
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, sys
|
import os
|
||||||
|
import sys
|
||||||
import Tkinter
|
import Tkinter
|
||||||
import ttk
|
import ttk
|
||||||
|
|
||||||
|
# PySol imports
|
||||||
|
from pysollib.mygettext import _
|
||||||
|
|
||||||
|
# Toolkit imports
|
||||||
|
from tkwidget import MfxTooltip
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
d = os.path.abspath(os.path.join(sys.path[0], os.pardir, os.pardir))
|
d = os.path.abspath(os.path.join(sys.path[0], os.pardir, os.pardir))
|
||||||
sys.path.append(d)
|
sys.path.append(d)
|
||||||
import gettext
|
import gettext
|
||||||
gettext.install('pysol', d, unicode=True)
|
gettext.install('pysol', d, unicode=True)
|
||||||
|
|
||||||
# PySol imports
|
if sys.version_info > (3,):
|
||||||
from pysollib.mygettext import _, n_
|
unicode = str
|
||||||
|
|
||||||
# Toolkit imports
|
|
||||||
from tkwidget import MfxTooltip
|
|
||||||
|
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
# *
|
# *
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
|
|
||||||
class MfxStatusbar:
|
class MfxStatusbar:
|
||||||
def __init__(self, top, row, column, columnspan):
|
def __init__(self, top, row, column, columnspan):
|
||||||
self.top = top
|
self.top = top
|
||||||
|
@ -90,7 +95,6 @@ class MfxStatusbar:
|
||||||
sg = ttk.Sizegrip(self.top_frame)
|
sg = ttk.Sizegrip(self.top_frame)
|
||||||
sg.pack(side='right', anchor='se')
|
sg.pack(side='right', anchor='se')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# public methods
|
# public methods
|
||||||
#
|
#
|
||||||
|
@ -138,10 +142,12 @@ class MfxStatusbar:
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
for w in self._tooltips:
|
for w in self._tooltips:
|
||||||
if w: w.destroy()
|
if w:
|
||||||
|
w.destroy()
|
||||||
self._tooltips = []
|
self._tooltips = []
|
||||||
for w in self._widgets:
|
for w in self._widgets:
|
||||||
if w: w.destroy()
|
if w:
|
||||||
|
w.destroy()
|
||||||
self._widgets = []
|
self._widgets = []
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,7 +161,7 @@ class PysolStatusbar(MfxStatusbar):
|
||||||
('moves', _('Moves/Total moves'), 10),
|
('moves', _('Moves/Total moves'), 10),
|
||||||
('gamenumber', _('Game number'), 26),
|
('gamenumber', _('Game number'), 26),
|
||||||
('stats', _('Games played: won/lost'), 12),
|
('stats', _('Games played: won/lost'), 12),
|
||||||
):
|
):
|
||||||
self._createLabel(n, tooltip=t, width=w)
|
self._createLabel(n, tooltip=t, width=w)
|
||||||
#
|
#
|
||||||
l = self._createLabel('info', expand=True)
|
l = self._createLabel('info', expand=True)
|
||||||
|
@ -191,13 +197,13 @@ class TestStatusbar(PysolStatusbar):
|
||||||
self.updateText(moves=999, gamenumber='#0123456789ABCDEF0123')
|
self.updateText(moves=999, gamenumber='#0123456789ABCDEF0123')
|
||||||
self.updateText(info='Some info text.')
|
self.updateText(info='Some info text.')
|
||||||
|
|
||||||
|
|
||||||
def statusbar_main(args):
|
def statusbar_main(args):
|
||||||
tk = Tkinter.Tk()
|
tk = Tkinter.Tk()
|
||||||
statusbar = TestStatusbar(tk, args)
|
TestStatusbar(tk, args)
|
||||||
tk.mainloop()
|
tk.mainloop()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(statusbar_main(sys.argv))
|
sys.exit(statusbar_main(sys.argv))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use String::ShellQuote qw/ shell_quote /;
|
||||||
|
|
||||||
# my $cmd = shell_quote( 'flake8', '.' );
|
# my $cmd = shell_quote( 'flake8', '.' );
|
||||||
my $cmd = shell_quote( 'flake8',
|
my $cmd = shell_quote( 'flake8',
|
||||||
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cmp]*/*.py ./pysollib/tile/[a-p]*.py') );
|
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cmp]*/*.py ./pysollib/tile/[a-s]*.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