mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
flake8
This commit is contained in:
parent
bfcfdc59a9
commit
c65a948357
7 changed files with 164 additions and 181 deletions
|
@ -23,11 +23,12 @@
|
|||
|
||||
|
||||
# imports
|
||||
import os, re, sys, types
|
||||
import gtk, gobject
|
||||
import os
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
# PySol imports
|
||||
from pysollib.mygettext import _, n_
|
||||
from pysollib.mygettext import _
|
||||
from pysollib.resource import CSI
|
||||
from pysollib.mfxutil import kwdefault
|
||||
|
||||
|
@ -62,8 +63,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
if self._cardset_store is None:
|
||||
self._createStore()
|
||||
|
||||
#padx, pady = kw.padx, kw.pady
|
||||
padx, pady = 5, 5
|
||||
# padx, pady = kw.padx, kw.pady
|
||||
# left
|
||||
# paned
|
||||
hpaned = gtk.HPaned()
|
||||
|
@ -74,52 +74,49 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
treeview = PysolTreeView(self, self._cardset_store)
|
||||
self.treeview = treeview
|
||||
hpaned.pack1(treeview.scrolledwindow, True, True)
|
||||
##treeview.treeview.expand_all()
|
||||
# treeview.treeview.expand_all()
|
||||
# right
|
||||
sw = gtk.ScrolledWindow()
|
||||
sw.show()
|
||||
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
hpaned.pack2(sw, True, True)
|
||||
##self.scrolledwindow = sw
|
||||
# self.scrolledwindow = sw
|
||||
#
|
||||
self.preview = MfxCanvas(self)
|
||||
self.preview.show()
|
||||
sw.add(self.preview)
|
||||
#hpaned.pack2(self.preview, True, True)
|
||||
# hpaned.pack2(self.preview, True, True)
|
||||
self.preview.setTile(app, app.tabletile_index, force=True)
|
||||
#
|
||||
hpaned.set_position(240)
|
||||
|
||||
self.createButtons(bottom_box, kw)
|
||||
|
||||
##~self.updatePreview(key)
|
||||
# ~self.updatePreview(key)
|
||||
|
||||
self.show_all()
|
||||
gtk.main()
|
||||
|
||||
|
||||
def _selectCardset(self, all_cardsets, selecter):
|
||||
if selecter is None:
|
||||
return [(cs.index, cs.name) for cs in all_cardsets]
|
||||
return [(cs.index, cs.name) for cs in all_cardsets if selecter(cs)]
|
||||
|
||||
|
||||
def _addCardsets(self, store, root_iter, root_label, cardsets):
|
||||
iter = store.append(root_iter)
|
||||
store.set(iter, 0, root_label, 1, -1)
|
||||
for index, name in cardsets:
|
||||
child_iter = store.append(iter)
|
||||
##~ name = _(name)
|
||||
# ~ name = _(name)
|
||||
store.set(child_iter, 0, name, 1, index)
|
||||
|
||||
|
||||
def _addCardsetsByType(self, store, root_label, all_cardsets,
|
||||
cardset_types, selecter_type, registered):
|
||||
manager = self.manager
|
||||
root_iter = store.append(None)
|
||||
store.set(root_iter, 0, root_label, 1, -1)
|
||||
items = cardset_types.items()
|
||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
||||
items.sort(key=lambda x: x[1])
|
||||
added = False
|
||||
for key, label in items:
|
||||
if key not in getattr(manager, registered):
|
||||
|
@ -127,18 +124,18 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
cardsets = []
|
||||
for cs in all_cardsets:
|
||||
si = getattr(cs.si, selecter_type)
|
||||
if isinstance(si, int): # type
|
||||
if isinstance(si, int): # type
|
||||
if key == si:
|
||||
cardsets.append((cs.index, cs.name))
|
||||
else: # style, nationality, date
|
||||
else: # style, nationality, date
|
||||
if key in si:
|
||||
cardsets.append((cs.index, cs.name))
|
||||
if cardsets:
|
||||
added = True
|
||||
self._addCardsets(store, root_iter, label, cardsets)
|
||||
if added:
|
||||
selecter = lambda cs, selecter_type=selecter_type: \
|
||||
not getattr(cs.si, selecter_type)
|
||||
def selecter(cs, selecter_type=selecter_type):
|
||||
return getattr(cs.si, selecter_type)
|
||||
cs = self._selectCardset(all_cardsets, selecter)
|
||||
if cs:
|
||||
self._addCardsets(store, root_iter, _('Uncategorized'), cs)
|
||||
|
@ -159,11 +156,12 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
root_iter = store.append(None)
|
||||
store.set(root_iter, 0, _('by Size'), 1, -1)
|
||||
for label, selecter in (
|
||||
(_("Tiny cardsets"), lambda cs: cs.si.size == CSI.SIZE_TINY),
|
||||
(_("Small cardsets"), lambda cs: cs.si.size == CSI.SIZE_SMALL),
|
||||
(_("Tiny cardsets"), lambda cs: cs.si.size == CSI.SIZE_TINY),
|
||||
(_("Small cardsets"), lambda cs: cs.si.size == CSI.SIZE_SMALL),
|
||||
(_("Medium cardsets"), lambda cs: cs.si.size == CSI.SIZE_MEDIUM),
|
||||
(_("Large cardsets"), lambda cs: cs.si.size == CSI.SIZE_LARGE),
|
||||
(_("XLarge cardsets"), lambda cs: cs.si.size == CSI.SIZE_XLARGE),):
|
||||
(_("Large cardsets"), lambda cs: cs.si.size == CSI.SIZE_LARGE),
|
||||
(_("XLarge cardsets"), lambda cs: cs.si.size == CSI.SIZE_XLARGE),
|
||||
):
|
||||
cs = self._selectCardset(all_cardsets, selecter)
|
||||
if cs:
|
||||
self._addCardsets(store, root_iter, label, cs)
|
||||
|
@ -180,21 +178,18 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
|
||||
self._cardset_store = store
|
||||
|
||||
|
||||
def getSelected(self):
|
||||
index = self.treeview.getSelected()
|
||||
if index < 0:
|
||||
return None
|
||||
return index
|
||||
|
||||
|
||||
def showSelected(self, w):
|
||||
key = self.getSelected()
|
||||
if key is not None:
|
||||
self.updatePreview(key)
|
||||
pass
|
||||
|
||||
|
||||
def updatePreview(self, key):
|
||||
if key == self.preview_key:
|
||||
return
|
||||
|
@ -207,7 +202,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))
|
||||
|
@ -228,7 +223,6 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
canvas.set_scroll_region(0, 0, sx+dx, sy+dy)
|
||||
self.preview_key = key
|
||||
|
||||
|
||||
def initKw(self, kw):
|
||||
kwdefault(kw,
|
||||
strings=(_("&Load"), _("&Cancel"), _("&Info..."),),
|
||||
|
@ -239,11 +233,9 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
)
|
||||
return MfxDialog.initKw(self, kw)
|
||||
|
||||
|
||||
def createInfo(self):
|
||||
pass
|
||||
|
||||
|
||||
def done(self, button):
|
||||
b = button.get_data('user_data')
|
||||
if b == 2:
|
||||
|
@ -257,7 +249,3 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
|||
self.button = b
|
||||
self.hide()
|
||||
self.quit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -23,14 +23,15 @@
|
|||
|
||||
|
||||
# imports
|
||||
import os, re, sys, types
|
||||
import gtk, gobject
|
||||
import os
|
||||
import gtk
|
||||
import gobject
|
||||
|
||||
#from UserList import UserList
|
||||
# from UserList import UserList
|
||||
|
||||
# PySol imports
|
||||
from pysollib.mygettext import _, n_
|
||||
from pysollib.mfxutil import destruct, Struct, KwStruct
|
||||
from pysollib.mygettext import _
|
||||
from pysollib.mfxutil import destruct, Struct
|
||||
from pysollib.mfxutil import kwdefault
|
||||
from pysollib.mfxutil import format_time
|
||||
from pysollib.gamedb import GI
|
||||
|
@ -40,7 +41,7 @@ from pysollib.resource import CSI
|
|||
# Toolkit imports
|
||||
from tkutil import unbind_destroy
|
||||
from tkwidget import MfxDialog
|
||||
from tkcanvas import MfxCanvas, MfxCanvasText
|
||||
from tkcanvas import MfxCanvas
|
||||
from pysoltree import PysolTreeView
|
||||
|
||||
|
||||
|
@ -49,7 +50,7 @@ from pysoltree import PysolTreeView
|
|||
# ************************************************************************
|
||||
|
||||
class SelectGameDialogWithPreview(MfxDialog):
|
||||
#Tree_Class = SelectGameTreeWithPreview
|
||||
# Tree_Class = SelectGameTreeWithPreview
|
||||
game_store = None
|
||||
#
|
||||
_paned_position = 300
|
||||
|
@ -109,7 +110,6 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
stats_frame.set_border_width(4)
|
||||
# info
|
||||
self.info_labels = {}
|
||||
i = 0
|
||||
for n, t, f, row in (
|
||||
('name', _('Name:'), info_frame, 0),
|
||||
('altnames', _('Alternate names:'), info_frame, 1),
|
||||
|
@ -125,7 +125,7 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
('time', _('Playing time:'), stats_frame, 3),
|
||||
('moves', _('Moves:'), stats_frame, 4),
|
||||
('percent', _('% won:'), stats_frame, 5),
|
||||
):
|
||||
):
|
||||
title_label = gtk.Label()
|
||||
title_label.show()
|
||||
title_label.set_text(t)
|
||||
|
@ -149,9 +149,11 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
# canvas
|
||||
self.preview = MfxCanvas(self)
|
||||
self.preview.show()
|
||||
table.attach(self.preview,
|
||||
table.attach(
|
||||
self.preview,
|
||||
0, 2, 1, 2,
|
||||
gtk.EXPAND|gtk.FILL|gtk.SHRINK, gtk.EXPAND|gtk.FILL|gtk.SHRINK,
|
||||
gtk.EXPAND | gtk.FILL | gtk.SHRINK,
|
||||
gtk.EXPAND | gtk.FILL | gtk.SHRINK,
|
||||
0, 0)
|
||||
self.preview.set_border_width(4)
|
||||
self.preview.setTile(app, app.tabletile_index, force=True)
|
||||
|
@ -162,8 +164,8 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
self.preview_key = -1
|
||||
self.preview_game = None
|
||||
self.preview_app = None
|
||||
##~ self.updatePreview(gameid, animations=0)
|
||||
##~ SelectGameTreeWithPreview.html_viewer = None
|
||||
# ~ self.updatePreview(gameid, animations=0)
|
||||
# ~ SelectGameTreeWithPreview.html_viewer = None
|
||||
|
||||
self.connect('unrealize', self._unrealizeEvent)
|
||||
|
||||
|
@ -172,7 +174,6 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
self.show_all()
|
||||
gtk.main()
|
||||
|
||||
|
||||
def _addGamesFromData(self, data, store, root_iter, root_label, all_games):
|
||||
gl = []
|
||||
for label, selecter in data:
|
||||
|
@ -186,7 +187,6 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
for label, games in gl:
|
||||
self._addGames(store, iter, label, games)
|
||||
|
||||
|
||||
def _addGames(self, store, root_iter, root_label, games):
|
||||
if not games:
|
||||
return
|
||||
|
@ -196,7 +196,6 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
child_iter = store.append(iter)
|
||||
store.set(child_iter, 0, name, 1, id)
|
||||
|
||||
|
||||
def _selectGames(self, all_games, selecter):
|
||||
# return list of tuples (gameid, gamename)
|
||||
if selecter is None:
|
||||
|
@ -205,7 +204,6 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
return all_games
|
||||
return [(gi.id, gi.name) for gi in all_games if selecter(gi)]
|
||||
|
||||
|
||||
def createGameStore(self):
|
||||
store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT)
|
||||
app = self.app
|
||||
|
@ -217,8 +215,9 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
for label, games, selecter in (
|
||||
(_('All Games'), all_games, None),
|
||||
(_('Alternate Names'), alter_games, 'alt'),
|
||||
(_('Popular Games'), all_games, lambda gi: gi.si.game_flags & GI.GT_POPULAR),
|
||||
):
|
||||
(_('Popular Games'), all_games,
|
||||
lambda gi: gi.si.game_flags & GI.GT_POPULAR),
|
||||
):
|
||||
games = self._selectGames(games, selecter)
|
||||
self._addGames(store, None, label, games)
|
||||
|
||||
|
@ -234,11 +233,11 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
None, _("French games"), all_games)
|
||||
# by skill level
|
||||
data = (
|
||||
(_('Luck only'), lambda gi: gi.skill_level == GI.SL_LUCK),
|
||||
(_('Mostly luck'), lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK),
|
||||
(_('Balanced'), lambda gi: gi.skill_level == GI.SL_BALANCED),
|
||||
(_('Luck only'), lambda gi: gi.skill_level == GI.SL_LUCK),
|
||||
(_('Mostly luck'), lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK),
|
||||
(_('Balanced'), lambda gi: gi.skill_level == GI.SL_BALANCED),
|
||||
(_('Mostly skill'), lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL),
|
||||
(_('Skill only'), lambda gi: gi.skill_level == GI.SL_SKILL),
|
||||
(_('Skill only'), lambda gi: gi.skill_level == GI.SL_SKILL),
|
||||
)
|
||||
self._addGamesFromData(data, store, None,
|
||||
_("by Skill Level"), all_games)
|
||||
|
@ -247,37 +246,41 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
root_iter = store.append(None)
|
||||
store.set(root_iter, 0, _('by Game Feature'), 1, -1)
|
||||
data = (
|
||||
(_("32 cards"), lambda gi: gi.si.ncards == 32),
|
||||
(_("48 cards"), lambda gi: gi.si.ncards == 48),
|
||||
(_("52 cards"), lambda gi: gi.si.ncards == 52),
|
||||
(_("64 cards"), lambda gi: gi.si.ncards == 64),
|
||||
(_("78 cards"), lambda gi: gi.si.ncards == 78),
|
||||
(_("104 cards"), lambda gi: gi.si.ncards == 104),
|
||||
(_("144 cards"), lambda gi: gi.si.ncards == 144),
|
||||
(_("Other number"), lambda gi: gi.si.ncards not in (32, 48, 52, 64, 78, 104, 144)),)
|
||||
self._addGamesFromData(data, store, root_iter,
|
||||
_("by Number of Cards"), all_games)
|
||||
(_("32 cards"), lambda gi: gi.si.ncards == 32),
|
||||
(_("48 cards"), lambda gi: gi.si.ncards == 48),
|
||||
(_("52 cards"), lambda gi: gi.si.ncards == 52),
|
||||
(_("64 cards"), lambda gi: gi.si.ncards == 64),
|
||||
(_("78 cards"), lambda gi: gi.si.ncards == 78),
|
||||
(_("104 cards"), lambda gi: gi.si.ncards == 104),
|
||||
(_("144 cards"), lambda gi: gi.si.ncards == 144),
|
||||
(_("Other number"),
|
||||
lambda gi: gi.si.ncards not in (32, 48, 52, 64, 78, 104, 144))
|
||||
)
|
||||
self._addGamesFromData(
|
||||
data, store, root_iter, _("by Number of Cards"), all_games)
|
||||
data = (
|
||||
(_("1 deck games"), lambda gi: gi.si.decks == 1),
|
||||
(_("2 deck games"), lambda gi: gi.si.decks == 2),
|
||||
(_("3 deck games"), lambda gi: gi.si.decks == 3),
|
||||
(_("4 deck games"), lambda gi: gi.si.decks == 4),)
|
||||
self._addGamesFromData(data, store, root_iter,
|
||||
_("by Number of Decks"), all_games)
|
||||
self._addGamesFromData(
|
||||
data, store, root_iter, _("by Number of Decks"), all_games)
|
||||
data = (
|
||||
(_("No redeal"), lambda gi: gi.si.redeals == 0),
|
||||
(_("1 redeal"), lambda gi: gi.si.redeals == 1),
|
||||
(_("1 redeal"), lambda gi: gi.si.redeals == 1),
|
||||
(_("2 redeals"), lambda gi: gi.si.redeals == 2),
|
||||
(_("3 redeals"), lambda gi: gi.si.redeals == 3),
|
||||
(_("Unlimited redeals"), lambda gi: gi.si.redeals == -1),
|
||||
##(_("Variable redeals"), lambda gi: gi.si.redeals == -2),
|
||||
(_("Other number of redeals"), lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)),)
|
||||
# (_("Variable redeals"), lambda gi: gi.si.redeals == -2),
|
||||
(_("Other number of redeals"),
|
||||
lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)),)
|
||||
self._addGamesFromData(data, store, root_iter,
|
||||
_("by Number of Redeals"), all_games)
|
||||
|
||||
data = []
|
||||
for label, vg in GI.GAMES_BY_COMPATIBILITY:
|
||||
selecter = lambda gi, vg=vg: gi.id in vg
|
||||
def selecter(gi, vg=vg):
|
||||
return gi.id in vg
|
||||
data.append((label, selecter))
|
||||
self._addGamesFromData(data, store, root_iter,
|
||||
_("by Compatibility"), all_games)
|
||||
|
@ -285,7 +288,8 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
# by PySol version
|
||||
data = []
|
||||
for version, vg in GI.GAMES_BY_PYSOL_VERSION:
|
||||
selecter = lambda gi, vg=vg: gi.id in vg
|
||||
def selecter(gi, vg=vg):
|
||||
return gi.id in vg
|
||||
label = _("New games in v. ") + version
|
||||
data.append((label, selecter))
|
||||
self._addGamesFromData(data, store, None,
|
||||
|
@ -293,24 +297,28 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
|
||||
#
|
||||
data = (
|
||||
(_("Games for Children (very easy)"), lambda gi: gi.si.game_flags & GI.GT_CHILDREN),
|
||||
(_("Games with Scoring"), lambda gi: gi.si.game_flags & GI.GT_SCORE),
|
||||
(_("Games with Separate Decks"), lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS),
|
||||
(_("Open Games (all cards visible)"), lambda gi: gi.si.game_flags & GI.GT_OPEN),
|
||||
(_("Relaxed Variants"), lambda gi: gi.si.game_flags & GI.GT_RELAXED),)
|
||||
(_("Games for Children (very easy)"),
|
||||
lambda gi: gi.si.game_flags & GI.GT_CHILDREN),
|
||||
(_("Games with Scoring"),
|
||||
lambda gi: gi.si.game_flags & GI.GT_SCORE),
|
||||
(_("Games with Separate Decks"),
|
||||
lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS),
|
||||
(_("Open Games (all cards visible)"),
|
||||
lambda gi: gi.si.game_flags & GI.GT_OPEN),
|
||||
(_("Relaxed Variants"),
|
||||
lambda gi: gi.si.game_flags & GI.GT_RELAXED),)
|
||||
self._addGamesFromData(data, store, None,
|
||||
_("Other Categories"), all_games)
|
||||
|
||||
#
|
||||
self._addGamesFromData(GI.SELECT_ORIGINAL_GAME_BY_TYPE, store,
|
||||
None, _("Original Games"), all_games)
|
||||
##self._addGamesFromData(GI.SELECT_CONTRIB_GAME_BY_TYPE, store,
|
||||
## None, _("Contrib Game"), all_games)
|
||||
# self._addGamesFromData(GI.SELECT_CONTRIB_GAME_BY_TYPE, store,
|
||||
# None, _("Contrib Game"), all_games)
|
||||
|
||||
SelectGameDialogWithPreview.game_store = store
|
||||
return
|
||||
|
||||
|
||||
def initKw(self, kw):
|
||||
kwdefault(kw,
|
||||
strings=(_("&Select"), _("&Rules"), _("&Cancel"),),
|
||||
|
@ -319,24 +327,21 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
)
|
||||
return MfxDialog.initKw(self, kw)
|
||||
|
||||
|
||||
def _unrealizeEvent(self, w):
|
||||
self.deletePreview(destroy=1)
|
||||
#self.preview.unbind_all()
|
||||
# self.preview.unbind_all()
|
||||
self._saveSettings()
|
||||
|
||||
|
||||
def _saveSettings(self):
|
||||
SelectGameDialogWithPreview._geometry = self.get_size()
|
||||
SelectGameDialogWithPreview._paned_position = self.hpaned.get_position()
|
||||
|
||||
SelectGameDialogWithPreview._paned_position = \
|
||||
self.hpaned.get_position()
|
||||
|
||||
def _restoreSettings(self):
|
||||
if self._geometry:
|
||||
self.resize(self._geometry[0], self._geometry[1])
|
||||
self.hpaned.set_position(self._paned_position)
|
||||
|
||||
|
||||
def getSelected(self):
|
||||
index = self.treeview.getSelected()
|
||||
if index < 0:
|
||||
|
@ -348,17 +353,16 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
if id:
|
||||
self.updatePreview(id)
|
||||
|
||||
|
||||
def deletePreview(self, destroy=0):
|
||||
self.preview_key = -1
|
||||
# clean up the canvas
|
||||
if self.preview:
|
||||
unbind_destroy(self.preview)
|
||||
self.preview.deleteAllItems()
|
||||
##~ if destroy:
|
||||
##~ self.preview.delete("all")
|
||||
# ~ if destroy:
|
||||
# ~ self.preview.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:
|
||||
|
@ -386,25 +390,25 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
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
|
||||
|
@ -416,17 +420,18 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
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.set_title(_("Playable Preview - ") + title)
|
||||
#
|
||||
self.preview_game = gi.gameclass(gi)
|
||||
self.preview_game.createPreview(self.preview_app)
|
||||
tx, ty = 0, 0
|
||||
gw, gh = self.preview_game.width, self.preview_game.height
|
||||
##~ canvas.config(scrollregion=(-tx, -ty, -tx, -ty))
|
||||
##~ canvas.xview_moveto(0)
|
||||
##~ canvas.yview_moveto(0)
|
||||
# tx, ty = 0, 0
|
||||
# gw, gh = self.preview_game.width, self.preview_game.height
|
||||
# ~ canvas.config(scrollregion=(-tx, -ty, -tx, -ty))
|
||||
# ~ canvas.xview_moveto(0)
|
||||
# ~ canvas.yview_moveto(0)
|
||||
#
|
||||
random = None
|
||||
if gameid == self.gameid:
|
||||
|
@ -435,7 +440,7 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
self.preview_game.restoreGameFromBookmark(self.bookmark)
|
||||
else:
|
||||
self.preview_game.newGame(random=random, autoplay=1)
|
||||
##~ canvas.config(scrollregion=(-tx, -ty, gw, gh))
|
||||
# ~ canvas.config(scrollregion=(-tx, -ty, gw, gh))
|
||||
#
|
||||
self.preview_app.audio = self.app.audio
|
||||
if self.app.opt.animations:
|
||||
|
@ -472,13 +477,19 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
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 (
|
||||
|
@ -495,7 +506,7 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
('time', time),
|
||||
('moves', moves),
|
||||
('percent', percent),
|
||||
):
|
||||
):
|
||||
title_label, text_label = self.info_labels[n]
|
||||
if t in ('', None):
|
||||
title_label.hide()
|
||||
|
@ -507,12 +518,12 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
|
||||
def done(self, button):
|
||||
button = button.get_data("user_data")
|
||||
print 'done', button
|
||||
print('done', button)
|
||||
if button == 0: # Ok or double click
|
||||
id = self.getSelected()
|
||||
if id:
|
||||
self.gameid = id
|
||||
##~ self.tree.n_expansions = 1 # save xyview in any case
|
||||
# ~ self.tree.n_expansions = 1 # save xyview in any case
|
||||
if button == 1: # Rules
|
||||
id = self.getSelected()
|
||||
if id:
|
||||
|
@ -526,5 +537,3 @@ class SelectGameDialogWithPreview(MfxDialog):
|
|||
self.status = 0
|
||||
self.button = button
|
||||
self.quit()
|
||||
|
||||
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
|
||||
# imports
|
||||
|
||||
## import os, string, sys, types
|
||||
import gobject, gtk
|
||||
# import os, string, sys, types
|
||||
import gobject
|
||||
import gtk
|
||||
from gtk import gdk
|
||||
|
||||
# PySol imports
|
||||
## from pysollib.mfxutil import destruct, Struct, KwStruct
|
||||
from pysollib.mygettext import _, n_
|
||||
from pysollib.resource import CSI
|
||||
# from pysollib.mfxutil import destruct, Struct, KwStruct
|
||||
from pysollib.mygettext import _
|
||||
from pysollib.mfxutil import kwdefault
|
||||
|
||||
# Toolkit imports
|
||||
## from tkutil import loadImage
|
||||
# from tkutil import loadImage
|
||||
from tkwidget import MfxDialog
|
||||
from tkcanvas import MfxCanvas
|
||||
from tkutil import setTransient
|
||||
|
@ -70,7 +70,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
hpaned.pack1(treeview.scrolledwindow, True, True)
|
||||
treeview.treeview.expand_all()
|
||||
#
|
||||
self.preview = MfxCanvas(top_box) # width=w2
|
||||
self.preview = MfxCanvas(top_box) # width=w2
|
||||
hpaned.pack2(self.preview, True, True)
|
||||
self.preview.show()
|
||||
hpaned.set_position(240)
|
||||
|
@ -82,11 +82,9 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
self.show_all()
|
||||
gtk.main()
|
||||
|
||||
|
||||
def rowActivated(self, w, row, col):
|
||||
# FIXME
|
||||
print 'row-activated-event', row, col
|
||||
|
||||
print('row-activated-event', row, col)
|
||||
|
||||
def getSelected(self):
|
||||
index = self.treeview.getSelected()
|
||||
|
@ -94,12 +92,10 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
return None
|
||||
return self.all_keys[index]
|
||||
|
||||
|
||||
def showSelected(self, w):
|
||||
key = self.getSelected()
|
||||
self.updatePreview(key)
|
||||
|
||||
|
||||
def _createStore(self, manager, key):
|
||||
self.all_keys = []
|
||||
index = 0
|
||||
|
@ -138,20 +134,19 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
|
||||
return model
|
||||
|
||||
|
||||
def updatePreview(self, key):
|
||||
##print 'updatePreview:', key, type(key)
|
||||
# print 'updatePreview:', key, type(key)
|
||||
if key is None:
|
||||
return
|
||||
if key == self.preview_key:
|
||||
return
|
||||
canvas = self.preview
|
||||
##canvas.deleteAllItems()
|
||||
# canvas.deleteAllItems()
|
||||
if isinstance(key, str):
|
||||
# solid color
|
||||
canvas.setTile(self.app, 0, force=True)
|
||||
canvas.config(bg=key)
|
||||
##canvas.setTextColor(None)
|
||||
# canvas.setTextColor(None)
|
||||
self.preview_key = key
|
||||
self.table_color = key
|
||||
else:
|
||||
|
@ -161,7 +156,6 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
else:
|
||||
self.preview_key = -1
|
||||
|
||||
|
||||
def initKw(self, kw):
|
||||
kwdefault(kw,
|
||||
strings=(_('&OK'), _('&Solid color...'), _('&Cancel'),),
|
||||
|
@ -172,7 +166,6 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
)
|
||||
return MfxDialog.initKw(self, kw)
|
||||
|
||||
|
||||
def _colorselOkClicked(self, w, d):
|
||||
c = d.colorsel.get_current_color()
|
||||
c = '#%02x%02x%02x' % (c.red/256, c.green/256, c.blue/256)
|
||||
|
@ -180,13 +173,12 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
self.updatePreview(c)
|
||||
self.treeview.unselectAll()
|
||||
|
||||
|
||||
def createColorsel(self):
|
||||
win = gtk.ColorSelectionDialog(_('Select table color'))
|
||||
win.help_button.destroy()
|
||||
win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||
if isinstance(self.preview_key, str):
|
||||
color = self.preview_key
|
||||
color = self.preview_key
|
||||
else:
|
||||
color = self.app.opt.colors['table']
|
||||
win.colorsel.set_current_color(gdk.color_parse(color))
|
||||
|
@ -196,7 +188,6 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
setTransient(win, self)
|
||||
win.show()
|
||||
|
||||
|
||||
def done(self, button):
|
||||
b = button.get_data('user_data')
|
||||
if b == 1:
|
||||
|
@ -208,8 +199,5 @@ class SelectTileDialogWithPreview(MfxDialog):
|
|||
self.key = self.preview_key
|
||||
self.status = 0
|
||||
self.button = b
|
||||
##self.hide()
|
||||
# self.hide()
|
||||
self.quit()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
# ---------------------------------------------------------------------------##
|
||||
|
||||
__all__ = [
|
||||
#'SolverDialog',
|
||||
# 'SolverDialog',
|
||||
'create_solver_dialog',
|
||||
'connect_game_solver_dialog',
|
||||
'destroy_solver_dialog',
|
||||
|
@ -30,15 +30,21 @@ __all__ = [
|
|||
]
|
||||
|
||||
|
||||
solver_dialog = None
|
||||
# solver_dialog = None
|
||||
|
||||
|
||||
def create_solver_dialog(parent, game):
|
||||
pass
|
||||
|
||||
|
||||
def connect_game_solver_dialog(game):
|
||||
pass
|
||||
|
||||
|
||||
def destroy_solver_dialog():
|
||||
pass
|
||||
solver_dialog = None
|
||||
# solver_dialog = None
|
||||
|
||||
|
||||
def reset_solver_dialog():
|
||||
pass
|
||||
|
||||
|
|
|
@ -23,15 +23,12 @@
|
|||
|
||||
|
||||
# imports
|
||||
import os, sys
|
||||
import gtk
|
||||
from gtk import glade
|
||||
|
||||
# PySol imports
|
||||
from pysollib.mygettext import _, n_
|
||||
from pysollib.mygettext import _
|
||||
|
||||
# Toolkit imports
|
||||
from tkwidget import MfxDialog
|
||||
|
||||
|
||||
# ************************************************************************
|
||||
|
@ -86,7 +83,7 @@ class SoundOptionsDialog:
|
|||
samples_checkbuttons[n] = check
|
||||
table.attach(check,
|
||||
col, col+1, row, row+1,
|
||||
gtk.FILL|gtk.EXPAND, gtk.FILL,
|
||||
gtk.FILL | gtk.EXPAND, gtk.FILL,
|
||||
4, 4)
|
||||
if col == 1:
|
||||
col = 0
|
||||
|
@ -103,6 +100,7 @@ class SoundOptionsDialog:
|
|||
sc = self.widgets_tree.get_widget(n+'_scale')
|
||||
sp.set_value(sc.get_value())
|
||||
dic[n+'_scale_value_changed'] = callback
|
||||
|
||||
def callback(w, n=n):
|
||||
sp = self.widgets_tree.get_widget(n+'_spinbutton')
|
||||
sc = self.widgets_tree.get_widget(n+'_scale')
|
||||
|
@ -142,15 +140,13 @@ class SoundOptionsDialog:
|
|||
dialog.destroy()
|
||||
break
|
||||
|
||||
|
||||
def _translateLabels(self):
|
||||
for n in (
|
||||
'label76',
|
||||
'label77',
|
||||
'label78',
|
||||
):
|
||||
):
|
||||
w = self.widgets_tree.get_widget(n)
|
||||
w.set_text(_(w.get_text()))
|
||||
w = self.widgets_tree.get_widget('enable_checkbutton')
|
||||
w.set_label(_(w.get_label()))
|
||||
|
||||
|
|
|
@ -23,17 +23,20 @@
|
|||
|
||||
|
||||
# imports
|
||||
import os, sys
|
||||
import sys
|
||||
import gtk
|
||||
|
||||
# PySol imports
|
||||
from pysollib.mygettext import _, n_
|
||||
from pysollib.mygettext import _
|
||||
|
||||
|
||||
if sys.version_info > (3,):
|
||||
unicode = str
|
||||
# ************************************************************************
|
||||
# *
|
||||
# ************************************************************************
|
||||
|
||||
|
||||
class BasicStatusbar:
|
||||
def __init__(self, top, row, column, columnspan):
|
||||
self.top = top
|
||||
|
@ -44,7 +47,6 @@ class BasicStatusbar:
|
|||
gtk.EXPAND | gtk.FILL, 0,
|
||||
0, 0)
|
||||
|
||||
|
||||
def createLabel(self, name, fill=False, expand=False,
|
||||
tooltip=None, grip=False, width=0):
|
||||
label = gtk.Statusbar()
|
||||
|
@ -57,12 +59,11 @@ class BasicStatusbar:
|
|||
lb = label.get_children()[0].get_children()[0]
|
||||
lb.set_alignment(0.5, 0.0)
|
||||
self._widgets.append(label)
|
||||
##label.push(0, '')
|
||||
## if tooltip:
|
||||
## tt = gtk.Tooltips()
|
||||
## tt.set_tip(label, tooltip, '')
|
||||
## tt.enable()
|
||||
|
||||
# label.push(0, '')
|
||||
# if tooltip:
|
||||
# tt = gtk.Tooltips()
|
||||
# tt.set_tip(label, tooltip, '')
|
||||
# tt.enable()
|
||||
|
||||
def updateText(self, **kw):
|
||||
for k, v in kw.items():
|
||||
|
@ -80,7 +81,6 @@ class BasicStatusbar:
|
|||
label.pop(0)
|
||||
label.push(0, unicode(kw['text']))
|
||||
|
||||
|
||||
def show(self, show=True, resize=False):
|
||||
if show:
|
||||
self.hbox.show()
|
||||
|
@ -92,7 +92,6 @@ class BasicStatusbar:
|
|||
self.show(False, resize)
|
||||
return True
|
||||
|
||||
|
||||
def destroy(self):
|
||||
pass
|
||||
|
||||
|
@ -109,16 +108,13 @@ class PysolStatusbar(BasicStatusbar):
|
|||
("moves", _('Moves/Total moves'), 10),
|
||||
("gamenumber", _("Game number"), 26),
|
||||
("stats", _("Games played: won/lost"), 12),
|
||||
):
|
||||
):
|
||||
self.createLabel(n, width=w, tooltip=t)
|
||||
#
|
||||
l = self.createLabel("info", fill=True, expand=True, grip=True)
|
||||
|
||||
self.createLabel("info", fill=True, expand=True, grip=True)
|
||||
|
||||
|
||||
class HelpStatusbar(BasicStatusbar):
|
||||
def __init__(self, top):
|
||||
BasicStatusbar.__init__(self, top, row=5, column=0, columnspan=3)
|
||||
self.createLabel("info", fill=True, expand=True)
|
||||
|
||||
|
||||
|
|
|
@ -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/[cm]*/*.py ./pysollib/pysolgtk/[a-p]*.py') );
|
||||
grep { not($_ eq './pysollib/pysoltk.py') } glob('./pysollib/*.py ./pysollib/[cm]*/*.py ./pysollib/pysolgtk/[a-s]*.py') );
|
||||
|
||||
# TEST
|
||||
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );
|
||||
|
|
Loading…
Add table
Reference in a new issue