diff --git a/pysollib/tile/selectcardset.py b/pysollib/tile/selectcardset.py index b53083ff..c931d304 100644 --- a/pysollib/tile/selectcardset.py +++ b/pysollib/tile/selectcardset.py @@ -29,7 +29,7 @@ import Tkinter import ttk # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct, USE_PIL from pysollib.util import CARDSET from pysollib.resource import CSI @@ -55,7 +55,8 @@ class SelectCardsetNode(SelectDialogTreeNode): contents = [] for obj in self.tree.data.all_objects: 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) return contents or self.tree.data.no_contents @@ -69,60 +70,94 @@ class SelectCardsetData(SelectDialogTreeData): SelectDialogTreeData.__init__(self) self.all_objects = manager.getAllSortedByName() 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 items = CSI.TYPE.items() - items.sort(lambda a, b: cmp(a[1], b[1])) + items.sort(key=lambda x: x[1]) nodes = [] for key, name in items: 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: - 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 items = CSI.STYLE.items() - items.sort(lambda a, b: cmp(a[1], b[1])) + items.sort(key=lambda x: x[1]) nodes = [] for key, name in items: 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: - nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.styles)) - select_by_style = SelectCardsetNode(None, _("by Style"), tuple(nodes)) + nodes.append( + SelectCardsetNode( + None, _("Uncategorized"), lambda cs: not cs.si.styles)) + select_by_style = SelectCardsetNode( + None, _("by Style"), tuple(nodes)) # select_by_nationality = None items = CSI.NATIONALITY.items() - items.sort(lambda a, b: cmp(a[1], b[1])) + items.sort(key=lambda x: x[1]) nodes = [] for key, name in items: 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: - nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.nationalities)) - select_by_nationality = SelectCardsetNode(None, _("by Nationality"), tuple(nodes)) + nodes.append( + SelectCardsetNode( + None, _("Uncategorized"), + lambda cs: not cs.si.nationalities)) + select_by_nationality = SelectCardsetNode( + None, _("by Nationality"), tuple(nodes)) # select_by_date = None items = CSI.DATE.items() - items.sort(lambda a, b: cmp(a[1], b[1])) + items.sort(key=lambda x: x[1]) nodes = [] for key, name in items: 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: - nodes.append(SelectCardsetNode(None, _("Uncategorized"), lambda cs: not cs.si.dates)) - select_by_date = SelectCardsetNode(None, _("by Date"), tuple(nodes)) + nodes.append( + SelectCardsetNode( + None, _("Uncategorized"), lambda cs: not cs.si.dates)) + select_by_date = SelectCardsetNode( + None, _("by Date"), tuple(nodes)) # self.rootnodes = filter(None, ( - SelectCardsetNode(None, _("All Cardsets"), lambda cs: 1, expanded=len(self.all_objects)<=12), - SelectCardsetNode(None, _("by Size"), ( - SelectCardsetNode(None, _("Tiny cardsets"), 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), + SelectCardsetNode( + None, _("All Cardsets"), + lambda cs: 1, expanded=len(self.all_objects) <= 12), + SelectCardsetNode( + None, _("by Size"), + (SelectCardsetNode( + None, _("Tiny cardsets"), + 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_style, select_by_date, @@ -134,15 +169,19 @@ class SelectCardsetByTypeData(SelectDialogTreeData): def __init__(self, manager, key): SelectDialogTreeData.__init__(self) 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.sort(lambda a, b: cmp(a[1], b[1])) + items.sort(key=lambda x: x[1]) nodes = [] for key, name in items: if manager.registered_types.get(key): - nodes.append(SelectCardsetNode(None, name, lambda cs, key=key: key == cs.si.type)) - select_by_type = SelectCardsetNode(None, _("by Type"), tuple(nodes), expanded=1) + nodes.append( + 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, ( select_by_type, @@ -182,7 +221,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): self.key = key self.app = app self.cardset_values = None - #padx, pady = kw.padx, kw.pady + # padx, pady = kw.padx, kw.pady padx, pady = 5, 5 if self.TreeDataHolder_Class.data is None: self.TreeDataHolder_Class.data = self.TreeData_Class(manager, key) @@ -214,7 +253,8 @@ class SelectCardsetDialogWithPreview(MfxDialog): orient='horizontal', variable=var, value=app.opt.scale_x, 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.set(app.opt.scale_y) @@ -224,7 +264,8 @@ class SelectCardsetDialogWithPreview(MfxDialog): orient='horizontal', variable=var, value=app.opt.scale_y, 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.set(app.opt.auto_scale) @@ -243,7 +284,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): left_frame, text=_('Preserve aspect ratio'), variable=self.preserve_aspect, takefocus=False, - #command=self._updateScale + # command=self._updateScale ) self.aspect_check.grid(row=4, column=0, sticky='ew', padx=padx, pady=pady) @@ -279,8 +320,8 @@ class SelectCardsetDialogWithPreview(MfxDialog): else: s = (_("&Info..."), 10) kw = KwStruct(kw, - strings = (s, 'sep', - _("&OK"), _("&Cancel"),), + strings=(s, 'sep', + _("&OK"), _("&Cancel"),), default=0, resizable=True, ) @@ -308,7 +349,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): cs = self.manager.get(self.tree.selection_key) if not cs: return - ##title = CARDSET+" "+cs.name + # title = CARDSET+" "+cs.name title = CARDSET.capitalize()+" "+cs.name d = CardsetInfoDialog(self.top, title=title, cardset=cs, images=self.preview_images) @@ -343,7 +384,7 @@ class SelectCardsetDialogWithPreview(MfxDialog): return names, columns = cs.getPreviewCardNames() try: - #???names, columns = cs.getPreviewCardNames() + # ???names, columns = cs.getPreviewCardNames() for n in names: f = os.path.join(cs.dir, n + cs.ext) self.preview_images.append(loadImage(file=f)) @@ -371,8 +412,8 @@ class SelectCardsetDialogWithPreview(MfxDialog): x = x + dx canvas.config(scrollregion=(0, 0, sx+dx, sy+dy), width=sx+dx, height=sy+dy) - #canvas.config(xscrollincrement=dx, yscrollincrement=dy) - canvas.event_generate('') # update bg image + # canvas.config(xscrollincrement=dx, yscrollincrement=dy) + canvas.event_generate('') # update bg image self.preview_key = key self.key = key @@ -386,6 +427,7 @@ class SelectCardsetByTypeDialogWithPreview(SelectCardsetDialogWithPreview): # * Cardset Info # ************************************************************************ + class CardsetInfoDialog(MfxDialog): def __init__(self, parent, title, cardset, images, **kw): kw = self.initKw(kw) @@ -411,14 +453,14 @@ class CardsetInfoDialog(MfxDialog): year = str(cardset.year) frow = 0 for n, t in ( - ##('Version:', str(cardset.version)), + # ('Version:', str(cardset.version)), (_('Type:'), CSI.TYPE[cardset.type]), (_('Styles:'), styles), (_('Nationality:'), nationalities), (_('Year:'), year), - ##(_('Number of cards:'), str(cardset.ncards)), + # (_('Number of cards:'), str(cardset.ncards)), (_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)), - ): + ): if t is not None: l = ttk.Label(info_frame, text=n, anchor='w', justify='left') @@ -432,11 +474,11 @@ class CardsetInfoDialog(MfxDialog): from random import choice im = choice(images) 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.grid(row=0, column=2, rowspan=frow+1, sticky='ne') 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') info_frame.columnconfigure(2, weight=1) @@ -456,7 +498,7 @@ class CardsetInfoDialog(MfxDialog): from_=5, to=40, resolution=1, orient='horizontal', variable=var, value=cardset.CARD_XOFFSET, - #command=self._updateScale + # command=self._updateScale ) self.x_offset.grid(row=0, column=0, sticky='ew', padx=padx, pady=pady) @@ -466,13 +508,13 @@ class CardsetInfoDialog(MfxDialog): from_=5, to=40, resolution=1, orient='horizontal', variable=var, value=cardset.CARD_YOFFSET, - #command=self._updateScale + # command=self._updateScale ) self.y_offset.grid(row=1, column=0, sticky='ew', padx=padx, pady=pady) row += 1 - ##bg = top_frame["bg"] + # bg = top_frame["bg"] bg = 'white' text_w = Tkinter.Text(frame, bd=1, relief="sunken", wrap="word", padx=4, width=64, height=16, bg=bg) @@ -496,12 +538,12 @@ class CardsetInfoDialog(MfxDialog): text_w.config(state="disabled") # focus = self.createButtons(bottom_frame, kw) - #focus = text_w + # focus = text_w self.mainloop(focus, kw.timeout) def initKw(self, kw): if USE_PIL: - strings = (_("&Save"),_("&Cancel")) + strings = (_("&Save"), _("&Cancel")) else: strings = (_("&OK"),) kw = KwStruct(kw, @@ -518,4 +560,3 @@ class CardsetInfoDialog(MfxDialog): else: self.cardset_values = None MfxDialog.mDone(self, button) - diff --git a/pysollib/tile/selectgame.py b/pysollib/tile/selectgame.py index d8026bea..d2c92398 100644 --- a/pysollib/tile/selectgame.py +++ b/pysollib/tile/selectgame.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 . # -# ---------------------------------------------------------------------------## +# --------------------------------------------------------------------------- # imports @@ -28,7 +28,7 @@ import ttk from UserList import UserList # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import destruct, Struct, KwStruct from pysollib.mfxutil import format_time from pysollib.gamedb import GI @@ -62,7 +62,7 @@ class SelectGameNode(SelectDialogTreeNode): for gi in self.tree.data.all_games_gi: if gi and self.select_func is None: # 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 node = SelectGameLeaf(self.tree, self, name, key=gi.id) contents.append(node) @@ -81,9 +81,10 @@ class SelectGameData(SelectDialogTreeData): def __init__(self, app): SelectDialogTreeData.__init__(self) 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 = [] for data in (GI.SELECT_GAME_BY_TYPE, GI.SELECT_ORIENTAL_GAME_BY_TYPE, @@ -97,7 +98,10 @@ class SelectGameData(SelectDialogTreeData): continue gg.append(SelectGameNode(None, _(name), select_func)) 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 if filter(select_mahjongg_game, self.all_games_gi): gg = SelectGameNode(None, _("Mahjongg Games"), @@ -115,14 +119,15 @@ class SelectGameData(SelectDialogTreeData): if g[3]: s_original = SelectGameNode(None, _("Original Games"), tuple(g[3])) -## if g[4]: -## s_contrib = SelectGameNode(None, "Contributed Games", tuple(g[4])) + # if g[4]: + # s_contrib = SelectGameNode(None, "Contributed Games", tuple(g[4])) if g[5]: s_mahjongg = g[5] # s_by_compatibility, gg = None, [] 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): continue gg.append(SelectGameNode(None, name, select_func)) @@ -132,9 +137,10 @@ class SelectGameData(SelectDialogTreeData): # s_by_pysol_version, gg = None, [] 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): - continue + continue name = _("New games in v. ") + name gg.append(SelectGameNode(None, name, select_func)) if 1 and gg: @@ -142,15 +148,17 @@ class SelectGameData(SelectDialogTreeData): tuple(gg)) s_by_inventors, gg = None, [] 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): - continue + continue gg.append(SelectGameNode(None, name, select_func)) if 1 and gg: s_by_inventors = SelectGameNode(None, _("by Inventors"), tuple(gg)) # - ul_alternate_names = UserList(list(app.gdb.getGamesTuplesSortedByAlternateName())) + ul_alternate_names = UserList( + list(app.gdb.getGamesTuplesSortedByAlternateName())) # self.rootnodes = filter(None, ( SelectGameNode(None, _("All Games"), None, expanded=0), @@ -170,8 +178,9 @@ class SelectGameData(SelectDialogTreeData): lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK), SelectGameNode(None, _('Balanced'), lambda gi: gi.skill_level == GI.SL_BALANCED), - SelectGameNode(None, _('Mostly skill'), - lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL), + SelectGameNode( + None, _('Mostly skill'), + lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL), SelectGameNode(None, _('Skill only'), lambda gi: gi.skill_level == GI.SL_SKILL), )), @@ -191,8 +200,10 @@ class SelectGameData(SelectDialogTreeData): lambda gi: gi.si.ncards == 104), SelectGameNode(None, _("144 cards"), lambda gi: gi.si.ncards == 144), - SelectGameNode(None, _("Other number"), - lambda gi: gi.si.ncards not in (32, 48, 52, 64, 78, 104, 144)), + SelectGameNode( + 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, _("1 deck games"), @@ -215,10 +226,11 @@ class SelectGameData(SelectDialogTreeData): lambda gi: gi.si.redeals == 3), SelectGameNode(None, _("Unlimited redeals"), lambda gi: gi.si.redeals == -1), -## SelectGameNode(None, "Variable redeals", -## lambda gi: gi.si.redeals == -2), - SelectGameNode(None, _("Other number of redeals"), - lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)), + # SelectGameNode(None, "Variable redeals", + # lambda gi: gi.si.redeals == -2), + SelectGameNode( + None, _("Other number of redeals"), + lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)), )), s_by_compatibility, )), @@ -229,8 +241,9 @@ class SelectGameData(SelectDialogTreeData): lambda gi: gi.si.game_flags & GI.GT_CHILDREN), SelectGameNode(None, _("Games with Scoring"), lambda gi: gi.si.game_flags & GI.GT_SCORE), - SelectGameNode(None, _("Games with Separate Decks"), - lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS), + SelectGameNode( + None, _("Games with Separate Decks"), + lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS), SelectGameNode(None, _("Open Games (all cards visible)"), lambda gi: gi.si.game_flags & GI.GT_OPEN), SelectGameNode(None, _("Relaxed Variants"), @@ -345,11 +358,11 @@ class SelectGameDialogWithPreview(SelectGameDialog): w1, w2 = 220, 480 else: w1, w2 = 200, 300 - ##print sw, w1, w2 + # print sw, w1, w2 w2 = max(200, min(w2, 10 + 12*(app.subsampled_images.CARDW+10))) - ##print sw, w1, w2 - ##padx, pady = kw.padx, kw.pady - #padx, pady = kw.padx/2, kw.pady/2 + # print sw, w1, w2 + # padx, pady = kw.padx, kw.pady + # padx, pady = kw.padx/2, kw.pady/2 padx, pady = 4, 4 # PanedWindow paned_window = ttk.PanedWindow(top_frame, orient='horizontal') @@ -372,7 +385,6 @@ class SelectGameDialogWithPreview(SelectGameDialog): ipadx=4, ipady=4, sticky='nws') # Info self.info_labels = {} - i = 0 for n, t, f, row in ( ('name', _('Name:'), info_frame, 0), ('altnames', _('Alternate names:'), info_frame, 1), @@ -388,13 +400,13 @@ class SelectGameDialogWithPreview(SelectGameDialog): ('time', _('Playing time:'), stats_frame, 3), ('moves', _('Moves:'), stats_frame, 4), ('percent', _('% won:'), stats_frame, 5), - ): + ): title_label = ttk.Label(f, text=t, justify='left', anchor='w') title_label.grid(row=row, column=0, sticky='nw', padx=4) text_label = ttk.Label(f, justify='left', anchor='w') text_label.grid(row=row, column=1, sticky='nw', padx=4) 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) stats_frame.rowconfigure(6, weight=1) # Canvas @@ -413,7 +425,7 @@ class SelectGameDialogWithPreview(SelectGameDialog): self.preview_game = None self.preview_app = None self.updatePreview(gameid, animations=0) - ##focus = self.tree.frame + # focus = self.tree.frame self.mainloop(focus, kw.timeout) def initKw(self, kw): @@ -438,7 +450,7 @@ class SelectGameDialogWithPreview(SelectGameDialog): if destroy: self.preview.canvas.delete("all") # - #for l in self.info_labels.values(): + # for l in self.info_labels.values(): # l.config(text='') # destruct the game if self.preview_game: @@ -466,25 +478,25 @@ class SelectGameDialogWithPreview(SelectGameDialog): if self.preview_app is None: self.preview_app = Struct( # variables - audio = self.app.audio, - canvas = canvas, - cardset = self.app.cardset.copy(), - comments = self.app.comments.new(), - gamerandom = self.app.gamerandom, - gdb = self.app.gdb, - gimages = self.app.gimages, - images = self.app.subsampled_images, - menubar = None, - miscrandom = self.app.miscrandom, - opt = self.app.opt.copy(), - startup_opt = self.app.startup_opt, - stats = self.app.stats.new(), - top = None, - top_cursor = self.app.top_cursor, - toolbar = None, + audio=self.app.audio, + canvas=canvas, + cardset=self.app.cardset.copy(), + comments=self.app.comments.new(), + gamerandom=self.app.gamerandom, + gdb=self.app.gdb, + gimages=self.app.gimages, + images=self.app.subsampled_images, + menubar=None, + miscrandom=self.app.miscrandom, + opt=self.app.opt.copy(), + startup_opt=self.app.startup_opt, + stats=self.app.stats.new(), + top=None, + top_cursor=self.app.top_cursor, + toolbar=None, # methods - constructGame = self.app.constructGame, - getFont = self.app.getFont, + constructGame=self.app.constructGame, + getFont=self.app.getFont, ) self.preview_app.opt.shadow = 0 self.preview_app.opt.shade = 0 @@ -496,7 +508,8 @@ class SelectGameDialogWithPreview(SelectGameDialog): if self.preview_game: self.preview_game.endGame() 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) self.top.wm_title(_("Playable Preview - ") + title) # @@ -550,13 +563,19 @@ class SelectGameDialogWithPreview(SelectGameDialog): GI.SL_SKILL: _('Skill only'), } skill_level = sl.get(gi.skill_level) - 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) # stats - won, lost, time, moves = self.app.stats.getFullStats(self.app.opt.player, gameid) - if won+lost > 0: percent = "%.1f" % (100.0*won/(won+lost)) - else: percent = "0.0" + won, lost, time, moves = self.app.stats.getFullStats( + self.app.opt.player, gameid) + if won+lost > 0: + percent = "%.1f" % (100.0*won/(won+lost)) + else: + percent = "0.0" time = format_time(time) moves = str(round(moves, 1)) for n, t in ( @@ -573,7 +592,7 @@ class SelectGameDialogWithPreview(SelectGameDialog): ('time', time), ('moves', moves), ('percent', percent), - ): + ): title_label, text_label = self.info_labels[n] if t in ('', None): title_label.grid_remove() @@ -582,4 +601,3 @@ class SelectGameDialogWithPreview(SelectGameDialog): title_label.grid() text_label.grid() text_label.config(text=t) - diff --git a/pysollib/tile/selecttile.py b/pysollib/tile/selecttile.py index 3e9665d8..a621bbde 100644 --- a/pysollib/tile/selecttile.py +++ b/pysollib/tile/selecttile.py @@ -23,12 +23,13 @@ # imports +import sys import Tkinter import ttk import tkColorChooser # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct # Toolkit imports @@ -37,6 +38,10 @@ from selecttree import SelectDialogTreeLeaf, SelectDialogTreeNode from selecttree import SelectDialogTreeData, SelectDialogTreeCanvas +if sys.version_info > (3,): + basestring = str + + # ************************************************************************ # * Nodes # ************************************************************************ @@ -50,7 +55,8 @@ class SelectTileNode(SelectDialogTreeNode): contents = [] for obj in self.tree.data.all_objects: 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) return contents or self.tree.data.no_contents @@ -64,9 +70,11 @@ class SelectTileData(SelectDialogTreeData): SelectDialogTreeData.__init__(self) self.all_objects = manager.getAllSortedByName() 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.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ] - e1 = isinstance(key, str) or len(self.all_objects) <=17 + self.all_objects = [tile for tile in self.all_objects + if tile.index > 0 and tile.filename] + self.no_contents = [SelectTileLeaf( + None, None, _("(no tiles)"), key=None), ] + e1 = isinstance(key, str) or len(self.all_objects) <= 17 e2 = 1 self.rootnodes = ( SelectTileNode(None, _("Solid Colors"), ( @@ -77,7 +85,9 @@ class SelectTileData(SelectDialogTreeData): SelectTileLeaf(None, None, _("Orange"), key="#f79600"), SelectTileLeaf(None, None, _("Teal"), key="#008286"), ), 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): return self.preview_key = -1 - diff --git a/pysollib/tile/selecttree.py b/pysollib/tile/selecttree.py index 026e3f37..b1b62d1e 100644 --- a/pysollib/tile/selecttree.py +++ b/pysollib/tile/selecttree.py @@ -26,29 +26,40 @@ __all__ = ['SelectDialogTreeData'] # Toolkit imports 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 # ************************************************************************ + class SelectDiagCommon: def _calc_MfxTreeNode(self): return MfxTreeNode + def _calc_MfxTreeInCanvas(self): return MfxTreeInCanvas + def _calc_MfxTreeLeaf(self): return MfxTreeLeaf -class SelectDialogTreeLeaf(SelectDiagCommon, BaseSelectDialogTreeLeaf, MfxTreeLeaf): + +class SelectDialogTreeLeaf(SelectDiagCommon, + BaseSelectDialogTreeLeaf, MfxTreeLeaf): pass -class SelectDialogTreeNode(SelectDiagCommon, BaseSelectDialogTreeNode, MfxTreeNode): + +class SelectDialogTreeNode(SelectDiagCommon, + BaseSelectDialogTreeNode, MfxTreeNode): pass # ************************************************************************ # * Canvas that shows the tree (left side) # ************************************************************************ -class SelectDialogTreeCanvas(SelectDiagCommon, BaseSelectDialogTreeCanvas, MfxTreeInCanvas): + +class SelectDialogTreeCanvas(SelectDiagCommon, + BaseSelectDialogTreeCanvas, MfxTreeInCanvas): pass diff --git a/pysollib/tile/solverdialog.py b/pysollib/tile/solverdialog.py index 2602618c..49d14b6d 100644 --- a/pysollib/tile/solverdialog.py +++ b/pysollib/tile/solverdialog.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------## __all__ = [ - #'SolverDialog', + # 'SolverDialog', 'create_solver_dialog', 'connect_game_solver_dialog', 'destroy_solver_dialog', @@ -30,16 +30,17 @@ __all__ = [ ] # imports -import ttk # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct # Toolkit imports from pysollib.tile.basetilemfxdialog import BaseTileMfxDialog 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.current(0) return cb + def _createShowProgressButton(self, frame): - return self._calcToolkit().Checkbutton(frame, variable=self.progress_var, - text=_('Show progress')) + return self._calcToolkit().Checkbutton( + frame, variable=self.progress_var, + text=_('Show progress')) def initKw(self, kw): - strings=[_('&Start'), _('&Play'), _('&New'), 'sep', _('&Close'),] + strings = [_('&Start'), _('&Play'), _('&New'), 'sep', _('&Close'), ] kw = KwStruct(kw, strings=strings, default=0, @@ -83,6 +86,8 @@ class SolverDialog(BaseSolverDialog, BaseTileMfxDialog): self.play_button.config(state='disabled') +solver_dialog = solver_dialog + def create_solver_dialog(parent, game): global solver_dialog @@ -90,6 +95,5 @@ def create_solver_dialog(parent, game): solver_dialog.top.wm_deiconify() solver_dialog.top.tkraise() except: - ##traceback.print_exc() + # traceback.print_exc() solver_dialog = SolverDialog(parent, game) - diff --git a/pysollib/tile/soundoptionsdialog.py b/pysollib/tile/soundoptionsdialog.py index 9caf39d0..be354c19 100644 --- a/pysollib/tile/soundoptionsdialog.py +++ b/pysollib/tile/soundoptionsdialog.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__ = ['SoundOptionsDialog'] @@ -29,7 +29,7 @@ import Tkinter import ttk # PySol imports -from pysollib.mygettext import _, n_ +from pysollib.mygettext import _ from pysollib.mfxutil import KwStruct from pysollib.settings import TITLE from pysollib.pysolaudio import pysolsoundserver @@ -109,13 +109,13 @@ class SoundOptionsDialog(MfxDialog): command=self.mOptSoundDirectX) 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 ttk.Label(frame, text=_('Sample volume:'), anchor='w' ).grid(row=row, column=0, sticky='ew') w = PysolScale(frame, from_=0, to=128, resolution=1, orient='horizontal', takefocus=0, - length="3i", #label=_('Sample volume'), + length="3i", # label=_('Sample volume'), variable=self.sample_volume) w.grid(row=row, column=1, sticky='w', padx=5) row += 1 @@ -123,7 +123,7 @@ class SoundOptionsDialog(MfxDialog): ).grid(row=row, column=0, sticky='ew') w = PysolScale(frame, from_=0, to=128, resolution=1, orient='horizontal', takefocus=0, - length="3i", #label=_('Music volume'), + length="3i", # label=_('Music volume'), variable=self.music_volume) w.grid(row=row, column=1, sticky='w', padx=5) @@ -154,7 +154,7 @@ class SoundOptionsDialog(MfxDialog): self.mainloop(focus, kw.timeout) def initKw(self, kw): - strings=[_("&OK"), _("&Apply"), _("&Cancel"),] + strings = [_("&OK"), _("&Apply"), _("&Cancel"), ] kw = KwStruct(kw, strings=strings, default=0, @@ -186,11 +186,11 @@ class SoundOptionsDialog(MfxDialog): return self.mDone(0) def mOptSoundDirectX(self, *event): - ##print self.sound_mode.get() - d = MfxMessageDialog(self.top, title=_("Sound preferences info"), - text=_("""\ + # print self.sound_mode.get() + MfxMessageDialog( + self.top, title=_("Sound preferences info"), + text=_("""\ Changing DirectX settings will take effect the next time you restart """)+TITLE, - bitmap="warning", - default=0, strings=(_("&OK"),)) - + bitmap="warning", + default=0, strings=(_("&OK"),)) diff --git a/pysollib/tile/statusbar.py b/pysollib/tile/statusbar.py index 80d2fe61..3daa0cb8 100644 --- a/pysollib/tile/statusbar.py +++ b/pysollib/tile/statusbar.py @@ -25,26 +25,31 @@ __all__ = ['PysolStatusbar', 'HelpStatusbar'] # imports -import os, sys +import os +import sys import Tkinter import ttk +# PySol imports +from pysollib.mygettext import _ + +# Toolkit imports +from tkwidget import MfxTooltip + if __name__ == '__main__': d = os.path.abspath(os.path.join(sys.path[0], os.pardir, os.pardir)) sys.path.append(d) import gettext gettext.install('pysol', d, unicode=True) -# PySol imports -from pysollib.mygettext import _, n_ - -# Toolkit imports -from tkwidget import MfxTooltip +if sys.version_info > (3,): + unicode = str # ************************************************************************ # * # ************************************************************************ + class MfxStatusbar: def __init__(self, top, row, column, columnspan): self.top = top @@ -90,7 +95,6 @@ class MfxStatusbar: sg = ttk.Sizegrip(self.top_frame) sg.pack(side='right', anchor='se') - # # public methods # @@ -138,10 +142,12 @@ class MfxStatusbar: def destroy(self): for w in self._tooltips: - if w: w.destroy() + if w: + w.destroy() self._tooltips = [] for w in self._widgets: - if w: w.destroy() + if w: + w.destroy() self._widgets = [] @@ -155,7 +161,7 @@ class PysolStatusbar(MfxStatusbar): ('moves', _('Moves/Total moves'), 10), ('gamenumber', _('Game number'), 26), ('stats', _('Games played: won/lost'), 12), - ): + ): self._createLabel(n, tooltip=t, width=w) # l = self._createLabel('info', expand=True) @@ -191,13 +197,13 @@ class TestStatusbar(PysolStatusbar): self.updateText(moves=999, gamenumber='#0123456789ABCDEF0123') self.updateText(info='Some info text.') + def statusbar_main(args): tk = Tkinter.Tk() - statusbar = TestStatusbar(tk, args) + TestStatusbar(tk, args) tk.mainloop() return 0 + if __name__ == '__main__': sys.exit(statusbar_main(sys.argv)) - - diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t index cc23a137..28e03e7a 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') } 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 eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );