From f6c646d1a5632d9157d0df9e08205a20c090132e Mon Sep 17 00:00:00 2001 From: skomoroh Date: Sat, 11 Aug 2007 21:20:05 +0000 Subject: [PATCH] * fixed using non-ascii filenames for background images * refactoring: move getBottomImage to Stack as _get*BottomImage * bugfixes git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@191 efabe8c0-fbe8-4139-b769-b5e6d273206e --- pysollib/app.py | 15 +++++++++------ pysollib/game.py | 19 ++++++++++--------- pysollib/gamedb.py | 2 +- pysollib/games/auldlangsyne.py | 5 ++--- pysollib/games/braid.py | 22 +++++++++------------- pysollib/games/calculation.py | 6 ++---- pysollib/games/canfield.py | 3 --- pysollib/games/fan.py | 3 +-- pysollib/games/fortythieves.py | 3 +-- pysollib/games/freecell.py | 6 ++---- pysollib/games/golf.py | 7 +++++-- pysollib/games/gypsy.py | 9 +++++---- pysollib/games/klondike.py | 3 +-- pysollib/games/larasgame.py | 3 +-- pysollib/games/matriarchy.py | 6 ++---- pysollib/games/montana.py | 3 +-- pysollib/games/montecarlo.py | 17 +++++++++-------- pysollib/games/napoleon.py | 3 +-- pysollib/games/numerica.py | 12 ++++++------ pysollib/games/picturegallery.py | 13 +++---------- pysollib/games/pileon.py | 12 ++++-------- pysollib/games/pushpin.py | 6 ++---- pysollib/games/royalcotillion.py | 26 ++++++++++---------------- pysollib/games/siebenbisas.py | 6 ++---- pysollib/games/sultan.py | 11 +++-------- pysollib/games/takeaway.py | 7 +++++-- pysollib/games/terrace.py | 4 +--- pysollib/games/tournament.py | 10 +++------- pysollib/games/unionsquare.py | 3 +-- pysollib/games/wavemotion.py | 22 +++++++++++----------- pysollib/games/windmill.py | 6 ++---- pysollib/options.py | 6 +++++- pysollib/stack.py | 30 +++++++++++++++++++----------- 33 files changed, 139 insertions(+), 170 deletions(-) diff --git a/pysollib/app.py b/pysollib/app.py index 91f43054..c70b7a60 100644 --- a/pysollib/app.py +++ b/pysollib/app.py @@ -1440,34 +1440,37 @@ Please select a %s type %s. def initTiles(self): manager = self.tabletile_manager # find all available tiles + # Note: we use a unicoded filenames dirs = manager.getSearchDirs(self, - ("tiles-*", os.path.join("tiles", 'stretch')), + (u"tiles-*", os.path.join(u"tiles", u"stretch")), "PYSOL_TILES") ##print dirs s = "((\\" + ")|(\\".join(IMAGE_EXTENSIONS) + "))$" - ext_re = re.compile(s, re.I) + ext_re = re.compile(s, re.I | re.U) found, t = [], {} for dir in dirs: - dir = dir.strip() try: names = [] if dir and os.path.isdir(dir): names = os.listdir(dir) - names.sort() for name in names: if not name or not ext_re.search(name): continue + if not isinstance(name, unicode): + try: + name = unicode(name) + except: + continue f = os.path.join(dir, name) if not os.path.isfile(f): continue tile = Tile() tile.filename = f - n = ext_re.sub("", name.strip()) + n = ext_re.sub("", name) if os.path.split(dir)[-1] == 'stretch': tile.stretch = 1 #n = re.sub("[-_]", " ", n) n = n.replace('_', ' ') - ##n = unicode(n) tile.name = n key = n.lower() if key not in t: diff --git a/pysollib/game.py b/pysollib/game.py index 741ef0d6..16af0d2c 100644 --- a/pysollib/game.py +++ b/pysollib/game.py @@ -1641,18 +1641,19 @@ class Game: self.updateStatus(stats=self.app.stats.getStats(self.app.opt.player, self.id)) top_msg = '' if ret: - if ret[0]: # playing time + if ret[0] and ret[1]: top_msg = _(''' You have reached -#%d in the %s of playing time''') % (ret[0], TOP_TITLE) - if ret[1]: # moves - if top_msg: - top_msg += _(''' -and #%d in the %s of moves''') % (ret[1], TOP_TITLE) - else: - top_msg = _(''' +#%d in the %s of playing time +and #%d in the %s of moves.''') % (ret[0], TOP_TITLE, ret[1], TOP_TITLE) + elif ret[0]: # playing time + top_msg = _(''' You have reached -#%d in the %s of moves''') % (ret[1], TOP_TITLE) +#%d in the %s of playing time.''') % (ret[0], TOP_TITLE) + elif ret[1]: # moves + top_msg = _(''' +You have reached +#%d in the %s of moves.''') % (ret[1], TOP_TITLE) return top_msg elif not demo: # only update the session log diff --git a/pysollib/gamedb.py b/pysollib/gamedb.py index 5a824eb6..11ea404c 100644 --- a/pysollib/gamedb.py +++ b/pysollib/gamedb.py @@ -287,7 +287,7 @@ class GI: ("Albert Morehead and Geoffrey Mott-Smith", (25, 42, 48, 173, 303, 547, 738)), ("David Parlett", (64, 98, 294, 338, 654, 674,)), - ("Capt. Jeffrey T. Spaulding", (400,)), + ("Captain Jeffrey T. Spaulding", (400,)), ("John Stoneham", (201,)), ("Bryan Stout", (655,)), ("Bill Taylor", (349,)), diff --git a/pysollib/games/auldlangsyne.py b/pysollib/games/auldlangsyne.py index ea6e2fda..52789338 100644 --- a/pysollib/games/auldlangsyne.py +++ b/pysollib/games/auldlangsyne.py @@ -153,8 +153,7 @@ class Strategy_RowStack(BasicRowStack): return 1 return BasicRowStack.doubleclickHandler(self, event) - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): return _('Tableau. Build regardless of rank and suit.') @@ -219,7 +218,7 @@ class StrategyPlus(Strategy): while c.rank == ACE: self.moveMove(1, stack, self.s.foundations[c.suit]) if stack.canFlipCard(): - stack.flipMove() + stack.flipMove(animation=True) if not stack.cards: break c = stack.cards[-1] diff --git a/pysollib/games/braid.py b/pysollib/games/braid.py index e78398a3..f4085f17 100644 --- a/pysollib/games/braid.py +++ b/pysollib/games/braid.py @@ -99,8 +99,7 @@ class Braid_RowStack(ReserveStack): if not self.cards and self.game.s.braid.cards: self.game.moveMove(1, self.game.s.braid, self) - def getBottomImage(self): - return self.game.app.images.getBraidBottom() + getBottomImage = Stack._getBraidBottomImage class Braid_ReserveStack(ReserveStack): @@ -109,8 +108,7 @@ class Braid_ReserveStack(ReserveStack): return False return ReserveStack.acceptsCards(self, from_stack, cards) - def getBottomImage(self): - return self.game.app.images.getTalonBottom() + getBottomImage = Stack._getTalonBottomImage # /*********************************************************************** @@ -399,8 +397,9 @@ class JewelsStack(OpenStack): class Casket_RowStack(SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + + getBottomImage = Stack._getReserveBottomImage + def acceptsCards(self, from_stack, cards): if not SS_RowStack.acceptsCards(self, from_stack, cards): return False @@ -532,11 +531,6 @@ class Well_TalonStack(DealRowRedealTalonStack): return num_cards -class Well_RowStack(SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - - class Well(Game): Hint_Class = CautiousDefaultHint @@ -570,13 +564,15 @@ class Well(Game): (4,2), (2,4)): x, y = x0+xx*l.XS, y0+yy*l.YS - stack = Well_RowStack(x, y, self, dir=1, max_move=1) + stack = SS_RowStack(x, y, self, dir=1, max_move=1) + stack.getBottomImage = stack._getReserveBottomImage stack.CARD_YOFFSET = 0 s.rows.append(stack) # left stack x, y = l.XM, l.YM+l.YS+l.TEXT_HEIGHT - stack = Well_RowStack(x, y, self, base_rank=ACE, dir=1, max_move=1) + stack = SS_RowStack(x, y, self, base_rank=ACE, dir=1, max_move=1) + stack.getBottomImage = stack._getReserveBottomImage stack.CARD_YOFFSET = 0 s.rows.append(stack) diff --git a/pysollib/games/calculation.py b/pysollib/games/calculation.py index be57a716..0964d4ef 100644 --- a/pysollib/games/calculation.py +++ b/pysollib/games/calculation.py @@ -86,8 +86,7 @@ class BetsyRoss_Foundation(RK_FoundationStack): class Calculation_Foundation(BetsyRoss_Foundation): - def getBottomImage(self): - return self.game.app.images.getLetter(self.cap.base_rank) + getBottomImage = Stack._getLetterImage class Calculation_RowStack(BasicRowStack): @@ -97,8 +96,7 @@ class Calculation_RowStack(BasicRowStack): # this stack accepts any one card from the Waste pile return from_stack is self.game.s.waste and len(cards) == 1 - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): return _('Tableau. Build regardless of rank and suit.') diff --git a/pysollib/games/canfield.py b/pysollib/games/canfield.py index 4c7bba7c..abd54277 100644 --- a/pysollib/games/canfield.py +++ b/pysollib/games/canfield.py @@ -209,9 +209,6 @@ class Canfield(Game): if not self.s.reserves[0].cards[-1].face_up: self.s.reserves[0].flipMove() self.s.reserves[0].moveMove(1, stack) - elif stack in self.s.reserves: - if stack.canFlipCard(): - stack.flipMove() shallHighlightMatch = Game._shallHighlightMatch_ACW diff --git a/pysollib/games/fan.py b/pysollib/games/fan.py index d4e5837b..7024864f 100644 --- a/pysollib/games/fan.py +++ b/pysollib/games/fan.py @@ -621,8 +621,7 @@ class Troika(Fan): class Quads_RowStack(RK_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Quads(Troika): RowStack_Class = StackWrapper(Quads_RowStack, dir=0, diff --git a/pysollib/games/fortythieves.py b/pysollib/games/fortythieves.py index c3a8cef3..c5ba9217 100644 --- a/pysollib/games/fortythieves.py +++ b/pysollib/games/fortythieves.py @@ -953,8 +953,7 @@ class TheSpark(Game): # ************************************************************************/ class DoubleGoldMine_RowStack(AC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class DoubleGoldMine(Streets): diff --git a/pysollib/games/freecell.py b/pysollib/games/freecell.py index 2283516c..047b64f6 100644 --- a/pysollib/games/freecell.py +++ b/pysollib/games/freecell.py @@ -442,8 +442,7 @@ class Repair(FreeCell): # ************************************************************************/ class FourColours_RowStack(AC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class FourColours(FreeCell): Solver_Class = None @@ -484,8 +483,7 @@ class FourColours(FreeCell): class GermanFreeCell_Reserve(ReserveStack): - def getBottomImage(self): - return self.game.app.images.getSuitBottom(self.cap.base_suit) + getBottomImage = Stack._getSuitBottomImage class GermanFreeCell(SevenByFour): diff --git a/pysollib/games/golf.py b/pysollib/games/golf.py index 5929d1b8..26049ba8 100644 --- a/pysollib/games/golf.py +++ b/pysollib/games/golf.py @@ -415,8 +415,11 @@ class FourLeafClovers(Game): for i in range(6): x = l.XM + i*l.XS s.rows.append(UD_RK_RowStack(x, y, self, mod=13, base_rank=NO_RANK)) - - s.foundations.append(FourLeafClovers_Foundation(l.XM+6*l.XS, self.height-l.YS, self, ANY_SUIT, dir=0, mod=13, max_move=0, max_cards=52)) + stack = FourLeafClovers_Foundation(l.XM+6*l.XS, self.height-l.YS, self, + suit=ANY_SUIT, dir=0, mod=13, + max_move=0, max_cards=52) + s.foundations.append(stack) + l.createText(stack, 'n') x, y = l.XM + 7*l.XS, self.height - l.YS s.talon = InitialDealTalonStack(x, y, self) diff --git a/pysollib/games/gypsy.py b/pysollib/games/gypsy.py index 28aeca89..b2255eb2 100644 --- a/pysollib/games/gypsy.py +++ b/pysollib/games/gypsy.py @@ -220,8 +220,7 @@ class MissMilligan_ReserveStack(AC_RowStack): # the reserve stack and the Talon are empty. return len(self.cards) == 0 and len(self.game.s.talon.cards) == 0 - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class MissMilligan(Gypsy): @@ -532,6 +531,9 @@ class Elba(Gypsy): class Millie(Gypsy): Layout_Method = Layout.klondikeLayout + def createGame(self): + Gypsy.createGame(self, playcards=24) + def startGame(self): self.startDealSample() self.s.talon.dealRow() @@ -590,8 +592,7 @@ class RightTriangle_Talon(OpenStack, DealRowTalonStack): def canFlipCard(self): return False - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): return DealRowTalonStack.getHelp(self) diff --git a/pysollib/games/klondike.py b/pysollib/games/klondike.py index 30752a05..ea5b2c56 100644 --- a/pysollib/games/klondike.py +++ b/pysollib/games/klondike.py @@ -1145,8 +1145,7 @@ class GoldRush(Klondike): # ************************************************************************/ class GoldMine_RowStack(AC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class GoldMine(Klondike): diff --git a/pysollib/games/larasgame.py b/pysollib/games/larasgame.py index d1955c56..060996a0 100644 --- a/pysollib/games/larasgame.py +++ b/pysollib/games/larasgame.py @@ -184,8 +184,7 @@ class LarasGame_Reserve(OpenStack): return False return from_stack in self.game.s.rows - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage # /*********************************************************************** diff --git a/pysollib/games/matriarchy.py b/pysollib/games/matriarchy.py index ef131a91..dce786ac 100644 --- a/pysollib/games/matriarchy.py +++ b/pysollib/games/matriarchy.py @@ -141,8 +141,7 @@ class Matriarchy_UpRowStack(SS_RowStack): min_cards=1, max_cards=12) self.CARD_YOFFSET = -self.CARD_YOFFSET - def getBottomImage(self): - return self.game.app.images.getSuitBottom(self.cap.suit) + getBottomImage = Stack._getSuitBottomImage class Matriarchy_DownRowStack(SS_RowStack): @@ -151,8 +150,7 @@ class Matriarchy_DownRowStack(SS_RowStack): base_rank=QUEEN, mod=13, dir=-1, min_cards=1, max_cards=12) - def getBottomImage(self): - return self.game.app.images.getSuitBottom(self.cap.suit) + getBottomImage = Stack._getSuitBottomImage # /*********************************************************************** diff --git a/pysollib/games/montana.py b/pysollib/games/montana.py index 898e346e..9fa09348 100644 --- a/pysollib/games/montana.py +++ b/pysollib/games/montana.py @@ -158,8 +158,7 @@ class Montana_RowStack(BasicRowStack): # bottom to get events for an empty stack prepareBottom = Stack.prepareInvisibleBottom - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Montana(Game): diff --git a/pysollib/games/montecarlo.py b/pysollib/games/montecarlo.py index a1fad6c3..844a5c91 100644 --- a/pysollib/games/montecarlo.py +++ b/pysollib/games/montecarlo.py @@ -119,25 +119,26 @@ class MonteCarlo(Game): # game layout # - def createGame(self): + def createGame(self, rows=5, cols=5): # create layout l, s = Layout(self), self.s # set window - self.setSize(l.XM + 6.5*l.XS, l.YM + 5*l.YS) + self.setSize(l.XM + (cols+1.5)*l.XS, l.YM + rows*l.YS) # create stacks - for i in range(5): - for j in range(5): + for i in range(rows): + for j in range(cols): x, y = l.XM + j*l.XS, l.YM + i*l.YS s.rows.append(self.RowStack_Class(x, y, self, max_accept=1, max_cards=2, dir=0, base_rank=NO_RANK)) - x, y = l.XM + 11*l.XS/2, l.YM + x, y = self.width - l.XS, l.YM s.foundations.append(self.Foundation_Class(x, y, self, suit=ANY_SUIT, - max_move=0, max_cards=self.gameinfo.ncards, base_rank=ANY_RANK)) + max_move=0, base_rank=ANY_RANK, + max_cards=self.gameinfo.ncards)) l.createText(s.foundations[0], "s") - y = y + 2*l.YS + y += 2*l.YS s.talon = self.Talon_Class(x, y, self, max_rounds=1) l.createText(s.talon, "s", text_format="%D") @@ -831,7 +832,7 @@ class DoubletsII(Game): def fillStack(self, stack): if stack in self.s.rows: if stack.cards: - stack.flipMove() + stack.flipMove(animation=True) else: if self.s.talon.cards: old_state = self.enterState(self.S_FILL) diff --git a/pysollib/games/napoleon.py b/pysollib/games/napoleon.py index f3da971e..00d87944 100644 --- a/pysollib/games/napoleon.py +++ b/pysollib/games/napoleon.py @@ -53,8 +53,7 @@ from braid import Braid_Foundation class Napoleon_RowStack(UD_SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Napoleon_ReserveStack(BasicRowStack): diff --git a/pysollib/games/numerica.py b/pysollib/games/numerica.py index 1450caaa..40058ca2 100644 --- a/pysollib/games/numerica.py +++ b/pysollib/games/numerica.py @@ -85,8 +85,7 @@ class Numerica_RowStack(BasicRowStack): # this stack accepts any one card from the Waste pile return from_stack is self.game.s.waste and len(cards) == 1 - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): ##return _('Tableau. Accepts any one card from the Waste.') @@ -263,13 +262,15 @@ class PussInTheCorner_Foundation(SS_FoundationStack): class PussInTheCorner_RowStack(BasicRowStack): + def acceptsCards(self, from_stack, cards): if not BasicRowStack.acceptsCards(self, from_stack, cards): return False # this stack accepts any one card from the Talon return from_stack is self.game.s.talon and len(cards) == 1 - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + + getBottomImage = Stack._getReserveBottomImage + def getHelp(self): ##return _('Tableau. Accepts any one card from the Waste.') return _('Tableau. Build regardless of rank and suit.') @@ -659,8 +660,7 @@ class Strategerie_RowStack(BasicRowStack): return True return False - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): return _('Tableau. Build regardless of rank and suit.') diff --git a/pysollib/games/picturegallery.py b/pysollib/games/picturegallery.py index 8257e04e..7d44973b 100644 --- a/pysollib/games/picturegallery.py +++ b/pysollib/games/picturegallery.py @@ -166,8 +166,7 @@ class PictureGallery_TableauStack(SS_RowStack): return False return True - def getBottomImage(self): - return self.game.app.images.getLetter(self.cap.base_rank) + getBottomImage = Stack._getLetterImage class PictureGallery_RowStack(BasicRowStack): @@ -179,8 +178,7 @@ class PictureGallery_RowStack(BasicRowStack): return False return True - def getBottomImage(self): - return self.game.app.images.getTalonBottom() + getBottomImage = Stack._getTalonBottomImage # /*********************************************************************** @@ -313,8 +311,7 @@ class GreatWheel_RowStack(BasicRowStack): c1, c2 = self.cards[-1], cards[0] return c1.suit == c2.suit and c1.rank == c2.rank+1 - def getBottomImage(self): - return self.game.app.images.getTalonBottom() + getBottomImage = Stack._getTalonBottomImage class GreatWheel(PictureGallery): @@ -374,10 +371,6 @@ class GreatWheel(PictureGallery): # ************************************************************************/ class MountOlympus_Foundation(SS_FoundationStack): - - #def getBottomImage(self): - # return self.game.app.images.getLetter(self.cap.base_rank) - def getHelp(self): return 'Build up in suit by twos.' diff --git a/pysollib/games/pileon.py b/pysollib/games/pileon.py index b7d59bb2..18dbae0f 100644 --- a/pysollib/games/pileon.py +++ b/pysollib/games/pileon.py @@ -49,8 +49,7 @@ from pysollib.pysoltk import MfxCanvasText # ************************************************************************/ class PileOn_RowStack(RK_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def closeStack(self): if len(self.cards) == 4 and isRankSequence(self.cards, dir=0): @@ -255,11 +254,6 @@ class FourByFour_Foundation(AbstractFoundationStack): return _('Foundation. Build up regardless of suit.') -class FourByFour_RowStack(UD_RK_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - - class FourByFour(Game): Hint_Class = FourByFour_Hint @@ -287,7 +281,9 @@ class FourByFour(Game): x, y = l.XM+3*l.XS, l.YM+l.YS for i in range(4): - s.rows.append(FourByFour_RowStack(x, y, self, mod=13)) + stack = UD_RK_RowStack(x, y, self, mod=13) + stack.getBottomImage = stack._getReserveBottomImage + s.rows.append(stack) x += l.XS l.defaultStackGroups() diff --git a/pysollib/games/pushpin.py b/pysollib/games/pushpin.py index 87c8b0c8..5edbcba9 100644 --- a/pysollib/games/pushpin.py +++ b/pysollib/games/pushpin.py @@ -62,8 +62,7 @@ class PushPin_Talon(DealRowTalonStack): if not r.cards: return self.dealRowAvail(rows=[r], sound=sound) return self.dealRowAvail(rows=[self.game.s.rows[0]], sound=sound) - def getBottomImage(self): - return self.game.app.images.getBlankBottom() + getBottomImage = Stack._getBlankBottomImage class PushPin_RowStack(ReserveStack): @@ -117,8 +116,7 @@ class PushPin_RowStack(ReserveStack): game.updateStackMove(game.s.talon, 1|16) # for redo game.leaveState(old_state) - def getBottomImage(self): - return self.game.app.images.getBlankBottom() + getBottomImage = Stack._getBlankBottomImage class PushPin(Game): diff --git a/pysollib/games/royalcotillion.py b/pysollib/games/royalcotillion.py index 0f4ea5da..263b5fdf 100644 --- a/pysollib/games/royalcotillion.py +++ b/pysollib/games/royalcotillion.py @@ -232,8 +232,7 @@ class Alhambra_Hint(CautiousDefaultHint): class Alhambra_RowStack(UD_SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Alhambra_Talon(DealRowTalonStack): @@ -930,11 +929,6 @@ class ShadyLanes(Game): # // Boxing the Compass # ************************************************************************/ -class FourWinds_RowStack(ReserveStack): - def getBottomImage(self): - return self.game.app.images.getSuitBottom(self.cap.base_suit) - - class FourWinds(Game): def createGame(self): @@ -946,7 +940,9 @@ class FourWinds(Game): for i in (0, 1): y = l.YM+l.YS for j in range(4): - s.rows.append(FourWinds_RowStack(x, y, self, base_suit=i)) + stack = ReserveStack(x, y, self, base_suit=i) + stack.getBottomImage = stack._getSuitBottomImage + s.rows.append(stack) y += l.YS x += 6*l.XS # horizontal rows @@ -954,7 +950,9 @@ class FourWinds(Game): for i in (2, 3): x = l.XM+2.5*l.XS for j in range(4): - s.rows.append(FourWinds_RowStack(x, y, self, base_suit=i)) + stack = ReserveStack(x, y, self, base_suit=i) + stack.getBottomImage = stack._getSuitBottomImage + s.rows.append(stack) x += l.XS y += 3*l.YS # foundations @@ -1055,8 +1053,7 @@ class Colonel_RowStack(SS_RowStack): return False return SS_RowStack.canMoveCards(self, cards) - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Colonel(Game): @@ -1122,10 +1119,6 @@ class TheRedAndTheBlack_Reserve(ReserveStack): return True return False -class TheRedAndTheBlack_RowStack(AC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - class TheRedAndTheBlack(Game): Hint_Class = CautiousDefaultHint @@ -1142,7 +1135,8 @@ class TheRedAndTheBlack(Game): x += l.XS x, y = l.XM+2*l.XS, l.YM+l.YS for i in range(4): - stack = TheRedAndTheBlack_RowStack(x, y, self, max_move=1) + stack = AC_RowStack(x, y, self, max_move=1) + stack.getBottomImage = stack._getReserveBottomImage stack.CARD_YOFFSET = 0 s.rows.append(stack) x += l.XS diff --git a/pysollib/games/siebenbisas.py b/pysollib/games/siebenbisas.py index eea36462..767d2fe8 100644 --- a/pysollib/games/siebenbisas.py +++ b/pysollib/games/siebenbisas.py @@ -108,8 +108,7 @@ class SiebenBisAs_RowStack(BasicRowStack): # bottom to get events for an empty stack ###prepareBottom = Stack.prepareInvisibleBottom - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class SiebenBisAs(Game): @@ -195,8 +194,7 @@ class Maze_RowStack(BasicRowStack): # bottom to get events for an empty stack prepareBottom = Stack.prepareInvisibleBottom - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Maze(Game): diff --git a/pysollib/games/sultan.py b/pysollib/games/sultan.py index 085337d0..e5aea135 100644 --- a/pysollib/games/sultan.py +++ b/pysollib/games/sultan.py @@ -687,8 +687,7 @@ class CornerSuite_RowStack(RK_RowStack): if not self.cards: return from_stack is self.game.s.waste return True - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class CornerSuite(Game): @@ -791,11 +790,6 @@ class Marshal(Game): # // Royal Aids # ************************************************************************/ -class RoyalAids_RowStack(KingAC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - - class RoyalAids(Game): Hint_Class = CautiousDefaultHint @@ -823,7 +817,8 @@ class RoyalAids(Game): x, y = l.XM+3.75*l.XS, l.YM+2*l.YS for i in (0,1): - stack = RoyalAids_RowStack(x, y, self, max_move=1) + stack = KingAC_RowStack(x, y, self, max_move=1) + stack.getBottomImage = stack._getReserveBottomImage s.rows.append(stack) stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, 0 x += l.XS diff --git a/pysollib/games/takeaway.py b/pysollib/games/takeaway.py index e507a33c..6071a156 100644 --- a/pysollib/games/takeaway.py +++ b/pysollib/games/takeaway.py @@ -49,6 +49,9 @@ class TakeAway_Foundation(AbstractFoundationStack): def closeStack(self): pass + def getHelp(self): + return _('Foundation. Build up or down regardless of suit.') + class TakeAway(Game): @@ -127,8 +130,8 @@ class Striptease_RowStack(UD_RK_RowStack): (r2 == JACK and r1 == KING)): return True return ((r1+1) % 13 == r2 or (r2+1) % 13 == r1) - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + + getBottomImage = Stack._getReserveBottomImage class Striptease_Reserve(OpenStack): diff --git a/pysollib/games/terrace.py b/pysollib/games/terrace.py index 7b803b3d..b13c2698 100644 --- a/pysollib/games/terrace.py +++ b/pysollib/games/terrace.py @@ -111,9 +111,7 @@ class Terrace_RowStack(AC_RowStack): self.game.s.talon.dealRow(rows=freerows, sound=True) self.game.s.talon.dealCards() # deal first card to WasteStack - - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage # /*********************************************************************** diff --git a/pysollib/games/tournament.py b/pysollib/games/tournament.py index 568c06a3..61056495 100644 --- a/pysollib/games/tournament.py +++ b/pysollib/games/tournament.py @@ -164,10 +164,6 @@ class KingsdownEights_Talon(DealRowTalonStack): self.game.stopSamples() return n -class KingsdownEights_Row(AC_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - class KingsdownEights(Game): Hint_Class = CautiousDefaultHint @@ -191,7 +187,8 @@ class KingsdownEights(Game): x += l.XS x, y = l.XM+2*l.XS, l.YM for i in range(8): - stack = KingsdownEights_Row(x, y, self, max_move=1) + stack = AC_RowStack(x, y, self, max_move=1) + stack.getBottomImage = stack._getReserveBottomImage stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, 0 s.rows.append(stack) x += l.XS @@ -220,8 +217,7 @@ class KingsdownEights(Game): # ************************************************************************/ class Saxony_Reserve(SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): return _('Reserve. Build down by suit.') diff --git a/pysollib/games/unionsquare.py b/pysollib/games/unionsquare.py index 10d90541..71737e3b 100644 --- a/pysollib/games/unionsquare.py +++ b/pysollib/games/unionsquare.py @@ -78,8 +78,7 @@ class UnionSquare_RowStack(OpenStack): stack_dir = (self.cards[1].rank - self.cards[0].rank) % self.cap.mod return (self.cards[-1].rank + stack_dir) % self.cap.mod == cards[0].rank - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage # /*********************************************************************** diff --git a/pysollib/games/wavemotion.py b/pysollib/games/wavemotion.py index 75e82b1a..8940bde8 100644 --- a/pysollib/games/wavemotion.py +++ b/pysollib/games/wavemotion.py @@ -33,36 +33,36 @@ from pysollib.game import Game from pysollib.layout import Layout from pysollib.hint import AbstractHint, DefaultHint, CautiousDefaultHint + # /*********************************************************************** # // Wave Motion # ************************************************************************/ -class WaveMotion_RowStack(SS_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() - class WaveMotion(Game): + RowStack_Class = SS_RowStack # # game layout # - def createGame(self): + def createGame(self, rows=8, reserves=8, playcards=7): # create layout l, s = Layout(self), self.s # set window - w, h = l.XM+8*l.XS, l.YM+2*l.YS+19*l.YOFFSET + max_rows = max(rows, reserves) + w, h = l.XM + max_rows*l.XS, l.YM + 2*l.YS + (12+playcards)*l.YOFFSET self.setSize(w, h) # create stacks - x, y = l.XM, l.YM - for i in range(8): - stack = WaveMotion_RowStack(x, y, self, base_rank=ANY_RANK) + x, y = l.XM + (max_rows-rows)*l.XS/2, l.YM + for i in range(rows): + stack = self.RowStack_Class(x, y, self, base_rank=ANY_RANK) + stack.getBottomImage = stack._getReserveBottomImage s.rows.append(stack) x += l.XS - x, y = l.XM, l.YM+l.YS+12*l.YOFFSET - for i in range(8): + x, y = l.XM + (max_rows-reserves)*l.XS/2, l.YM+l.YS+12*l.YOFFSET + for i in range(reserves): stack = OpenStack(x, y, self, max_accept=0) s.reserves.append(stack) stack.CARD_XOFFSET, stack.CARD_YOFFSET = 0, l.YOFFSET diff --git a/pysollib/games/windmill.py b/pysollib/games/windmill.py index 43d30a09..b50092cb 100644 --- a/pysollib/games/windmill.py +++ b/pysollib/games/windmill.py @@ -154,8 +154,7 @@ class Windmill(Game): class DutchSolitaire_RowStack(UD_RK_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class DutchSolitaire(Windmill): @@ -330,8 +329,7 @@ class Corners(Game): # ************************************************************************/ class Czarina_RowStack(RK_RowStack): - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage class Czarina(Corners): diff --git a/pysollib/options.py b/pysollib/options.py index a4767fe4..23c8bbb6 100644 --- a/pysollib/options.py +++ b/pysollib/options.py @@ -427,6 +427,8 @@ class Options: # general for key, t in self.GENERAL_OPTIONS: val = getattr(self, key) + if isinstance(val, str): + val = unicode(val, 'utf-8') config['general'][key] = val config['general']['recent_gameid'] = self.recent_gameid @@ -537,7 +539,9 @@ class Options: # general for key, t in self.GENERAL_OPTIONS: val = self._getOption('general', key, t) - if val is not None: + if val == 'None': + setattr(self, key, None) + elif val is not None: setattr(self, key, val) recent_gameid = self._getOption('general', 'recent_gameid', 'list') diff --git a/pysollib/stack.py b/pysollib/stack.py index 37f39af8..baa3597e 100644 --- a/pysollib/stack.py +++ b/pysollib/stack.py @@ -734,8 +734,21 @@ class Stack: # Appearance {view} # - def getBottomImage(self): + def _getBlankBottomImage(self): return self.game.app.images.getBlankBottom() + def _getReserveBottomImage(self): + return self.game.app.images.getReserveBottom() + def _getSuitBottomImage(self): + return self.game.app.images.getSuitBottom(self.cap.base_suit) + def _getNoneBottomImage(self): + return None + def _getTalonBottomImage(self): + return self.game.app.images.getTalonBottom() + def _getBraidBottomImage(self): + return self.game.app.images.getBraidBottom() + def _getLetterImage(self): + return self.game.app.images.getLetter(self.cap.base_rank) + getBottomImage = _getBlankBottomImage def getPositionFor(self, card): model, view = self, self @@ -1774,8 +1787,7 @@ class TalonStack(Stack, pass self.top_bottom = self.texts.redeal - def getBottomImage(self): - return self.game.app.images.getTalonBottom() + getBottomImage = Stack._getTalonBottomImage def getRedealImages(self): # returns a tuple of two PhotoImages @@ -1807,8 +1819,7 @@ class InitialDealTalonStack(TalonStack): def initBindings(self): pass # no bottom - def getBottomImage(self): - return None + getBottomImage = Stack._getNoneBottomImage class RedealTalonStack(TalonStack, RedealCards_StackMethods): @@ -2081,8 +2092,7 @@ class AbstractFoundationStack(OpenStack): def quickPlayHandler(self, event, from_stacks=None, to_stacks=None): return 0 - def getBottomImage(self): - return self.game.app.images.getSuitBottom(self.cap.base_suit) + getBottomImage = Stack._getSuitBottomImage def getBaseCard(self): return self._getBaseCard() @@ -2695,8 +2705,7 @@ class ReserveStack(OpenStack): kwdefault(cap, max_accept=1, max_cards=1) OpenStack.__init__(self, x, y, game, **cap) - def getBottomImage(self): - return self.game.app.images.getReserveBottom() + getBottomImage = Stack._getReserveBottomImage def getHelp(self): if self.cap.max_accept == 0: @@ -2725,8 +2734,7 @@ class InvisibleStack(Stack): pass # no bottom - def getBottomImage(self): - return None + getBottomImage = Stack._getNoneBottomImage # /***********************************************************************