1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

* improved solitaire wizard

git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@159 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
skomoroh 2007-05-05 21:13:52 +00:00
parent 92cab44b85
commit 9bf19c0f4c
9 changed files with 207 additions and 134 deletions

View file

@ -43,10 +43,12 @@ class CustomGame(Game):
for w in WizardWidgets:
if isinstance(w, basestring):
continue
if w.widget == 'menu':
v = dict(w.values_map)[ss[w.var_name]]
else:
if w.var_name in ss:
v = ss[w.var_name]
else:
v = w.default
if w.widget == 'menu':
v = dict(w.values_map)[v]
s[w.var_name] = v
##from pprint import pprint; pprint(s)
@ -54,6 +56,7 @@ class CustomGame(Game):
kw = {
'dir': s['found_dir'],
'base_rank': s['found_base_card'],
'mod': 13,
}
if s['found_type'] not in (Spider_SS_Foundation,
Spider_AC_Foundation,):
@ -64,8 +67,6 @@ class CustomGame(Game):
kw['base_rank'] = ACE
elif s['found_base_card'] == ACE:
kw['base_rank'] = KING
if s['found_wrap']:
kw['mod'] = 13
foundation = StackWrapper(s['found_type'], **kw)
# talon
@ -74,6 +75,8 @@ class CustomGame(Game):
}
if s['redeals'] >= 0:
kw['max_rounds'] += 1
if s['talon'] is WasteTalonStack:
kw['num_deal'] = s['deal_to_waste']
talon = StackWrapper(s['talon'], **kw)
# rows
@ -84,20 +87,24 @@ class CustomGame(Game):
}
if s['rows_wrap']:
kw['mod'] = 13
if s['rows_type'] in (UD_SS_RowStack, UD_AC_RowStack,
UD_RK_RowStack, UD_SC_RowStack):
kw['max_move'] = 1
row = StackWrapper(s['rows_type'], **kw)
# layout
layout_kw = {'rows' : s['rows_num'],
'waste' : False,
'texts' : True,
}
layout_kw = {
'rows' : s['rows_num'],
'reserves' : s['reserves_num'],
'waste' : False,
'texts' : True,
}
if s['talon'] is InitialDealTalonStack:
layout_kw['texts'] = False
layout_kw['playcards'] = 12+s['deal_to_rows']
# reserves
if s['reserves_num']:
layout_kw['reserves'] = s['reserves_num']
kw = {
'max_accept': s['reserves_max_accept'],
}
@ -156,10 +163,11 @@ class CustomGame(Game):
for stack in self.s.rows:
stack.canDropCards = stack.spiderCanDropCards
if s['found_base_card'] == ANY_RANK:
# acceptsCards
if s['found_base_card'] == ANY_RANK and s['found_equal']:
for stack in self.s.foundations:
stack.acceptsCards = stack.varyAcceptsCards
stack.getBaseCard = stack.getVaryBaseCard
stack.getBaseCard = stack.varyGetBaseCard
def startGame(self):
@ -213,17 +221,16 @@ class CustomGame(Game):
def registerCustomGame(gameclass):
s = gameclass.SETTINGS
for w in WizardWidgets:
if isinstance(w, basestring):
continue
if w.var_name == 'decks':
v = s['decks']
decks = dict(w.values_map)[v]
if w.var_name == 'redeals':
elif w.var_name == 'redeals':
v = s['redeals']
redeals = dict(w.values_map)[v]
if w.var_name == 'skill_level':
elif w.var_name == 'skill_level':
v = s['skill_level']
skill_level = dict(w.values_map)[v]
gameid = s['gameid']

View file

@ -174,7 +174,6 @@ class GI:
(n_("Two-Deck games"),lambda gi, gt=GT_2DECK_TYPE: gi.si.game_type == gt),
(n_("Three-Deck games"),lambda gi, gt=GT_3DECK_TYPE: gi.si.game_type == gt),
(n_("Four-Deck games"),lambda gi, gt=GT_4DECK_TYPE: gi.si.game_type == gt),
(n_("Cusom games"), lambda gi, gt=GT_CUSTOM: gi.si.game_type == gt),
)
SELECT_ORIGINAL_GAME_BY_TYPE = (

View file

@ -314,7 +314,7 @@ class Layout:
for suit in range(suits):
for i in range(decks):
self.s.foundations.append(S(x+i*XS, y, suit=suit))
y = y + YS
y += YS
# create talon
h = YM + 2*h
@ -341,7 +341,9 @@ class Layout:
decks = self.game.gameinfo.decks
suits = len(self.game.gameinfo.suits) + bool(self.game.gameinfo.trumps)
toprows = reserves + 1 + suits*decks
toprows = suits*decks
if reserves:
toprows += reserves+1
maxrows = max(rows, toprows)
w = XM + maxrows*XS
@ -352,19 +354,21 @@ class Layout:
# create reserves & foundations
x, y = (w - (toprows*XS - XM))/2, YM
for i in range(reserves):
self.s.reserves.append(S(x, y))
x = x + XS
if reserves:
for i in range(reserves):
self.s.reserves.append(S(x, y))
x += XS
x += XS
for suit in range(suits):
for i in range(decks):
x = x + XS
self.s.foundations.append(S(x, y, suit=suit))
x += XS
# create rows
x, y = (w - (rows*XS - XM))/2, YM + YS
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (-999, y - CH / 2, 999999, 999999))
# create talon
@ -416,7 +420,7 @@ class Layout:
x, y = XM, YM
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (-999, -999, x - CW / 2, 999999))
# create foundations
@ -424,18 +428,18 @@ class Layout:
for suit in range(suits):
for i in range(decks):
self.s.foundations.append(S(x+i*XS, y, suit=suit))
y = y + YS
y += YS
# create talon and waste
x, y = x + (decks-1)*XS, h - YS
if texts:
x = x - XS/2
x -= XS/2
self.s.talon = s = S(x, y)
if texts:
# place text right of stack
self._setText(s, anchor="se")
if waste:
x = x - XS
x -= XS
self.s.waste = s = S(x, y)
if texts:
# place text left of stack
@ -495,7 +499,7 @@ class Layout:
for suit in range(suits):
for i in range(decks):
self.s.foundations.append(S(x, y, suit=suit))
x = x + XS
x += XS
if waste:
x = w - 2*XS
self.s.waste = s = S(x, y)
@ -550,7 +554,7 @@ class Layout:
# place text right of stack
self._setText(s, 'ne')
if waste:
x = x + XS
x += XS
self.s.waste = s = S(x, y)
if texts:
# place text below stack
@ -565,8 +569,8 @@ class Layout:
for suit in range(suits / foundrows):
for i in range(decks):
self.s.foundations.append(S(x, y, suit=suit + (row * (suits / 2))))
x = x + XS
y = y + YS
x += XS
y += YS
# below
x = XM
@ -576,7 +580,7 @@ class Layout:
self.setRegion(self.s.rows, (-999, y-CH/2, 999999, 999999))
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
# bottom
if reserves:
@ -615,14 +619,14 @@ class Layout:
x, y = XM, YM
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (-999, -999, x - CW / 2, 999999))
# create foundations
for suit in range(suits):
for i in range(decks):
self.s.foundations.append(S(x+i*XS, y, suit=suit))
y = y + YS
y += YS
# create talon
x, y = XM, h - YS
@ -670,7 +674,7 @@ class Layout:
# place text right of stack
self._setText(s, 'ne')
if waste:
x = x + XS
x += XS
self.s.waste = s = S(x, y)
if texts:
# place text below stack
@ -684,7 +688,7 @@ class Layout:
for i in range(decks):
for rank in range(ranks):
self.s.foundations.append(S(x0, y0, suit=rank))
x0 = x0 + XS
x0 += XS
if i == 1 and decks > 2:
x0, y0 = x, y + YS
y = y0
@ -694,7 +698,7 @@ class Layout:
self.setRegion(self.s.rows, (-999, y - YM / 2, 999999, 999999))
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
# set window
self.size = (XM + maxrows * XS, YM + YS + yextra + h)
@ -735,7 +739,7 @@ class Layout:
# place text right of stack
self._setText(s, 'ne')
if waste:
x = x + XS
x += XS
self.s.waste = s = S(x, y)
if texts:
# place text below stack
@ -751,14 +755,14 @@ class Layout:
if i == decks - 1 and suit == 5:
x0, y0 = x + XS * (toprows - decks), YM
d, x, y = -1, x0, y0
d = d + 1
d += 1
# top center
x, y = XM + XS * decks, YM
self.setRegion(self.s.rows, (x - XM / 2, 0, x + XS * rows, 999999))
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
# set window
self.size = (XM + toprows * XS, YM + YS + yextra + h)
@ -793,25 +797,25 @@ class Layout:
for i in range(decks):
for suit in range(12):
self.s.foundations.append(S(x, y, suit=suit))
x = x + XS
x += XS
x, y = XM, y + YS
# create rows
x, y = XM + XS * ((toprows - rows) / 2), YM + YS * decks
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (XS + XM / 2, YS * decks + YM / 2, XS * 11 - XM / 2, 999999))
# create reserves
x, y = XM, YM + YS * decks
for i in range(reserves / 2):
self.s.reserves.append(S(x, y))
y = y + YS
y += YS
x, y = w - XS, YM + YS * decks
for i in range(reserves / 2):
self.s.reserves.append(S(x, y))
y = y + YS
y += YS
# create talon
x, y = XM, h + YM
@ -853,18 +857,18 @@ class Layout:
for i in range(decks):
for rank in range(ranks):
self.s.foundations.append(S(x, y, suit=rank))
y = y + YS
y += YS
x, y = x + XS, YM
# create rows
x, y = XM, YM
for i in range(rows / 2):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
x, y = XM, (YS + h) / 2
for i in range(rows / 2):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (0, 0, XS * rows / 2 + XM / 2, 999999))
# create reserves
@ -872,7 +876,7 @@ class Layout:
for i in range(decks):
for i in range(reserves / decks):
self.s.reserves.append(S(x, y))
y = y + YS
y += YS
x, y = x + XS, YM + YS * 4
# create talon
@ -919,11 +923,11 @@ class Layout:
x, y = XS + XM * 3, YM
for i in range(rows / 2):
self.s.rows.append(S(x, y))
x = x + XS + XM
x += XS + XM
x, y = XS + XM * 3, (YS + h) / 2
for i in range(rows / 2):
self.s.rows.append(S(x, y))
x = x + XS + XM
x += XS + XM
self.setRegion(self.s.rows, (XS + XM, -999, 999999, 999999))
# create reserves
@ -931,7 +935,7 @@ class Layout:
for i in range(decks):
for i in range(reserves / decks):
self.s.reserves.append(S(x, y))
y = y + YS
y += YS
x, y = x + XS, YM + YS * 4
# set window
@ -963,7 +967,7 @@ class Layout:
x, y = XM, YM
for i in range(suits):
self.s.foundations.append(S(x, y, suit=i))
y = y + YS
y += YS
if i == suits / 2 - 1:
x, y = w - XS, YM
@ -1023,18 +1027,18 @@ class Layout:
for suit in range(suits / 2):
for i in range(decks):
self.s.foundations.append(S(x, y, suit = suit))
x = x + XS
x += XS
x = w - fspace - XS * frows / 2
y = y + YS
y += YS
for suit in range(suits / 2):
for i in range(decks):
self.s.foundations.append(S(x, y, suit = suit + suits / 2))
x = x + XS
x += XS
# bottom
x, y = XM, YM * 2 + YS * 2
for i in range(rows):
self.s.rows.append(S(x, y))
x = x + XS
x += XS
self.setRegion(self.s.rows, (-999, y - YM, 999999, 999999))

View file

@ -2088,7 +2088,7 @@ class AbstractFoundationStack(OpenStack):
return base_card.rank == cards[0].rank
return True # all foundations is empty
def getVaryBaseCard(self):
def varyGetBaseCard(self):
rank = None
for s in self.game.s.foundations:
if s.cards:
@ -2119,11 +2119,6 @@ class RK_FoundationStack(SS_FoundationStack):
def __init__(self, x, y, game, suit=ANY_SUIT, **cap):
SS_FoundationStack.__init__(self, x, y, game, ANY_SUIT, **cap)
def assertStack(self):
SS_FoundationStack.assertStack(self)
##assert self.cap.suit == ANY_SUIT
assert self.cap.color == ANY_COLOR
def getHelp(self):
if self.cap.dir > 0: return _('Foundation. Build up regardless of suit.')
elif self.cap.dir < 0: return _('Foundation. Build down regardless of suit.')

View file

@ -653,7 +653,9 @@ class PysolMenubar(PysolMenubarActions):
self._addSelectOrientalGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
self._addSelectSpecialGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
self.tkopt.gameid)
self._addSelectCustomGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
menu.add_separator()
if self.progress: self.progress.update(step=1)
self._addSelectAllGameSubMenu(games, menu, self.mSelectGame,
@ -755,6 +757,12 @@ class PysolMenubar(PysolMenubarActions):
GI.SELECT_SPECIAL_GAME_BY_TYPE,
self.mSelectGame, self.tkopt.gameid)
def _addSelectCustomGameSubMenu(self, games, menu, command, variable):
submenu = MfxMenu(menu, label=n_("&Cusom games"))
select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM
games = filter(select_func, games)
self.updateGamesMenu(submenu, games)
def _addSelectAllGameSubMenu(self, games, menu, command, variable):
menu = MfxMenu(menu, label=n_("&All games by name"))
n, d = 0, self.__cb_max
@ -797,6 +805,20 @@ class PysolMenubar(PysolMenubarActions):
'value': gi.id,
'label': label}))
def updateGamesMenu(self, menu, games):
menu.delete(0, 'last')
if len(games) == 0:
menu.add_radiobutton(label='<none>', name=None, state='disabled')
elif len(games) > self.__cb_max*4:
games.sort(lambda a, b: cmp(gettext(a.name), gettext(b.name)))
self._addSelectAllGameSubMenu(games, menu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
else:
self._addSelectGameSubSubMenu(games, menu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
#
# Select Game menu actions
#
@ -853,24 +875,13 @@ class PysolMenubar(PysolMenubarActions):
def updateFavoriteGamesMenu(self):
gameids = self.app.opt.favorite_gameid
# delete all entries
submenu = self.__menupath[".menubar.file.favoritegames"][2]
submenu.delete(0, "last")
# insert games
games = []
for id in gameids:
gi = self.app.getGameInfo(id)
if gi:
games.append(gi)
if len(games) > self.__cb_max*4:
games.sort(lambda a, b: cmp(gettext(a.name), gettext(b.name)))
self._addSelectAllGameSubMenu(games, submenu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
else:
self._addSelectGameSubSubMenu(games, submenu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
self.updateGamesMenu(submenu, games)
state = self._getEnabledState
in_favor = self.app.game.id in gameids
menu, index, submenu = self.__menupath[".menubar.file.addtofavorites"]
@ -1367,6 +1378,8 @@ the next time you restart """)+PACKAGE,
from pysollib.wizardutil import write_game, reset_wizard
if edit:
reset_wizard(self.game)
else:
reset_wizard(None)
d = WizardDialog(self.top, _('Solitaire Wizard'), self.app)
if d.status == 0 and d.button == 0:
try:
@ -1385,13 +1398,15 @@ Error while saving game.
''') % str(err),
bitmap='error')
return
if SELECT_GAME_MENU and not edit:
gi = self.app.getGameInfo(gameid)
label = gettext(gi.name)
menu = self.__menupath[".menubar.select.frenchgames.cusomgames"][2]
menu.add_radiobutton(command=self.mSelectGame,
variable=self.tkopt.gameid,
value=gameid, label=label, name=None)
if SELECT_GAME_MENU:
menu = self.__menupath[".menubar.select.cusomgames"][2]
select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM
games = map(self.app.gdb.get,
self.app.gdb.getGamesIdSortedByName())
games = filter(select_func, games)
self.updateGamesMenu(menu, games)
self.tkopt.gameid.set(gameid)
self._mSelectGame(gameid, force=True)
@ -1404,5 +1419,3 @@ Error while saving game.
if self._cancelDrag(break_pause=False): return
self.wizardDialog(edit=True)

View file

@ -63,31 +63,40 @@ class WizardDialog(MfxDialog):
Label(frame, text=w.label).grid(row=row, column=0)
if w.widget == 'entry':
w.variable = var = StringVar()
en = Entry(frame, textvariable=var)
if w.variable is None:
w.variable = StringVar()
en = Entry(frame, textvariable=w.variable)
en.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
elif w.widget == 'menu':
w.variable = var = StringVar()
cb = Combobox(frame, values=tuple(w.values), textvariable=var,
if w.variable is None:
w.variable = StringVar()
cb = Combobox(frame, values=tuple(w.values),
textvariable=w.variable,
state='readonly', width=32)
cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
elif w.widget == 'spin':
w.variable = var = IntVar()
if w.variable is None:
w.variable = IntVar()
else:
# delete all trace callbacks
for mod, cbname in w.variable.trace_vinfo():
w.variable.trace_vdelete(mod, cbname)
from_, to = w.values
##s = Spinbox(frame, textvariable=var, from_=from_, to=to)
##s = Spinbox(frame, textvariable=w.variable, from_=from_, to=to)
s = PysolScale(frame, from_=from_, to=to, resolution=1,
orient='horizontal',
variable=var)
variable=w.variable)
s.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
elif w.widget == 'check':
w.variable = var = BooleanVar()
ch = Checkbutton(frame, variable=var, takefocus=False)
if w.variable is None:
w.variable = BooleanVar()
ch = Checkbutton(frame, variable=w.variable, takefocus=False)
ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
if w.current_value is None:
var.set(w.default)
w.variable.set(w.default)
else:
var.set(w.current_value)
w.variable.set(w.current_value)
row += 1

View file

@ -48,6 +48,7 @@ from pysollib.settings import PACKAGE, WIN_SYSTEM
from pysollib.settings import TOP_TITLE
from pysollib.settings import SELECT_GAME_MENU
from pysollib.settings import USE_FREECELL_SOLVER
from pysollib.settings import DEBUG
from pysollib.gamedb import GI
from pysollib.actions import PysolMenubarActions
@ -656,7 +657,9 @@ class PysolMenubar(PysolMenubarActions):
self._addSelectOrientalGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
self._addSelectSpecialGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
self.tkopt.gameid)
self._addSelectCustomGameSubMenu(games, menu, self.mSelectGame,
self.tkopt.gameid)
menu.add_separator()
if self.progress: self.progress.update(step=1)
self._addSelectAllGameSubMenu(games, menu, self.mSelectGame,
@ -758,6 +761,12 @@ class PysolMenubar(PysolMenubarActions):
GI.SELECT_SPECIAL_GAME_BY_TYPE,
self.mSelectGame, self.tkopt.gameid)
def _addSelectCustomGameSubMenu(self, games, menu, command, variable):
submenu = MfxMenu(menu, label=n_("&Cusom games"))
select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM
games = filter(select_func, games)
self.updateGamesMenu(submenu, games)
def _addSelectAllGameSubMenu(self, games, menu, command, variable):
menu = MfxMenu(menu, label=n_("&All games by name"))
n, d = 0, self.__cb_max
@ -800,6 +809,20 @@ class PysolMenubar(PysolMenubarActions):
'value': gi.id,
'label': label}))
def updateGamesMenu(self, menu, games):
menu.delete(0, 'last')
if len(games) == 0:
menu.add_radiobutton(label='<none>', name=None, state='disabled')
elif len(games) > self.__cb_max*4:
games.sort(lambda a, b: cmp(gettext(a.name), gettext(b.name)))
self._addSelectAllGameSubMenu(games, menu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
else:
self._addSelectGameSubSubMenu(games, menu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
#
# Select Game menu actions
#
@ -856,24 +879,13 @@ class PysolMenubar(PysolMenubarActions):
def updateFavoriteGamesMenu(self):
gameids = self.app.opt.favorite_gameid
# delete all entries
submenu = self.__menupath[".menubar.file.favoritegames"][2]
submenu.delete(0, "last")
# insert games
games = []
for id in gameids:
gi = self.app.getGameInfo(id)
if gi:
games.append(gi)
if len(games) > self.__cb_max*4:
games.sort(lambda a, b: cmp(gettext(a.name), gettext(b.name)))
self._addSelectAllGameSubMenu(games, submenu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
else:
self._addSelectGameSubSubMenu(games, submenu,
command=self.mSelectGame,
variable=self.tkopt.gameid)
self.updateGamesMenu(submenu, games)
state = self._getEnabledState
in_favor = self.app.game.id in gameids
menu, index, submenu = self.__menupath[".menubar.file.addtofavorites"]
@ -1351,6 +1363,8 @@ class PysolMenubar(PysolMenubarActions):
from pysollib.wizardutil import write_game, reset_wizard
if edit:
reset_wizard(self.game)
else:
reset_wizard(None)
d = WizardDialog(self.top, _('Solitaire Wizard'), self.app)
if d.status == 0 and d.button == 0:
try:
@ -1369,13 +1383,14 @@ Error while saving game.
''') % str(err),
bitmap='error')
return
if SELECT_GAME_MENU and not edit:
gi = self.app.getGameInfo(gameid)
label = gettext(gi.name)
menu = self.__menupath[".menubar.select.frenchgames.cusomgames"][2]
menu.add_radiobutton(command=self.mSelectGame,
variable=self.tkopt.gameid,
value=gameid, label=label, name=None)
if SELECT_GAME_MENU:
menu = self.__menupath[".menubar.select.cusomgames"][2]
select_func = lambda gi: gi.si.game_type == GI.GT_CUSTOM
games = map(self.app.gdb.get,
self.app.gdb.getGamesIdSortedByName())
games = filter(select_func, games)
self.updateGamesMenu(menu, games)
self.tkopt.gameid.set(gameid)
self._mSelectGame(gameid, force=True)

View file

@ -64,30 +64,34 @@ class WizardDialog(MfxDialog):
Label(frame, text=w.label).grid(row=row, column=0, padx=2)
if w.widget == 'entry':
w.variable = var = StringVar()
en = Entry(frame, textvariable=var)
if w.variable is None:
w.variable = StringVar()
en = Entry(frame, textvariable=w.variable)
en.grid(row=row, column=1, sticky='ew', padx=2)
elif w.widget == 'menu':
w.variable = var = StringVar()
om = OptionMenu(frame, var, *w.values)
if w.variable is None:
w.variable = StringVar()
om = OptionMenu(frame, w.variable, *w.values)
om.grid(row=row, column=1, sticky='ew', padx=2)
elif w.widget == 'spin':
w.variable = var = IntVar()
if w.variable is None:
w.variable = IntVar()
from_, to = w.values
s = Scale(frame, from_=from_, to=to, resolution=1,
orient='horizontal',
variable=var)
variable=w.variable)
s.grid(row=row, column=1, sticky='ew', padx=2)
elif w.widget == 'check':
w.variable = var = BooleanVar()
ch = Checkbutton(frame, variable=var,
if w.variable is None:
w.variable = BooleanVar()
ch = Checkbutton(frame, variable=w.variable,
takefocus=False, anchor='w')
ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2)
if w.current_value is None:
var.set(w.default)
w.variable.set(w.default)
else:
var.set(w.current_value)
w.variable.set(w.current_value)
row += 1

View file

@ -103,19 +103,27 @@ TalonType = WizSetting(
(n_('Deal to rows'), DealRowTalonStack),
),
default = n_('Initial dealing'),
label = _('Type of talon:'),
label = _('Type:'),
var_name = 'talon',
)
Redeals = WizSetting(
values_map = ((n_('No redeals'), 0),
(n_('One redeal'), 1),
(n_('Two redeals'), 2),
(n_('Three redeals'), 3),
(n_('Unlimited redeals'), -1),
),
default = n_('No redeals'),
label = _('Number of redeals:'),
var_name = 'redeals',
)
DealToWaste = WizSetting(
values_map = (1, 5),
default = 1,
widget = 'spin',
label = _('Deal to waste:'),
var_name = 'deal_to_waste',
)
FoundType = WizSetting(
values_map = ((n_('Same suit'), SS_FoundationStack),
(n_('Alternate color'), AC_FoundationStack),
@ -144,8 +152,8 @@ FoundDir = WizSetting(
var_name = 'found_dir',
)
FoundWrap = WizSetting(
values_map = (True, False),
default = False,
values_map = (0, 1),
default = 0,
label = _('Wrapping:'),
var_name = 'found_wrap',
widget = 'check',
@ -156,6 +164,13 @@ FoundMaxMove = WizSetting(
label = _('Max move cards:'),
var_name = 'found_max_move',
)
FoundEqual = WizSetting(
values_map = (0, 1),
default = 1,
label = _('Equal base cards:'),
var_name = 'found_equal',
widget = 'check',
)
RowsNum = WizSetting(
values_map = (1, 20),
default = 8,
@ -261,19 +276,21 @@ WizardWidgets = (
_('Talon'),
TalonType,
Redeals,
DealToWaste,
_('Foundations'),
FoundType,
FoundBaseCard,
FoundDir,
FoundWrap,
##FoundWrap,
FoundMaxMove,
FoundEqual,
_('Tableau'),
RowsNum,
RowsType,
RowsBaseCard,
RowsDir,
RowsWrap,
RowsMaxMove,
RowsWrap,
_('Reserves'),
ReservesNum,
ReservesMaxAccept,
@ -332,8 +349,11 @@ class MyCustomGame(CustomGame):
if isinstance(v, int):
fd.write(" '%s': %i,\n" % (w.var_name, v))
else:
if w.var_name == 'name' and not v:
v = 'Invalid Game Name'
if w.var_name == 'name':
v = v.replace('\\', '\\\\')
v = v.replace("'", "\\'")
if not v:
v = 'Invalid Game Name'
fd.write(" '%s': '%s',\n" % (w.var_name, v))
fd.write(" 'gameid': %i,\n" % gameid)
fd.write(" 'file': '%s',\n" % os.path.split(fn)[1])
@ -350,11 +370,18 @@ registerCustomGame(MyCustomGame)
return gameid
def reset_wizard(game):
s = game.SETTINGS
for w in WizardWidgets:
if isinstance(w, basestring):
continue
v = s[w.var_name]
if game is None:
# set to default
v = w.default
else:
# set from current game
if w.var_name in game.SETTINGS:
v = game.SETTINGS[w.var_name]
else:
v = w.default
if w.widget == 'menu':
v = gettext(v)
w.current_value = v