mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
+ animated flip
* cleanup code git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@128 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
parent
6d63b6cf54
commit
1e0df4b925
61 changed files with 371 additions and 361 deletions
|
@ -35,11 +35,11 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, sys, types, locale
|
import os, locale
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import EnvError, SubclassResponsibility
|
from mfxutil import EnvError, SubclassResponsibility
|
||||||
from mfxutil import Struct, destruct, openURL
|
from mfxutil import Struct, openURL
|
||||||
from pysolrandom import constructRandom
|
from pysolrandom import constructRandom
|
||||||
from settings import PACKAGE, PACKAGE_URL
|
from settings import PACKAGE, PACKAGE_URL
|
||||||
from settings import TOP_TITLE
|
from settings import TOP_TITLE
|
||||||
|
@ -142,7 +142,7 @@ class PysolMenubarActions:
|
||||||
def _clearMenuState(self):
|
def _clearMenuState(self):
|
||||||
ms = self.menustate
|
ms = self.menustate
|
||||||
for k, v in ms.__dict__.items():
|
for k, v in ms.__dict__.items():
|
||||||
if type(v) is types.ListType:
|
if isinstance(v, list):
|
||||||
ms.__dict__[k] = [0] * len(v)
|
ms.__dict__[k] = [0] * len(v)
|
||||||
else:
|
else:
|
||||||
ms.__dict__[k] = 0
|
ms.__dict__[k] = 0
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, re, types
|
import sys, os, re
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
|
@ -53,7 +53,7 @@ from resource import Music, MusicManager
|
||||||
from images import Images, SubsampledImages
|
from images import Images, SubsampledImages
|
||||||
from pysolrandom import PysolRandom
|
from pysolrandom import PysolRandom
|
||||||
from gamedb import GI, GAME_DB, loadGame
|
from gamedb import GI, GAME_DB, loadGame
|
||||||
from settings import TOP_SIZE, TOP_TITLE, TOOLKIT
|
from settings import TOP_SIZE, TOOLKIT
|
||||||
from settings import DEBUG
|
from settings import DEBUG
|
||||||
from winsystems import TkSettings
|
from winsystems import TkSettings
|
||||||
|
|
||||||
|
@ -342,13 +342,13 @@ class GameStat:
|
||||||
score = game.getGameScore()
|
score = game.getGameScore()
|
||||||
##print 'GameScore:', score
|
##print 'GameScore:', score
|
||||||
score_p = None
|
score_p = None
|
||||||
if not score is None:
|
if score is not None:
|
||||||
score_p = self.score_result.update(
|
score_p = self.score_result.update(
|
||||||
score, game_number, game_start_time)
|
score, game_number, game_start_time)
|
||||||
score = game.getGameScoreCasino()
|
score = game.getGameScoreCasino()
|
||||||
##print 'GameScoreCasino:', score
|
##print 'GameScoreCasino:', score
|
||||||
score_casino_p = None
|
score_casino_p = None
|
||||||
if not score is None:
|
if score is not None:
|
||||||
score_casino_p = self.score_casino_result.update(
|
score_casino_p = self.score_casino_result.update(
|
||||||
score, game_number, game_start_time)
|
score, game_number, game_start_time)
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ class Statistics:
|
||||||
def resetStats(self, player, gameid):
|
def resetStats(self, player, gameid):
|
||||||
self.__resetPrevGames(player, self.prev_games, gameid)
|
self.__resetPrevGames(player, self.prev_games, gameid)
|
||||||
self.__resetPrevGames(player, self.session_games, gameid)
|
self.__resetPrevGames(player, self.session_games, gameid)
|
||||||
if not self.games_stats.has_key(player):
|
if player not in self.games_stats:
|
||||||
return
|
return
|
||||||
if gameid == 0:
|
if gameid == 0:
|
||||||
# remove all games
|
# remove all games
|
||||||
|
@ -402,7 +402,7 @@ class Statistics:
|
||||||
except KeyError: pass
|
except KeyError: pass
|
||||||
|
|
||||||
def __resetPrevGames(self, player, games, gameid):
|
def __resetPrevGames(self, player, games, gameid):
|
||||||
if not games.has_key(player):
|
if player not in games:
|
||||||
return
|
return
|
||||||
if gameid == 0:
|
if gameid == 0:
|
||||||
del games[player]
|
del games[player]
|
||||||
|
@ -416,7 +416,7 @@ class Statistics:
|
||||||
def getFullStats(self, player, gameid):
|
def getFullStats(self, player, gameid):
|
||||||
# returned (won, lost, playing time, moves)
|
# returned (won, lost, playing time, moves)
|
||||||
stats = self.games_stats
|
stats = self.games_stats
|
||||||
if stats.has_key(player) and stats[player].has_key(gameid):
|
if player in stats and gameid in stats[player]:
|
||||||
s = self.games_stats[player][gameid]
|
s = self.games_stats[player][gameid]
|
||||||
return (s.num_won+s.num_perfect,
|
return (s.num_won+s.num_perfect,
|
||||||
s.num_lost,
|
s.num_lost,
|
||||||
|
@ -444,24 +444,24 @@ class Statistics:
|
||||||
ret = self.updateGameStat(player, game, status)
|
ret = self.updateGameStat(player, game, status)
|
||||||
else:
|
else:
|
||||||
# player
|
# player
|
||||||
if not self.prev_games.has_key(player):
|
if player not in self.prev_games:
|
||||||
self.prev_games[player] = []
|
self.prev_games[player] = []
|
||||||
self.prev_games[player].append(log)
|
self.prev_games[player].append(log)
|
||||||
if not self.all_prev_games.has_key(player):
|
if player not in self.all_prev_games:
|
||||||
self.all_prev_games[player] = []
|
self.all_prev_games[player] = []
|
||||||
self.all_prev_games[player].append(log)
|
self.all_prev_games[player].append(log)
|
||||||
ret = self.updateGameStat(player, game, status)
|
ret = self.updateGameStat(player, game, status)
|
||||||
# session log
|
# session log
|
||||||
if not self.session_games.has_key(player):
|
if player not in self.session_games:
|
||||||
self.session_games[player] = []
|
self.session_games[player] = []
|
||||||
self.session_games[player].append(log)
|
self.session_games[player].append(log)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def updateGameStat(self, player, game, status):
|
def updateGameStat(self, player, game, status):
|
||||||
#
|
#
|
||||||
if not self.games_stats.has_key(player):
|
if player not in self.games_stats:
|
||||||
self.games_stats[player] = {}
|
self.games_stats[player] = {}
|
||||||
if not self.games_stats[player].has_key(game.id):
|
if game.id not in self.games_stats[player]:
|
||||||
game_stat = GameStat(game.id)
|
game_stat = GameStat(game.id)
|
||||||
self.games_stats[player][game.id] = game_stat
|
self.games_stats[player][game.id] = game_stat
|
||||||
else:
|
else:
|
||||||
|
@ -644,13 +644,13 @@ class Application:
|
||||||
self.nextgame.loadedgame.gstats.holded = 0
|
self.nextgame.loadedgame.gstats.holded = 0
|
||||||
except:
|
except:
|
||||||
self.nextgame.loadedgame = None
|
self.nextgame.loadedgame = None
|
||||||
elif not self.commandline.game is None:
|
elif self.commandline.game is not None:
|
||||||
gameid = self.gdb.getGameByName(self.commandline.game)
|
gameid = self.gdb.getGameByName(self.commandline.game)
|
||||||
if gameid is None:
|
if gameid is None:
|
||||||
print >> sys.stderr, "WARNING: can't find game:", self.commandline.game
|
print >> sys.stderr, "WARNING: can't find game:", self.commandline.game
|
||||||
else:
|
else:
|
||||||
self.nextgame.id, self.nextgame.random = gameid, None
|
self.nextgame.id, self.nextgame.random = gameid, None
|
||||||
elif not self.commandline.gameid is None:
|
elif self.commandline.gameid is not None:
|
||||||
self.nextgame.id, self.nextgame.random = self.commandline.gameid, None
|
self.nextgame.id, self.nextgame.random = self.commandline.gameid, None
|
||||||
self.opt.game_holded = 0
|
self.opt.game_holded = 0
|
||||||
tmpgame.destruct()
|
tmpgame.destruct()
|
||||||
|
@ -763,7 +763,6 @@ class Application:
|
||||||
id = self.gdb.getGamesIdSortedByName()[0]
|
id = self.gdb.getGamesIdSortedByName()[0]
|
||||||
g = self.getGameClass(id)
|
g = self.getGameClass(id)
|
||||||
gi = self.getGameInfo(id)
|
gi = self.getGameInfo(id)
|
||||||
#assert g and type(g) is types.ClassType and id > 0
|
|
||||||
assert gi is not None and gi.id == id
|
assert gi is not None and gi.id == id
|
||||||
self.game = self.constructGame(id)
|
self.game = self.constructGame(id)
|
||||||
self.gdb.setSelected(id)
|
self.gdb.setSelected(id)
|
||||||
|
@ -923,9 +922,9 @@ class Application:
|
||||||
def loadImages4(self):
|
def loadImages4(self):
|
||||||
# load all remaining images
|
# load all remaining images
|
||||||
for k, v in self.gimages.__dict__.items():
|
for k, v in self.gimages.__dict__.items():
|
||||||
if type(v) is types.ListType:
|
if isinstance(v, list):
|
||||||
for i in range(len(v)):
|
for i in range(len(v)):
|
||||||
if type(v[i]) is types.StringType:
|
if isinstance(v[i], str):
|
||||||
v[i] = loadImage(v[i])
|
v[i] = loadImage(v[i])
|
||||||
if self.intro.progress:
|
if self.intro.progress:
|
||||||
self.intro.progress.update(step=1)
|
self.intro.progress.update(step=1)
|
||||||
|
@ -1037,7 +1036,7 @@ class Application:
|
||||||
images = Images(self.dataloader, cs)
|
images = Images(self.dataloader, cs)
|
||||||
try:
|
try:
|
||||||
if not images.load(app=self, progress=progress):
|
if not images.load(app=self, progress=progress):
|
||||||
raise Exception, "Invalid or damaged "+CARDSET
|
raise Exception("Invalid or damaged "+CARDSET)
|
||||||
simages = SubsampledImages(images)
|
simages = SubsampledImages(images)
|
||||||
if self.opt.cache_cardsets:
|
if self.opt.cache_cardsets:
|
||||||
c = self.cardsets_cache.get(cs.type)
|
c = self.cardsets_cache.get(cs.type)
|
||||||
|
@ -1242,7 +1241,7 @@ Please select a %s type %s.
|
||||||
def constructGame(self, id):
|
def constructGame(self, id):
|
||||||
gi = self.gdb.get(id)
|
gi = self.gdb.get(id)
|
||||||
if gi is None:
|
if gi is None:
|
||||||
raise Exception, "Unknown game (id %d)" % id
|
raise Exception("Unknown game (id %d)" % id)
|
||||||
return gi.gameclass(gi)
|
return gi.gameclass(gi)
|
||||||
|
|
||||||
def getGamesIdSortedById(self):
|
def getGamesIdSortedById(self):
|
||||||
|
@ -1472,7 +1471,7 @@ Please select a %s type %s.
|
||||||
if _debug: print_err(1, 5, 'not integer')
|
if _debug: print_err(1, 5, 'not integer')
|
||||||
return 0
|
return 0
|
||||||
s = int(m.group(1))
|
s = int(m.group(1))
|
||||||
if not s in cs.styles:
|
if s not in cs.styles:
|
||||||
cs.styles.append(s)
|
cs.styles.append(s)
|
||||||
if cs.version >= 5:
|
if cs.version >= 5:
|
||||||
if len(fields) < 7:
|
if len(fields) < 7:
|
||||||
|
@ -1538,7 +1537,7 @@ Please select a %s type %s.
|
||||||
dir = dir.strip()
|
dir = dir.strip()
|
||||||
try:
|
try:
|
||||||
names = []
|
names = []
|
||||||
if dir and os.path.isdir(dir) and not t.has_key(dir):
|
if dir and os.path.isdir(dir) and dir not in t:
|
||||||
t[dir] = 1
|
t[dir] = 1
|
||||||
names = os.listdir(dir)
|
names = os.listdir(dir)
|
||||||
names.sort()
|
names.sort()
|
||||||
|
@ -1625,7 +1624,7 @@ Please select a %s type %s.
|
||||||
##n = unicode(n)
|
##n = unicode(n)
|
||||||
tile.name = n
|
tile.name = n
|
||||||
key = n.lower()
|
key = n.lower()
|
||||||
if not t.has_key(key):
|
if key not in t:
|
||||||
t[key] = 1
|
t[key] = 1
|
||||||
found.append((n, tile))
|
found.append((n, tile))
|
||||||
except EnvError, ex:
|
except EnvError, ex:
|
||||||
|
@ -1666,7 +1665,7 @@ Please select a %s type %s.
|
||||||
n = ext_re.sub("", name.strip())
|
n = ext_re.sub("", name.strip())
|
||||||
obj.name = n
|
obj.name = n
|
||||||
key = n.lower()
|
key = n.lower()
|
||||||
if not t.has_key(key):
|
if key not in t:
|
||||||
t[key] = 1
|
t[key] = 1
|
||||||
found.append((n, obj))
|
found.append((n, obj))
|
||||||
except EnvError, ex:
|
except EnvError, ex:
|
||||||
|
|
139
pysollib/game.py
139
pysollib/game.py
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import time, types
|
import time
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
|
@ -53,8 +53,7 @@ from pysoltk import CURSOR_WATCH
|
||||||
from pysoltk import bind, wm_map
|
from pysoltk import bind, wm_map
|
||||||
from pysoltk import after, after_idle, after_cancel
|
from pysoltk import after, after_idle, after_cancel
|
||||||
from pysoltk import MfxMessageDialog, MfxExceptionDialog
|
from pysoltk import MfxMessageDialog, MfxExceptionDialog
|
||||||
from pysoltk import MfxCanvasText, MfxCanvasImage
|
from pysoltk import MfxCanvasText, MfxCanvasLine, MfxCanvasRectangle
|
||||||
from pysoltk import MfxCanvasLine, MfxCanvasRectangle
|
|
||||||
from pysoltk import Card
|
from pysoltk import Card
|
||||||
from move import AMoveMove, AFlipMove, ATurnStackMove
|
from move import AMoveMove, AFlipMove, ATurnStackMove
|
||||||
from move import ANextRoundMove, ASaveSeedMove, AShuffleStackMove
|
from move import ANextRoundMove, ASaveSeedMove, AShuffleStackMove
|
||||||
|
@ -237,7 +236,7 @@ class Game:
|
||||||
(self._shallHighlightMatch_RK,
|
(self._shallHighlightMatch_RK,
|
||||||
self._shallHighlightMatch_RKW)),):
|
self._shallHighlightMatch_RKW)),):
|
||||||
if isinstance(r, c):
|
if isinstance(r, c):
|
||||||
if not self.shallHighlightMatch in f:
|
if self.shallHighlightMatch not in f:
|
||||||
print 'WARNING: shallHighlightMatch is not valid:', \
|
print 'WARNING: shallHighlightMatch is not valid:', \
|
||||||
class_name, r.__class__
|
class_name, r.__class__
|
||||||
if r.cap.mod == 13 and self.shallHighlightMatch != f[1]:
|
if r.cap.mod == 13 and self.shallHighlightMatch != f[1]:
|
||||||
|
@ -817,7 +816,7 @@ class Game:
|
||||||
if v is None:
|
if v is None:
|
||||||
if sb: sb.updateText(gamenumber="")
|
if sb: sb.updateText(gamenumber="")
|
||||||
continue
|
continue
|
||||||
if type(v) is types.StringType:
|
if isinstance(v, str):
|
||||||
if sb: sb.updateText(gamenumber=v)
|
if sb: sb.updateText(gamenumber=v)
|
||||||
continue
|
continue
|
||||||
if k == "info":
|
if k == "info":
|
||||||
|
@ -825,7 +824,7 @@ class Game:
|
||||||
if v is None:
|
if v is None:
|
||||||
if sb: sb.updateText(info="")
|
if sb: sb.updateText(info="")
|
||||||
continue
|
continue
|
||||||
if type(v) is types.StringType:
|
if isinstance(v, str):
|
||||||
if sb: sb.updateText(info=v)
|
if sb: sb.updateText(info=v)
|
||||||
continue
|
continue
|
||||||
if k == "moves":
|
if k == "moves":
|
||||||
|
@ -833,15 +832,15 @@ class Game:
|
||||||
##if tb: tb.updateText(moves="Moves\n")
|
##if tb: tb.updateText(moves="Moves\n")
|
||||||
if sb: sb.updateText(moves="")
|
if sb: sb.updateText(moves="")
|
||||||
continue
|
continue
|
||||||
if type(v) is types.TupleType:
|
if isinstance(v, tuple):
|
||||||
##if tb: tb.updateText(moves="Moves\n%d/%d" % v)
|
##if tb: tb.updateText(moves="Moves\n%d/%d" % v)
|
||||||
if sb: sb.updateText(moves="%d/%d" % v)
|
if sb: sb.updateText(moves="%d/%d" % v)
|
||||||
continue
|
continue
|
||||||
if type(v) is types.IntType:
|
if isinstance(v, int):
|
||||||
##if tb: tb.updateText(moves="Moves\n%d" % v)
|
##if tb: tb.updateText(moves="Moves\n%d" % v)
|
||||||
if sb: sb.updateText(moves="%d" % v)
|
if sb: sb.updateText(moves="%d" % v)
|
||||||
continue
|
continue
|
||||||
if type(v) is types.StringType:
|
if isinstance(v, str):
|
||||||
##if tb: tb.updateText(moves=v)
|
##if tb: tb.updateText(moves=v)
|
||||||
if sb: sb.updateText(moves=v)
|
if sb: sb.updateText(moves=v)
|
||||||
continue
|
continue
|
||||||
|
@ -849,7 +848,7 @@ class Game:
|
||||||
if v is None:
|
if v is None:
|
||||||
if tb: tb.updateText(player=_("Player\n"))
|
if tb: tb.updateText(player=_("Player\n"))
|
||||||
continue
|
continue
|
||||||
if type(v) in types.StringTypes:
|
if isinstance(v, basestring):
|
||||||
if tb:
|
if tb:
|
||||||
#if self.app.opt.toolbar_size:
|
#if self.app.opt.toolbar_size:
|
||||||
if self.app.toolbar.getSize():
|
if self.app.toolbar.getSize():
|
||||||
|
@ -861,17 +860,17 @@ class Game:
|
||||||
if v is None:
|
if v is None:
|
||||||
if sb: sb.updateText(stats="")
|
if sb: sb.updateText(stats="")
|
||||||
continue
|
continue
|
||||||
if type(v) is types.TupleType:
|
if isinstance(v, tuple):
|
||||||
t = "%d: %d/%d" % (v[0]+v[1], v[0], v[1])
|
t = "%d: %d/%d" % (v[0]+v[1], v[0], v[1])
|
||||||
if sb: sb.updateText(stats=t)
|
if sb: sb.updateText(stats=t)
|
||||||
continue
|
continue
|
||||||
if k == "time":
|
if k == "time":
|
||||||
if v is None:
|
if v is None:
|
||||||
if sb: sb.updateText(time='')
|
if sb: sb.updateText(time='')
|
||||||
if type(v) in types.StringTypes:
|
if isinstance(v, basestring):
|
||||||
if sb: sb.updateText(time=v)
|
if sb: sb.updateText(time=v)
|
||||||
continue
|
continue
|
||||||
raise AttributeError, k
|
raise AttributeError(k)
|
||||||
|
|
||||||
def _unmapHandler(self, event):
|
def _unmapHandler(self, event):
|
||||||
# pause game if root window has been iconified
|
# pause game if root window has been iconified
|
||||||
|
@ -885,7 +884,7 @@ class Game:
|
||||||
|
|
||||||
def playSample(self, name, priority=0, loop=0):
|
def playSample(self, name, priority=0, loop=0):
|
||||||
##print "Game.playSample:", name, priority, loop
|
##print "Game.playSample:", name, priority, loop
|
||||||
if self.app.opt.sound_samples.has_key(name) and \
|
if name in self.app.opt.sound_samples and \
|
||||||
not self.app.opt.sound_samples[name]:
|
not self.app.opt.sound_samples[name]:
|
||||||
return 0
|
return 0
|
||||||
if self.app.audio:
|
if self.app.audio:
|
||||||
|
@ -1009,6 +1008,71 @@ class Game:
|
||||||
card.moveBy(dx, dy)
|
card.moveBy(dx, dy)
|
||||||
self.canvas.update_idletasks()
|
self.canvas.update_idletasks()
|
||||||
|
|
||||||
|
def animatedFlip(self, stack):
|
||||||
|
if self.app.opt.animations == 0:
|
||||||
|
return False
|
||||||
|
if TOOLKIT == 'gtk':
|
||||||
|
return False
|
||||||
|
if not stack.cards:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
import ImageTk # use PIL
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
if self.moves.state == self.S_INIT:
|
||||||
|
# don't use flip animation for initial dealing
|
||||||
|
return False
|
||||||
|
canvas = self.canvas
|
||||||
|
card = stack.cards[-1]
|
||||||
|
im1 = card._active_image._pil_image
|
||||||
|
if card.face_up:
|
||||||
|
im2 = card._back_image._pil_image
|
||||||
|
else:
|
||||||
|
im2 = card._face_image._pil_image
|
||||||
|
w, h = im1.size
|
||||||
|
id = card.item.id
|
||||||
|
#
|
||||||
|
delay = 10
|
||||||
|
frames = 3.0 # num frames for each step
|
||||||
|
if self.app.opt.animations == 3: # slow
|
||||||
|
delay = 10
|
||||||
|
frames = 7.0
|
||||||
|
elif self.app.opt.animations == 4: # very slow
|
||||||
|
delay = 10
|
||||||
|
frames = 12.0
|
||||||
|
delta = 2*int(w/frames/2) # should be even for save position
|
||||||
|
ddx, ddy = 0, self.app.images.SHADOW_YOFFSET/2 # ascent of the card
|
||||||
|
# siep 1
|
||||||
|
ww = w
|
||||||
|
dx = delta/2
|
||||||
|
canvas.move(id, -ddx, -ddy)
|
||||||
|
canvas.update_idletasks()
|
||||||
|
canvas.after(delay)
|
||||||
|
while True:
|
||||||
|
if ww-delta <= 0:
|
||||||
|
break
|
||||||
|
ww -= delta
|
||||||
|
tmp = im1.resize((ww, h))
|
||||||
|
tk_tmp = ImageTk.PhotoImage(image=tmp)
|
||||||
|
canvas.itemconfig(id, image=tk_tmp)
|
||||||
|
canvas.move(id, dx, 0)
|
||||||
|
canvas.update_idletasks()
|
||||||
|
canvas.after(delay)
|
||||||
|
dx = -dx
|
||||||
|
# step 2
|
||||||
|
while True:
|
||||||
|
tmp = im2.resize((ww, h))
|
||||||
|
tk_tmp = ImageTk.PhotoImage(image=tmp)
|
||||||
|
canvas.itemconfig(id, image=tk_tmp)
|
||||||
|
canvas.move(id, dx, 0)
|
||||||
|
canvas.update_idletasks()
|
||||||
|
canvas.after(delay)
|
||||||
|
ww += delta
|
||||||
|
if ww >= w:
|
||||||
|
break
|
||||||
|
canvas.move(id, ddx, ddy)
|
||||||
|
return True
|
||||||
|
|
||||||
def winAnimation(self, perfect=0):
|
def winAnimation(self, perfect=0):
|
||||||
# Stupid animation when you win a game.
|
# Stupid animation when you win a game.
|
||||||
# FIXME: make this interruptible by a key- or mousepress
|
# FIXME: make this interruptible by a key- or mousepress
|
||||||
|
@ -1033,7 +1097,7 @@ class Game:
|
||||||
acards = []
|
acards = []
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
c, s = self.app.miscrandom.choice(cards)
|
c, s = self.app.miscrandom.choice(cards)
|
||||||
if not c in acards:
|
if c not in acards:
|
||||||
acards.append(c)
|
acards.append(c)
|
||||||
# animate
|
# animate
|
||||||
sx, sy = self.s.talon.x, self.s.talon.y
|
sx, sy = self.s.talon.x, self.s.talon.y
|
||||||
|
@ -1117,7 +1181,7 @@ class Game:
|
||||||
# with the same priority
|
# with the same priority
|
||||||
for d in self.regions.data:
|
for d in self.regions.data:
|
||||||
if priority == d[0]:
|
if priority == d[0]:
|
||||||
assert not s in d[2]
|
assert s not in d[2]
|
||||||
# add to regions
|
# add to regions
|
||||||
self.regions.data.append((priority, -len(self.regions.data), tuple(stacks), tuple(rect)))
|
self.regions.data.append((priority, -len(self.regions.data), tuple(stacks), tuple(rect)))
|
||||||
|
|
||||||
|
@ -2427,32 +2491,34 @@ Please report this bug."""))
|
||||||
#
|
#
|
||||||
def pload(t=None, p=p):
|
def pload(t=None, p=p):
|
||||||
obj = p.load()
|
obj = p.load()
|
||||||
if type(t) is types.TypeType:
|
if isinstance(t, type):
|
||||||
assert type(obj) is t, err_txt
|
assert isinstance(obj, t), err_txt
|
||||||
return obj
|
return obj
|
||||||
#
|
#
|
||||||
package = pload()
|
package = pload()
|
||||||
assert type(package) is types.StringType and package == PACKAGE, err_txt
|
assert isinstance(package, str) and package == PACKAGE, err_txt
|
||||||
version = pload()
|
version = pload()
|
||||||
assert type(version) is types.StringType and len(version) <= 20, err_txt
|
assert isinstance(version, str) and len(version) <= 20, err_txt
|
||||||
version_tuple = get_version_tuple(version)
|
version_tuple = get_version_tuple(version)
|
||||||
v = self._getUndumpVersion(version_tuple)
|
v = self._getUndumpVersion(version_tuple)
|
||||||
assert v >= 0 and version_tuple <= VERSION_TUPLE, "Cannot load games saved with\n" + PACKAGE + " version " + version
|
assert v >= 0 and version_tuple <= VERSION_TUPLE, \
|
||||||
|
"Cannot load games saved with\n"+PACKAGE+" version "+version
|
||||||
game_version = 1
|
game_version = 1
|
||||||
bookmark = 0
|
bookmark = 0
|
||||||
if v >= 2:
|
if v >= 2:
|
||||||
vt = pload()
|
vt = pload()
|
||||||
assert type(vt) is types.TupleType and vt == version_tuple, err_txt
|
assert isinstance(vt, tuple) and vt == version_tuple, err_txt
|
||||||
bookmark = pload()
|
bookmark = pload()
|
||||||
assert type(bookmark) is types.IntType and 0 <= bookmark <= 2, "Incompatible savegame format"
|
assert isinstance(bookmark, int) and 0 <= bookmark <= 2, \
|
||||||
|
"Incompatible savegame format"
|
||||||
game_version = pload()
|
game_version = pload()
|
||||||
assert type(game_version) is types.IntType and game_version > 0, err_txt
|
assert isinstance(game_version, int) and game_version > 0, err_txt
|
||||||
if v <= 3:
|
if v <= 3:
|
||||||
bookmark = 0
|
bookmark = 0
|
||||||
#
|
#
|
||||||
id = pload()
|
id = pload()
|
||||||
assert type(id) is types.IntType and id > 0, err_txt
|
assert isinstance(id, int) and id > 0, err_txt
|
||||||
if not GI.PROTECTED_GAMES.has_key(id):
|
if id not in GI.PROTECTED_GAMES:
|
||||||
game = app.constructGame(id)
|
game = app.constructGame(id)
|
||||||
if game:
|
if game:
|
||||||
if not game.canLoadGame(version_tuple, game_version):
|
if not game.canLoadGame(version_tuple, game_version):
|
||||||
|
@ -2468,7 +2534,7 @@ in the current implementation.''' % version
|
||||||
#game.random = pload()
|
#game.random = pload()
|
||||||
#assert isinstance(game.random, PysolRandom), err_txt
|
#assert isinstance(game.random, PysolRandom), err_txt
|
||||||
initial_seed = pload()
|
initial_seed = pload()
|
||||||
assert type(initial_seed) is types.LongType
|
assert isinstance(initial_seed, long)
|
||||||
if initial_seed <= 32000:
|
if initial_seed <= 32000:
|
||||||
game.random = LCRandom31(initial_seed)
|
game.random = LCRandom31(initial_seed)
|
||||||
else:
|
else:
|
||||||
|
@ -2480,15 +2546,14 @@ in the current implementation.''' % version
|
||||||
game.loadinfo.stacks = []
|
game.loadinfo.stacks = []
|
||||||
game.loadinfo.ncards = 0
|
game.loadinfo.ncards = 0
|
||||||
nstacks = pload()
|
nstacks = pload()
|
||||||
#assert type(nstacks) is types.IntType and 1 <= nstacks <= 255, err_txt
|
assert isinstance(nstacks, int) and 1 <= nstacks, err_txt
|
||||||
assert type(nstacks) is types.IntType and 1 <= nstacks, err_txt
|
|
||||||
for i in range(nstacks):
|
for i in range(nstacks):
|
||||||
stack = []
|
stack = []
|
||||||
ncards = pload()
|
ncards = pload()
|
||||||
assert type(ncards) is types.IntType and 0 <= ncards <= 1024, err_txt
|
assert isinstance(ncards, int) and 0 <= ncards <= 1024, err_txt
|
||||||
for j in range(ncards):
|
for j in range(ncards):
|
||||||
card_id = pload(types.IntType)
|
card_id = pload(int)
|
||||||
face_up = pload(types.IntType)
|
face_up = pload(int)
|
||||||
stack.append((card_id, face_up))
|
stack.append((card_id, face_up))
|
||||||
game.loadinfo.stacks.append(stack)
|
game.loadinfo.stacks.append(stack)
|
||||||
game.loadinfo.ncards = game.loadinfo.ncards + ncards
|
game.loadinfo.ncards = game.loadinfo.ncards + ncards
|
||||||
|
@ -2506,7 +2571,7 @@ in the current implementation.''' % version
|
||||||
game.gsaveinfo.__dict__.update(gsaveinfo.__dict__)
|
game.gsaveinfo.__dict__.update(gsaveinfo.__dict__)
|
||||||
elif v >= 1:
|
elif v >= 1:
|
||||||
# not used
|
# not used
|
||||||
talon_base_cards = pload(types.ListType)
|
talon_base_cards = pload(list)
|
||||||
moves = pload()
|
moves = pload()
|
||||||
assert isinstance(moves, Struct), err_txt
|
assert isinstance(moves, Struct), err_txt
|
||||||
game.moves.__dict__.update(moves.__dict__)
|
game.moves.__dict__.update(moves.__dict__)
|
||||||
|
@ -2519,7 +2584,7 @@ in the current implementation.''' % version
|
||||||
game.stats.__dict__.update(stats.__dict__)
|
game.stats.__dict__.update(stats.__dict__)
|
||||||
game._loadGameHook(p)
|
game._loadGameHook(p)
|
||||||
if v >= 4:
|
if v >= 4:
|
||||||
dummy = pload(types.StringType)
|
dummy = pload(str)
|
||||||
assert dummy == "EOF", err_txt
|
assert dummy == "EOF", err_txt
|
||||||
if bookmark == 2:
|
if bookmark == 2:
|
||||||
# copy back all variables that are not saved
|
# copy back all variables that are not saved
|
||||||
|
@ -2533,7 +2598,7 @@ in the current implementation.''' % version
|
||||||
f = None
|
f = None
|
||||||
try:
|
try:
|
||||||
if not self.canSaveGame():
|
if not self.canSaveGame():
|
||||||
raise Exception, "Cannot save this game."
|
raise Exception("Cannot save this game.")
|
||||||
f = open(filename, "wb")
|
f = open(filename, "wb")
|
||||||
p = Pickler(f, binmode)
|
p = Pickler(f, binmode)
|
||||||
self._dumpGame(p)
|
self._dumpGame(p)
|
||||||
|
@ -2633,9 +2698,9 @@ in the current implementation.''' % version
|
||||||
kw = dict([(args[i], args[i+1]) for i in range(0, len(args), 2)])
|
kw = dict([(args[i], args[i+1]) for i in range(0, len(args), 2)])
|
||||||
if not kw:
|
if not kw:
|
||||||
kw = {'info': '', 'help': ''}
|
kw = {'info': '', 'help': ''}
|
||||||
if kw.has_key('info') and self.app.opt.statusbar and self.app.opt.num_cards:
|
if 'info' in kw and self.app.opt.statusbar and self.app.opt.num_cards:
|
||||||
self.app.statusbar.updateText(info=kw['info'])
|
self.app.statusbar.updateText(info=kw['info'])
|
||||||
if kw.has_key('help') and self.app.opt.helpbar:
|
if 'help' in kw and self.app.opt.helpbar:
|
||||||
self.app.helpbar.updateText(info=kw['help'])
|
self.app.helpbar.updateText(info=kw['help'])
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, imp, os, types
|
import imp
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Struct
|
from mfxutil import Struct
|
||||||
|
@ -392,7 +392,7 @@ class GameInfo(Struct):
|
||||||
rules_filename=None,
|
rules_filename=None,
|
||||||
):
|
):
|
||||||
def to_unicode(s):
|
def to_unicode(s):
|
||||||
if not type(s) is unicode:
|
if not isinstance(s, unicode):
|
||||||
return unicode(s, 'utf-8')
|
return unicode(s, 'utf-8')
|
||||||
return s
|
return s
|
||||||
#
|
#
|
||||||
|
@ -403,7 +403,7 @@ class GameInfo(Struct):
|
||||||
if not short_name:
|
if not short_name:
|
||||||
short_name = name
|
short_name = name
|
||||||
short_name = to_unicode(short_name)
|
short_name = to_unicode(short_name)
|
||||||
if type(altnames) in types.StringTypes:
|
if isinstance(altnames, basestring):
|
||||||
altnames = (altnames,)
|
altnames = (altnames,)
|
||||||
altnames = [to_unicode(n) for n in altnames]
|
altnames = [to_unicode(n) for n in altnames]
|
||||||
#
|
#
|
||||||
|
@ -426,19 +426,17 @@ class GameInfo(Struct):
|
||||||
category = GI.GC_FRENCH
|
category = GI.GC_FRENCH
|
||||||
#
|
#
|
||||||
if not (1 <= id <= 999999):
|
if not (1 <= id <= 999999):
|
||||||
raise GameInfoException, name + ": invalid game ID " + str(id)
|
raise GameInfoException(name+": invalid game ID "+str(id))
|
||||||
if category == GI.GC_MAHJONGG:
|
if category == GI.GC_MAHJONGG:
|
||||||
if decks%4:
|
if decks%4:
|
||||||
raise GameInfoException, name + ": invalid number of decks " + str(id)
|
raise GameInfoException(name+": invalid number of decks "+str(id))
|
||||||
else:
|
else:
|
||||||
if not (1 <= decks <= 4):
|
if not (1 <= decks <= 4):
|
||||||
raise GameInfoException, name + ": invalid number of decks " + str(id)
|
raise GameInfoException(name+": invalid number of decks "+str(id))
|
||||||
##if not name or not (2 <= len(short_name) <= 30):
|
|
||||||
## raise GameInfoException, name + ": invalid game name"
|
|
||||||
if not name:
|
if not name:
|
||||||
raise GameInfoException, name + ": invalid game name"
|
raise GameInfoException(name+": invalid game name")
|
||||||
if GI.PROTECTED_GAMES.get(id):
|
if GI.PROTECTED_GAMES.get(id):
|
||||||
raise GameInfoException, name + ": protected game ID " + str(id)
|
raise GameInfoException(name+": protected game ID "+str(id))
|
||||||
#
|
#
|
||||||
for f, l in ((GI.GT_CHILDREN, GI._CHILDREN_GAMES),
|
for f, l in ((GI.GT_CHILDREN, GI._CHILDREN_GAMES),
|
||||||
(GI.GT_OPEN, GI._OPEN_GAMES),
|
(GI.GT_OPEN, GI._OPEN_GAMES),
|
||||||
|
@ -480,7 +478,7 @@ class GameManager:
|
||||||
return self.__selected_key
|
return self.__selected_key
|
||||||
|
|
||||||
def setSelected(self, gameid):
|
def setSelected(self, gameid):
|
||||||
assert self.__all_games.has_key(gameid)
|
assert gameid in self.__all_games
|
||||||
self.__selected_key = gameid
|
self.__selected_key = gameid
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
|
@ -488,29 +486,30 @@ class GameManager:
|
||||||
|
|
||||||
def _check_game(self, gi):
|
def _check_game(self, gi):
|
||||||
##print 'check game:', gi.id, gi.short_name.encode('utf-8')
|
##print 'check game:', gi.id, gi.short_name.encode('utf-8')
|
||||||
if self.__all_games.has_key(gi.id):
|
if gi.id in self.__all_games:
|
||||||
raise GameInfoException, "duplicate game ID %s: %s and %s" % \
|
raise GameInfoException("duplicate game ID %s: %s and %s" %
|
||||||
(gi.id, str(gi.gameclass),
|
(gi.id, str(gi.gameclass),
|
||||||
str(self.__all_games[gi.id].gameclass))
|
str(self.__all_games[gi.id].gameclass)))
|
||||||
if self.__all_gamenames.has_key(gi.name):
|
if gi.name in self.__all_gamenames:
|
||||||
gameclass = self.__all_gamenames[gi.name].gameclass
|
gameclass = self.__all_gamenames[gi.name].gameclass
|
||||||
raise GameInfoException, "duplicate game name %s: %s and %s" % \
|
raise GameInfoException("duplicate game name %s: %s and %s" %
|
||||||
(gi.name, str(gi.gameclass), str(gameclass))
|
(gi.name, str(gi.gameclass),
|
||||||
|
str(gameclass)))
|
||||||
if 1:
|
if 1:
|
||||||
for id, game in self.__all_games.items():
|
for id, game in self.__all_games.items():
|
||||||
if gi.gameclass is game.gameclass:
|
if gi.gameclass is game.gameclass:
|
||||||
raise GameInfoException, \
|
raise GameInfoException(
|
||||||
"duplicate game class %s: %s and %s" % \
|
"duplicate game class %s: %s and %s" %
|
||||||
(gi.id, str(gi.gameclass), str(game.gameclass))
|
(gi.id, str(gi.gameclass), str(game.gameclass)))
|
||||||
for n in gi.altnames:
|
for n in gi.altnames:
|
||||||
if self.__all_gamenames.has_key(n):
|
if n in self.__all_gamenames:
|
||||||
raise GameInfoException, "duplicate game altname %s: %s" % \
|
raise GameInfoException("duplicate game altname %s: %s" %
|
||||||
(gi.id, n)
|
(gi.id, n))
|
||||||
|
|
||||||
def register(self, gi):
|
def register(self, gi):
|
||||||
##print gi.id, gi.short_name.encode('utf-8')
|
##print gi.id, gi.short_name.encode('utf-8')
|
||||||
if not isinstance(gi, GameInfo):
|
if not isinstance(gi, GameInfo):
|
||||||
raise GameInfoException, "wrong GameInfo class"
|
raise GameInfoException("wrong GameInfo class")
|
||||||
gi.plugin = self.loading_plugin
|
gi.plugin = self.loading_plugin
|
||||||
if self.loading_plugin or CHECK_GAMES:
|
if self.loading_plugin or CHECK_GAMES:
|
||||||
self._check_game(gi)
|
self._check_game(gi)
|
||||||
|
|
|
@ -35,13 +35,11 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import EnvError
|
from mfxutil import EnvError
|
||||||
from settings import PACKAGE, PACKAGE_URL, TOOLKIT, VERSION, FC_VERSION
|
from settings import PACKAGE, PACKAGE_URL, TOOLKIT, FC_VERSION
|
||||||
from pysoltk import make_help_toplevel, wm_map
|
from pysoltk import make_help_toplevel
|
||||||
from pysoltk import MfxMessageDialog
|
from pysoltk import MfxMessageDialog
|
||||||
from pysoltk import HTMLViewer
|
from pysoltk import HTMLViewer
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,10 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import struct, os, sys
|
import os, sys
|
||||||
import traceback
|
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Struct, destruct
|
from mfxutil import destruct
|
||||||
from util import KING
|
from util import KING
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,7 +249,7 @@ class AbstractHint(HintInterface):
|
||||||
#
|
#
|
||||||
|
|
||||||
def _canDropAllCards(self, from_stack, stacks, stackcards):
|
def _canDropAllCards(self, from_stack, stacks, stackcards):
|
||||||
assert not from_stack in stacks
|
assert from_stack not in stacks
|
||||||
return 0
|
return 0
|
||||||
# FIXME: this does not account for cards which are dropped herein
|
# FIXME: this does not account for cards which are dropped herein
|
||||||
cards = pile[:]
|
cards = pile[:]
|
||||||
|
@ -785,13 +784,13 @@ class FreeCellSolverWrapper:
|
||||||
]
|
]
|
||||||
#
|
#
|
||||||
game_type = self.fcs_args[3]
|
game_type = self.fcs_args[3]
|
||||||
if game_type.has_key('sbb'):
|
if 'sbb' in game_type:
|
||||||
args += ['--sequences-are-built-by', game_type['sbb']]
|
args += ['--sequences-are-built-by', game_type['sbb']]
|
||||||
if game_type.has_key('sm'):
|
if 'sm' in game_type:
|
||||||
args += ['--sequence-move', game_type['sm']]
|
args += ['--sequence-move', game_type['sm']]
|
||||||
if game_type.has_key('esf'):
|
if 'esf' in game_type:
|
||||||
args += ['--empty-stacks-filled-by', game_type['esf']]
|
args += ['--empty-stacks-filled-by', game_type['esf']]
|
||||||
if game_type.has_key('preset'):
|
if 'preset' in game_type:
|
||||||
args += ['--preset', game_type['preset']]
|
args += ['--preset', game_type['preset']]
|
||||||
|
|
||||||
command = fcs_command+' '+' '.join([str(i) for i in args])
|
command = fcs_command+' '+' '.join([str(i) for i in args])
|
||||||
|
@ -907,7 +906,7 @@ class FreeCellSolverWrapper:
|
||||||
game_type = self.fcs_args[3]
|
game_type = self.fcs_args[3]
|
||||||
game_type_defaults = {'sbb' : 'alternate_color', 'sm' : 'limited', 'esf': 'all'}
|
game_type_defaults = {'sbb' : 'alternate_color', 'sm' : 'limited', 'esf': 'all'}
|
||||||
for k,v in game_type_defaults.items():
|
for k,v in game_type_defaults.items():
|
||||||
if (not game_type.has_key(k)):
|
if k not in game_type:
|
||||||
game_type[k] = v
|
game_type[k] = v
|
||||||
|
|
||||||
solver.config(["--sequences-are-built-by", game_type['sbb'],
|
solver.config(["--sequences-are-built-by", game_type['sbb'],
|
||||||
|
|
|
@ -35,19 +35,13 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, types
|
import os
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Pickler, Unpickler, UnpicklingError
|
|
||||||
from mfxutil import Struct, EnvError
|
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from pysoltk import tkversion, loadImage, copyImage, createImage, shadowImage
|
from pysoltk import tkversion, loadImage, copyImage, createImage, shadowImage
|
||||||
|
|
||||||
try:
|
|
||||||
import Image
|
|
||||||
except ImportError:
|
|
||||||
Image = None
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // Images
|
# // Images
|
||||||
|
@ -110,7 +104,7 @@ class Images:
|
||||||
else:
|
else:
|
||||||
if ((check_w and w != self.CARDW) or
|
if ((check_w and w != self.CARDW) or
|
||||||
(check_h and h != self.CARDH)):
|
(check_h and h != self.CARDH)):
|
||||||
raise Exception, "Invalid size %dx%d of image %s" % (w, h, f)
|
raise ValueError("Invalid size %dx%d of image %s" % (w, h, f))
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def __addBack(self, im1, name):
|
def __addBack(self, im1, name):
|
||||||
|
@ -262,7 +256,7 @@ class Images:
|
||||||
return self._blank_bottom
|
return self._blank_bottom
|
||||||
|
|
||||||
def getSuitBottom(self, suit=-1):
|
def getSuitBottom(self, suit=-1):
|
||||||
assert type(suit) is types.IntType
|
assert isinstance(suit, int)
|
||||||
if suit == -1: return self._bottom[1] # any suit
|
if suit == -1: return self._bottom[1] # any suit
|
||||||
i = 3 + suit
|
i = 3 + suit
|
||||||
if i >= len(self._bottom):
|
if i >= len(self._bottom):
|
||||||
|
@ -295,7 +289,7 @@ class Images:
|
||||||
return self._shade[self._shade_index]
|
return self._shade[self._shade_index]
|
||||||
|
|
||||||
def getShadowCard(self, deck, suit, rank):
|
def getShadowCard(self, deck, suit, rank):
|
||||||
if self._shadow_cards.has_key((suit, rank)):
|
if (suit, rank) in self._shadow_cards:
|
||||||
shade = self._shadow_cards[(suit, rank)]
|
shade = self._shadow_cards[(suit, rank)]
|
||||||
else:
|
else:
|
||||||
image = self.getFace(deck, suit, rank)
|
image = self.getFace(deck, suit, rank)
|
||||||
|
|
|
@ -31,7 +31,7 @@ import settings
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
|
||||||
if os.name == 'nt' and not os.environ.has_key('LANG'):
|
if os.name == 'nt' and 'LANG' not in os.environ:
|
||||||
try:
|
try:
|
||||||
l = locale.getdefaultlocale()
|
l = locale.getdefaultlocale()
|
||||||
os.environ['LANG'] = l[0]
|
os.environ['LANG'] = l[0]
|
||||||
|
@ -51,11 +51,11 @@ def init():
|
||||||
##if locale_dir: locale_dir = os.path.normpath(locale_dir)
|
##if locale_dir: locale_dir = os.path.normpath(locale_dir)
|
||||||
gettext.install('pysol', locale_dir, unicode=True)
|
gettext.install('pysol', locale_dir, unicode=True)
|
||||||
|
|
||||||
if os.environ.has_key('PYSOL_CHECK_GAMES') or \
|
if 'PYSOL_CHECK_GAMES' in os.environ or \
|
||||||
os.environ.has_key('PYSOL_DEBUG'):
|
'PYSOL_DEBUG' in os.environ:
|
||||||
settings.CHECK_GAMES = True
|
settings.CHECK_GAMES = True
|
||||||
print 'PySol debugging: set CHECK_GAMES to True'
|
print 'PySol debugging: set CHECK_GAMES to True'
|
||||||
if os.environ.has_key('PYSOL_DEBUG'):
|
if 'PYSOL_DEBUG' in os.environ:
|
||||||
try:
|
try:
|
||||||
settings.DEBUG = int(os.environ['PYSOL_DEBUG'])
|
settings.DEBUG = int(os.environ['PYSOL_DEBUG'])
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -35,10 +35,9 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys
|
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import destruct, Struct, SubclassResponsibility
|
from mfxutil import Struct
|
||||||
from pysoltk import MfxCanvasText
|
from pysoltk import MfxCanvasText
|
||||||
from resource import CSI
|
from resource import CSI
|
||||||
|
|
||||||
|
@ -129,9 +128,9 @@ class Layout:
|
||||||
|
|
||||||
self.__dict__.update(kw)
|
self.__dict__.update(kw)
|
||||||
if self.game.preview > 1:
|
if self.game.preview > 1:
|
||||||
if kw.has_key("XOFFSET"):
|
if "XOFFSET" in kw:
|
||||||
self.XOFFSET = self.XOFFSET / self.game.preview
|
self.XOFFSET = self.XOFFSET / self.game.preview
|
||||||
if kw.has_key("YOFFSET"):
|
if "YOFFSET" in kw:
|
||||||
self.YOFFSET = self.YOFFSET / self.game.preview
|
self.YOFFSET = self.YOFFSET / self.game.preview
|
||||||
self.TEXT_HEIGHT = 10
|
self.TEXT_HEIGHT = 10
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ class Layout:
|
||||||
#from pprint import pprint
|
#from pprint import pprint
|
||||||
#print mapkey
|
#print mapkey
|
||||||
#pprint(self.stackmap)
|
#pprint(self.stackmap)
|
||||||
assert not self.stackmap.has_key(mapkey)
|
assert mapkey not in self.stackmap
|
||||||
self.stackmap[mapkey] = stack
|
self.stackmap[mapkey] = stack
|
||||||
return stack
|
return stack
|
||||||
|
|
||||||
|
@ -172,7 +171,7 @@ class Layout:
|
||||||
if waste_class:
|
if waste_class:
|
||||||
s.waste = waste_class(self.s.waste.x, self.s.waste.y, game)
|
s.waste = waste_class(self.s.waste.x, self.s.waste.y, game)
|
||||||
if foundation_class:
|
if foundation_class:
|
||||||
if type(foundation_class) in (list, tuple):
|
if isinstance(foundation_class, (list, tuple)):
|
||||||
n = len(self.s.foundations)/len(foundation_class)
|
n = len(self.s.foundations)/len(foundation_class)
|
||||||
i = 0
|
i = 0
|
||||||
for j in range(n):
|
for j in range(n):
|
||||||
|
@ -225,7 +224,7 @@ class Layout:
|
||||||
return (x+self.CW+delta_x, y+self.CH, "sw", f)
|
return (x+self.CW+delta_x, y+self.CH, "sw", f)
|
||||||
if anchor == "e":
|
if anchor == "e":
|
||||||
return (x+self.CW+delta_x, y+self.CH/2, "w", f)
|
return (x+self.CW+delta_x, y+self.CH/2, "w", f)
|
||||||
raise Exception, anchor
|
raise ValueError(anchor)
|
||||||
|
|
||||||
def createText(self, stack, anchor, dx=0, dy=0, text_format=""):
|
def createText(self, stack, anchor, dx=0, dy=0, text_format=""):
|
||||||
if self.canvas.preview > 1:
|
if self.canvas.preview > 1:
|
||||||
|
|
|
@ -40,10 +40,8 @@ import traceback
|
||||||
import getopt
|
import getopt
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import destruct, EnvError
|
|
||||||
from util import DataLoader
|
from util import DataLoader
|
||||||
from resource import Tile
|
from resource import Tile
|
||||||
from gamedb import GI
|
|
||||||
from app import Application
|
from app import Application
|
||||||
from pysolaudio import AbstractAudioClient, PysolSoundServerModuleClient
|
from pysolaudio import AbstractAudioClient, PysolSoundServerModuleClient
|
||||||
from pysolaudio import Win32AudioClient, OSSAudioClient, PyGameAudioClient
|
from pysolaudio import Win32AudioClient, OSSAudioClient, PyGameAudioClient
|
||||||
|
@ -51,8 +49,8 @@ from settings import PACKAGE, SOUND_MOD
|
||||||
from winsystems import initRootWindow
|
from winsystems import initRootWindow
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from pysoltk import wm_withdraw, loadImage
|
from pysoltk import loadImage
|
||||||
from pysoltk import MfxMessageDialog, MfxExceptionDialog
|
from pysoltk import MfxMessageDialog
|
||||||
from pysoltk import MfxRoot
|
from pysoltk import MfxRoot
|
||||||
from pysoltk import PysolProgressBar
|
from pysoltk import PysolProgressBar
|
||||||
|
|
||||||
|
@ -72,7 +70,6 @@ Main data directory is:
|
||||||
Please check your %s installation.
|
Please check your %s installation.
|
||||||
''') % (app.dataloader.dir, PACKAGE),
|
''') % (app.dataloader.dir, PACKAGE),
|
||||||
bitmap="error", strings=(_("&Quit"),))
|
bitmap="error", strings=(_("&Quit"),))
|
||||||
##raise Exception, "no cardsets found !"
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
|
@ -173,7 +170,7 @@ def pysol_init(app, args):
|
||||||
if filename:
|
if filename:
|
||||||
app.commandline.loadgame = filename
|
app.commandline.loadgame = filename
|
||||||
app.commandline.game = opts['game']
|
app.commandline.game = opts['game']
|
||||||
if not opts['gameid'] is None:
|
if opts['gameid'] is not None:
|
||||||
try:
|
try:
|
||||||
app.commandline.gameid = int(opts['gameid'])
|
app.commandline.gameid = int(opts['gameid'])
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -35,8 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, time, types
|
import os, time, types
|
||||||
#import traceback
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cPickle import Pickler, Unpickler, UnpicklingError
|
from cPickle import Pickler, Unpickler, UnpicklingError
|
||||||
|
@ -69,30 +68,7 @@ class SubclassResponsibility(Exception):
|
||||||
# // misc. util
|
# // misc. util
|
||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
## def static(f, *args, **kw):
|
|
||||||
## if args:
|
|
||||||
## a = tuple([f.im_class()] + list(args))
|
|
||||||
## else:
|
|
||||||
## a = (f.im_class(),)
|
|
||||||
## return apply(f, a, kw)
|
|
||||||
|
|
||||||
|
|
||||||
## def ifelse(expr, val1, val2):
|
|
||||||
## if expr:
|
|
||||||
## return val1
|
|
||||||
## return val2
|
|
||||||
|
|
||||||
|
|
||||||
## def merge_dict(dict1, dict2, merge_none=1):
|
|
||||||
## for k, v in dict2.items():
|
|
||||||
## if dict1.has_key(k):
|
|
||||||
## if type(dict1[k]) is type(v):
|
|
||||||
## dict1[k] = v
|
|
||||||
## elif dict2[k] is None and merge_none:
|
|
||||||
## dict1[k] = v
|
|
||||||
|
|
||||||
|
|
||||||
# this is a quick hack - we definitely need Unicode support...
|
|
||||||
def latin1_to_ascii(n):
|
def latin1_to_ascii(n):
|
||||||
#return n
|
#return n
|
||||||
n = n.encode('iso8859-1', 'replace')
|
n = n.encode('iso8859-1', 'replace')
|
||||||
|
@ -198,7 +174,7 @@ def win32_gethomedir():
|
||||||
def destruct(obj):
|
def destruct(obj):
|
||||||
# assist in breaking circular references
|
# assist in breaking circular references
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
assert type(obj) is types.InstanceType
|
assert isinstance(obj, types.InstanceType)
|
||||||
for k in obj.__dict__.keys():
|
for k in obj.__dict__.keys():
|
||||||
obj.__dict__[k] = None
|
obj.__dict__[k] = None
|
||||||
##del obj.__dict__[k]
|
##del obj.__dict__[k]
|
||||||
|
@ -216,30 +192,29 @@ class Struct:
|
||||||
return str(self.__dict__)
|
return str(self.__dict__)
|
||||||
|
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
if not self.__dict__.has_key(key):
|
if key not in self.__dict__:
|
||||||
raise AttributeError, key
|
raise AttributeError(key)
|
||||||
self.__dict__[key] = value
|
self.__dict__[key] = value
|
||||||
|
|
||||||
def addattr(self, **kw):
|
def addattr(self, **kw):
|
||||||
for key in kw.keys():
|
for key in kw.keys():
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
raise AttributeError, key
|
raise AttributeError(key)
|
||||||
self.__dict__.update(kw)
|
self.__dict__.update(kw)
|
||||||
|
|
||||||
def update(self, dict):
|
def update(self, dict):
|
||||||
for key in dict.keys():
|
for key in dict.keys():
|
||||||
if not self.__dict__.has_key(key):
|
if key not in self.__dict__:
|
||||||
raise AttributeError, key
|
raise AttributeError(key)
|
||||||
self.__dict__.update(dict)
|
self.__dict__.update(dict)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
for key in self.__dict__.keys():
|
for key in self.__dict__.keys():
|
||||||
t = type(key)
|
if isinstance(key, list):
|
||||||
if t is types.ListType:
|
|
||||||
self.__dict__[key] = []
|
self.__dict__[key] = []
|
||||||
elif t is types.TupleType:
|
elif isinstance(key, tuple):
|
||||||
self.__dict__[key] = ()
|
self.__dict__[key] = ()
|
||||||
elif t is types.DictType:
|
elif isinstance(key, dict):
|
||||||
self.__dict__[key] = {}
|
self.__dict__[key] = {}
|
||||||
else:
|
else:
|
||||||
self.__dict__[key] = None
|
self.__dict__[key] = None
|
||||||
|
@ -258,7 +233,7 @@ class Struct:
|
||||||
# update keyword arguments with default arguments
|
# update keyword arguments with default arguments
|
||||||
def kwdefault(kw, **defaults):
|
def kwdefault(kw, **defaults):
|
||||||
for k, v in defaults.items():
|
for k, v in defaults.items():
|
||||||
if not kw.has_key(k):
|
if k not in kw:
|
||||||
kw[k] = v
|
kw[k] = v
|
||||||
|
|
||||||
|
|
||||||
|
@ -271,13 +246,13 @@ class KwStruct:
|
||||||
if defaults:
|
if defaults:
|
||||||
kw = kw.copy()
|
kw = kw.copy()
|
||||||
for k, v in defaults.items():
|
for k, v in defaults.items():
|
||||||
if not kw.has_key(k):
|
if k not in kw:
|
||||||
kw[k] = v
|
kw[k] = v
|
||||||
self.__dict__.update(kw)
|
self.__dict__.update(kw)
|
||||||
|
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
if not self.__dict__.has_key(key):
|
if key not in self.__dict__:
|
||||||
raise AttributeError, key
|
raise AttributeError(key)
|
||||||
self.__dict__[key] = value
|
self.__dict__[key] = value
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
|
@ -119,6 +118,7 @@ class AFlipMove(AtomicMove):
|
||||||
# do the actual move
|
# do the actual move
|
||||||
def __doMove(self, game, stack):
|
def __doMove(self, game, stack):
|
||||||
card = stack.cards[-1]
|
card = stack.cards[-1]
|
||||||
|
game.animatedFlip(stack)
|
||||||
if card.face_up:
|
if card.face_up:
|
||||||
card.showBack()
|
card.showBack()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, sys, time
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -88,7 +88,7 @@ class FontsDialog:
|
||||||
label = self.widgets_tree.get_widget(name+'_label')
|
label = self.widgets_tree.get_widget(name+'_label')
|
||||||
font_desc = create_pango_font_desc(font)
|
font_desc = create_pango_font_desc(font)
|
||||||
label.modify_font(font_desc)
|
label.modify_font(font_desc)
|
||||||
text = ' '.join([str(i) for i in font if not i in ('roman', 'normal')])
|
text = ' '.join([str(i) for i in font if i not in ('roman', 'normal')])
|
||||||
label.set_text(text)
|
label.set_text(text)
|
||||||
label.set_data('user_data', font)
|
label.set_data('user_data', font)
|
||||||
|
|
||||||
|
|
|
@ -565,7 +565,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
games = {}
|
games = {}
|
||||||
for gi in mahjongg_games:
|
for gi in mahjongg_games:
|
||||||
c = gettext(gi.short_name).strip()[0]
|
c = gettext(gi.short_name).strip()[0]
|
||||||
if games.has_key(c):
|
if c in games:
|
||||||
games[c].append(gi)
|
games[c].append(gi)
|
||||||
else:
|
else:
|
||||||
games[c] = [gi]
|
games[c] = [gi]
|
||||||
|
@ -610,7 +610,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
'help.rulesforthisgame': '/menubar/help/rules',
|
'help.rulesforthisgame': '/menubar/help/rules',
|
||||||
'options.automaticplay.autodrop': '/menubar/options/automaticplay/optautodrop'
|
'options.automaticplay.autodrop': '/menubar/options/automaticplay/optautodrop'
|
||||||
}
|
}
|
||||||
if path_map.has_key(path):
|
if path in path_map:
|
||||||
path = path_map[path]
|
path = path_map[path]
|
||||||
else:
|
else:
|
||||||
path = '/menubar/'+path.replace('.', '/')
|
path = '/menubar/'+path.replace('.', '/')
|
||||||
|
@ -809,7 +809,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
manager=self.app.tabletile_manager,
|
manager=self.app.tabletile_manager,
|
||||||
key=key)
|
key=key)
|
||||||
if d.status == 0 and d.button in (0, 1):
|
if d.status == 0 and d.button in (0, 1):
|
||||||
if type(d.key) is str:
|
if isinstance(d.key, str):
|
||||||
tile = self.app.tabletile_manager.get(0)
|
tile = self.app.tabletile_manager.get(0)
|
||||||
tile.color = d.key
|
tile.color = d.key
|
||||||
self.app.setTile(0)
|
self.app.setTile(0)
|
||||||
|
|
|
@ -129,12 +129,12 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
items.sort(lambda a, b: cmp(a[1], b[1]))
|
items.sort(lambda a, b: cmp(a[1], b[1]))
|
||||||
added = False
|
added = False
|
||||||
for key, label in items:
|
for key, label in items:
|
||||||
if not getattr(manager, registered).has_key(key):
|
if key not in getattr(manager, registered):
|
||||||
continue
|
continue
|
||||||
cardsets = []
|
cardsets = []
|
||||||
for cs in all_cardsets:
|
for cs in all_cardsets:
|
||||||
si = getattr(cs.si, selecter_type)
|
si = getattr(cs.si, selecter_type)
|
||||||
if type(si) is int: # type
|
if isinstance(si, int): # type
|
||||||
if key == si:
|
if key == si:
|
||||||
cardsets.append((cs.index, cs.name))
|
cardsets.append((cs.index, cs.name))
|
||||||
else: # style, nationality, date
|
else: # style, nationality, date
|
||||||
|
@ -197,7 +197,7 @@ class SelectCardsetDialogWithPreview(MfxDialog):
|
||||||
|
|
||||||
def showSelected(self, w):
|
def showSelected(self, w):
|
||||||
key = self.getSelected()
|
key = self.getSelected()
|
||||||
if not key is None:
|
if key is not None:
|
||||||
self.updatePreview(key)
|
self.updatePreview(key)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,7 @@ class SelectGameDialogWithPreview(MfxDialog):
|
||||||
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
||||||
category = gettext(CSI.TYPE[gi.category])
|
category = gettext(CSI.TYPE[gi.category])
|
||||||
type = ''
|
type = ''
|
||||||
if GI.TYPE_NAMES.has_key(gi.si.game_type):
|
if gi.si.game_type in GI.TYPE_NAMES:
|
||||||
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
||||||
sl = {
|
sl = {
|
||||||
GI.SL_LUCK: _('Luck only'),
|
GI.SL_LUCK: _('Luck only'),
|
||||||
|
|
|
@ -144,7 +144,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
return
|
return
|
||||||
canvas = self.preview
|
canvas = self.preview
|
||||||
##canvas.deleteAllItems()
|
##canvas.deleteAllItems()
|
||||||
if type(key) is str:
|
if isinstance(key, str):
|
||||||
# solid color
|
# solid color
|
||||||
canvas.setTile(self.app, 0, force=True)
|
canvas.setTile(self.app, 0, force=True)
|
||||||
canvas.config(bg=key)
|
canvas.config(bg=key)
|
||||||
|
@ -182,7 +182,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
win = gtk.ColorSelectionDialog(_('Select table color'))
|
win = gtk.ColorSelectionDialog(_('Select table color'))
|
||||||
win.help_button.destroy()
|
win.help_button.destroy()
|
||||||
win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
|
||||||
if type(self.preview_key) is str:
|
if isinstance(self.preview_key, str):
|
||||||
color = self.preview_key
|
color = self.preview_key
|
||||||
else:
|
else:
|
||||||
color = self.app.opt.colors['table']
|
color = self.app.opt.colors['table']
|
||||||
|
|
|
@ -116,7 +116,6 @@ class _CanvasItem:
|
||||||
## ##self._item.get_property('parent').lower_to_bottom()
|
## ##self._item.get_property('parent').lower_to_bottom()
|
||||||
## else:
|
## else:
|
||||||
## print self, positions
|
## print self, positions
|
||||||
## ##~ assert type(positions) is types.IntType and positions > 0
|
|
||||||
## self._item.lower(positions)
|
## self._item.lower(positions)
|
||||||
|
|
||||||
def tkraise(self, positions=None):
|
def tkraise(self, positions=None):
|
||||||
|
@ -127,7 +126,6 @@ class _CanvasItem:
|
||||||
else:
|
else:
|
||||||
#print self, 'tkraise', positions
|
#print self, 'tkraise', positions
|
||||||
#self._item.raise_to_top()
|
#self._item.raise_to_top()
|
||||||
##~ assert type(positions) is types.IntType and positions > 0
|
|
||||||
self._item.raise_to_top() #positions)
|
self._item.raise_to_top() #positions)
|
||||||
|
|
||||||
def move(self, x, y):
|
def move(self, x, y):
|
||||||
|
@ -163,7 +161,7 @@ class MfxCanvasImage(_CanvasItem):
|
||||||
def __init__(self, canvas, x, y, image, anchor=gtk.ANCHOR_NW, group=None):
|
def __init__(self, canvas, x, y, image, anchor=gtk.ANCHOR_NW, group=None):
|
||||||
_CanvasItem.__init__(self, canvas)
|
_CanvasItem.__init__(self, canvas)
|
||||||
self._x, self._y = x, y
|
self._x, self._y = x, y
|
||||||
if type(anchor) is str:
|
if isinstance(anchor, str):
|
||||||
anchor = anchor_tk2gtk(anchor)
|
anchor = anchor_tk2gtk(anchor)
|
||||||
if group:
|
if group:
|
||||||
self._group = group
|
self._group = group
|
||||||
|
@ -187,7 +185,7 @@ class MfxCanvasLine(_CanvasItem):
|
||||||
def __init__(self, canvas, *points, **kw):
|
def __init__(self, canvas, *points, **kw):
|
||||||
_CanvasItem.__init__(self, canvas)
|
_CanvasItem.__init__(self, canvas)
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if kw.has_key('arrow'):
|
if 'arrow' in kw:
|
||||||
if kw['arrow'] == 'first':
|
if kw['arrow'] == 'first':
|
||||||
kwargs['first_arrowhead'] = True
|
kwargs['first_arrowhead'] = True
|
||||||
elif kw['arrow'] == 'last':
|
elif kw['arrow'] == 'last':
|
||||||
|
@ -195,15 +193,15 @@ class MfxCanvasLine(_CanvasItem):
|
||||||
elif kw['arrow'] == 'both':
|
elif kw['arrow'] == 'both':
|
||||||
kwargs['first_arrowhead'] = True
|
kwargs['first_arrowhead'] = True
|
||||||
kwargs['last_arrowhead'] = True
|
kwargs['last_arrowhead'] = True
|
||||||
if kw.has_key('fill'):
|
if 'fill' in kw:
|
||||||
kwargs['fill_color'] = kw['fill']
|
kwargs['fill_color'] = kw['fill']
|
||||||
if kw.has_key('width'):
|
if 'width' in kw:
|
||||||
kwargs['width_units'] = float(kw['width'])
|
kwargs['width_units'] = float(kw['width'])
|
||||||
if kw.has_key('arrowshape'):
|
if 'arrowshape' in kw:
|
||||||
kwargs['arrow_shape_a'] = kw['arrowshape'][0]
|
kwargs['arrow_shape_a'] = kw['arrowshape'][0]
|
||||||
kwargs['arrow_shape_b'] = kw['arrowshape'][1]
|
kwargs['arrow_shape_b'] = kw['arrowshape'][1]
|
||||||
kwargs['arrow_shape_c'] = kw['arrowshape'][2]
|
kwargs['arrow_shape_c'] = kw['arrowshape'][2]
|
||||||
if kw.has_key('group'):
|
if 'group' in kw:
|
||||||
self._group = kw['group']
|
self._group = kw['group']
|
||||||
group = kw['group']._item
|
group = kw['group']._item
|
||||||
else:
|
else:
|
||||||
|
@ -241,7 +239,7 @@ class MfxCanvasText(_CanvasItem):
|
||||||
self._item = None
|
self._item = None
|
||||||
return
|
return
|
||||||
anchor = anchor_tk2gtk(anchor)
|
anchor = anchor_tk2gtk(anchor)
|
||||||
if kw.has_key('group'):
|
if 'group' in kw:
|
||||||
self._group = kw['group']
|
self._group = kw['group']
|
||||||
group = kw['group']._item
|
group = kw['group']._item
|
||||||
del kw['group']
|
del kw['group']
|
||||||
|
@ -249,7 +247,7 @@ class MfxCanvasText(_CanvasItem):
|
||||||
group = canvas.root()
|
group = canvas.root()
|
||||||
self._item = group.add(gnomecanvas.CanvasText,
|
self._item = group.add(gnomecanvas.CanvasText,
|
||||||
x=x, y=y, anchor=anchor)
|
x=x, y=y, anchor=anchor)
|
||||||
if not kw.has_key('fill'):
|
if 'fill' not in kw:
|
||||||
kw['fill'] = canvas._text_color
|
kw['fill'] = canvas._text_color
|
||||||
for k, v in kw.items():
|
for k, v in kw.items():
|
||||||
self[k] = v
|
self[k] = v
|
||||||
|
@ -526,7 +524,7 @@ class MfxCanvas(gnomecanvas.Canvas):
|
||||||
self.__topimage = None
|
self.__topimage = None
|
||||||
if not image:
|
if not image:
|
||||||
return
|
return
|
||||||
if type(image) is str:
|
if isinstance(image, str):
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_file(image)
|
pixbuf = gtk.gdk.pixbuf_new_from_file(image)
|
||||||
else:
|
else:
|
||||||
pixbuf = image.pixbuf
|
pixbuf = image.pixbuf
|
||||||
|
|
|
@ -94,7 +94,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
if self.anchor:
|
if self.anchor:
|
||||||
href = self.anchor[0]
|
href = self.anchor[0]
|
||||||
tag_name = 'href_' + href
|
tag_name = 'href_' + href
|
||||||
if self.viewer.anchor_tags.has_key(tag_name):
|
if tag_name in self.viewer.anchor_tags:
|
||||||
tag = self.viewer.anchor_tags[tag_name][0]
|
tag = self.viewer.anchor_tags[tag_name][0]
|
||||||
else:
|
else:
|
||||||
tag = self.text.create_tag(tag_name, foreground='blue',
|
tag = self.text.create_tag(tag_name, foreground='blue',
|
||||||
|
@ -124,7 +124,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
if font:
|
if font:
|
||||||
##print 'start_font(%s)' % `font`
|
##print 'start_font(%s)' % `font`
|
||||||
self.font_mark = self.text.get_end_iter().get_offset()
|
self.font_mark = self.text.get_end_iter().get_offset()
|
||||||
if self.viewer.fontmap.has_key(font[0]):
|
if font[0] in self.viewer.fontmap:
|
||||||
self.font = font[0]
|
self.font = font[0]
|
||||||
elif font[3]:
|
elif font[3]:
|
||||||
self.font = 'pre'
|
self.font = 'pre'
|
||||||
|
@ -506,7 +506,7 @@ to open the following URL:
|
||||||
|
|
||||||
|
|
||||||
def addHistory(self, url, position=(0,0)):
|
def addHistory(self, url, position=(0,0)):
|
||||||
if not url in self.visited_urls:
|
if url not in self.visited_urls:
|
||||||
self.visited_urls.append(url)
|
self.visited_urls.append(url)
|
||||||
if self.history.index > 0:
|
if self.history.index > 0:
|
||||||
u, pos = self.history.list[self.history.index-1]
|
u, pos = self.history.list[self.history.index-1]
|
||||||
|
@ -548,7 +548,7 @@ to open the following URL:
|
||||||
strings=(_('&OK'),), default=0)
|
strings=(_('&OK'),), default=0)
|
||||||
|
|
||||||
def getImage(self, fn):
|
def getImage(self, fn):
|
||||||
if self.images.has_key(fn):
|
if fn in self.images:
|
||||||
return self.images[fn]
|
return self.images[fn]
|
||||||
try:
|
try:
|
||||||
img = gdk.pixbuf_new_from_file(fn)
|
img = gdk.pixbuf_new_from_file(fn)
|
||||||
|
|
|
@ -338,8 +338,8 @@ class Game_StatsDialog:
|
||||||
|
|
||||||
|
|
||||||
def _updateTop(self, gameid):
|
def _updateTop(self, gameid):
|
||||||
if (not self.app.stats.games_stats.has_key(self.player) or
|
if (self.player not in self.app.stats.games_stats or
|
||||||
not self.app.stats.games_stats[self.player].has_key(gameid) or
|
gameid not in self.app.stats.games_stats[self.player] or
|
||||||
not self.app.stats.games_stats[self.player][gameid].time_result.top):
|
not self.app.stats.games_stats[self.player][gameid].time_result.top):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, string, time, types
|
import sys, os, string, time
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
import pango, gtk
|
import pango, gtk
|
||||||
|
@ -82,10 +82,10 @@ def setTransient(window, parent, relx=0.5, rely=0.3, expose=1):
|
||||||
# ************************************************************************/
|
# ************************************************************************/
|
||||||
|
|
||||||
def anchor_tk2gtk(anchor):
|
def anchor_tk2gtk(anchor):
|
||||||
if type(anchor) is types.IntType:
|
if isinstance(anchor, int):
|
||||||
assert 0 <= anchor <= 8
|
assert 0 <= anchor <= 8
|
||||||
return anchor
|
return anchor
|
||||||
if type(anchor) is types.StringType:
|
if isinstance(anchor, str):
|
||||||
a = ['center', 'n', 'nw', 'ne', 's', 'sw', 'se', 'w', 'e']
|
a = ['center', 'n', 'nw', 'ne', 's', 'sw', 'se', 'w', 'e']
|
||||||
return a.index(string.lower(anchor))
|
return a.index(string.lower(anchor))
|
||||||
assert 0
|
assert 0
|
||||||
|
@ -165,6 +165,10 @@ def shadowImage(image):
|
||||||
# FIXME
|
# FIXME
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def markImage(image):
|
||||||
|
# FIXME
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // event wrapper
|
# // event wrapper
|
||||||
|
@ -254,7 +258,7 @@ def bind(widget, sequence, func, add=None):
|
||||||
wrap, signal = wrap
|
wrap, signal = wrap
|
||||||
#
|
#
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __bindings.has_key(k):
|
if k in __bindings:
|
||||||
__bindings[k].append((wrap, func))
|
__bindings[k].append((wrap, func))
|
||||||
else:
|
else:
|
||||||
l = [(wrap, func)]
|
l = [(wrap, func)]
|
||||||
|
@ -264,7 +268,7 @@ def bind(widget, sequence, func, add=None):
|
||||||
|
|
||||||
def unbind_destroy(widget):
|
def unbind_destroy(widget):
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __bindings.has_key(k):
|
if k in __bindings:
|
||||||
## FIXME
|
## FIXME
|
||||||
del __bindings[k]
|
del __bindings[k]
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, re, time, types
|
import sys, re, time
|
||||||
import random
|
import random
|
||||||
from mfxutil import SubclassResponsibility
|
from mfxutil import SubclassResponsibility
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class MFXRandom:
|
||||||
|
|
||||||
def setSeed(self, seed):
|
def setSeed(self, seed):
|
||||||
seed = self._convertSeed(seed)
|
seed = self._convertSeed(seed)
|
||||||
if type(seed) is not types.LongType:
|
if not isinstance(seed, long):
|
||||||
raise TypeError, "seeds must be longs"
|
raise TypeError, "seeds must be longs"
|
||||||
if not (0L <= seed <= self.MAX_SEED):
|
if not (0L <= seed <= self.MAX_SEED):
|
||||||
raise ValueError, "seed out of range"
|
raise ValueError, "seed out of range"
|
||||||
|
|
|
@ -35,12 +35,10 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, glob, operator, types
|
import os, glob
|
||||||
#import traceback
|
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Struct, KwStruct, EnvError, latin1_to_ascii
|
from mfxutil import Struct, KwStruct, EnvError
|
||||||
from settings import PACKAGE, VERSION
|
|
||||||
from settings import DEBUG
|
from settings import DEBUG
|
||||||
|
|
||||||
gettext = _
|
gettext = _
|
||||||
|
@ -89,7 +87,7 @@ class ResourceManager:
|
||||||
|
|
||||||
def register(self, obj):
|
def register(self, obj):
|
||||||
assert obj.index == -1
|
assert obj.index == -1
|
||||||
assert obj.name and not self._objects_cache_name.has_key(obj.name)
|
assert obj.name and obj.name not in self._objects_cache_name
|
||||||
self._objects_cache_name[obj.name] = obj
|
self._objects_cache_name[obj.name] = obj
|
||||||
if obj.filename:
|
if obj.filename:
|
||||||
obj.absname = os.path.abspath(obj.filename)
|
obj.absname = os.path.abspath(obj.filename)
|
||||||
|
@ -130,13 +128,13 @@ class ResourceManager:
|
||||||
try:
|
try:
|
||||||
if dir:
|
if dir:
|
||||||
dir = os.path.normpath(dir)
|
dir = os.path.normpath(dir)
|
||||||
if dir and os.path.isdir(dir) and not dir in result:
|
if dir and os.path.isdir(dir) and dir not in result:
|
||||||
result.append(dir)
|
result.append(dir)
|
||||||
except EnvError, ex:
|
except EnvError, ex:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getSearchDirs(self, app, search, env=None):
|
def getSearchDirs(self, app, search, env=None):
|
||||||
if type(search) is types.StringType:
|
if isinstance(search, str):
|
||||||
search = (search,)
|
search = (search,)
|
||||||
result = []
|
result = []
|
||||||
if env:
|
if env:
|
||||||
|
@ -378,10 +376,10 @@ class Cardset(Resource):
|
||||||
|
|
||||||
def updateCardback(self, backname=None, backindex=None):
|
def updateCardback(self, backname=None, backindex=None):
|
||||||
# update default back
|
# update default back
|
||||||
if type(backname) is types.StringType:
|
if isinstance(backname, str):
|
||||||
if backname in self.backnames:
|
if backname in self.backnames:
|
||||||
backindex = self.backnames.index(backname)
|
backindex = self.backnames.index(backname)
|
||||||
if type(backindex) is types.IntType:
|
if isinstance(backindex, int):
|
||||||
self.backindex = backindex % len(self.backnames)
|
self.backindex = backindex % len(self.backnames)
|
||||||
self.backname = self.backnames[self.backindex]
|
self.backname = self.backnames[self.backindex]
|
||||||
|
|
||||||
|
@ -397,7 +395,7 @@ class CardsetManager(ResourceManager):
|
||||||
|
|
||||||
def _check(self, cs):
|
def _check(self, cs):
|
||||||
s = cs.type
|
s = cs.type
|
||||||
if not CSI.TYPE.has_key(s):
|
if s not in CSI.TYPE:
|
||||||
return 0
|
return 0
|
||||||
cs.si.type = s
|
cs.si.type = s
|
||||||
if s == CSI.TYPE_FRENCH:
|
if s == CSI.TYPE_FRENCH:
|
||||||
|
@ -473,14 +471,14 @@ class CardsetManager(ResourceManager):
|
||||||
cs.si.size = CSI.SIZE_XLARGE
|
cs.si.size = CSI.SIZE_XLARGE
|
||||||
#
|
#
|
||||||
keys = cs.styles[:]
|
keys = cs.styles[:]
|
||||||
cs.si.styles = tuple(filter(lambda s: CSI.STYLE.has_key(s), keys))
|
cs.si.styles = tuple(filter(lambda s: s in CSI.STYLE, keys))
|
||||||
for s in cs.si.styles:
|
for s in cs.si.styles:
|
||||||
self.registered_styles[s] = self.registered_styles.get(s, 0) + 1
|
self.registered_styles[s] = self.registered_styles.get(s, 0) + 1
|
||||||
cs.si.nationalities = tuple(filter(lambda s: CSI.NATIONALITY.has_key(s), keys))
|
cs.si.nationalities = tuple(filter(lambda s: s in CSI.NATIONALITY, keys))
|
||||||
for s in cs.si.nationalities:
|
for s in cs.si.nationalities:
|
||||||
self.registered_nationalities[s] = self.registered_nationalities.get(s, 0) + 1
|
self.registered_nationalities[s] = self.registered_nationalities.get(s, 0) + 1
|
||||||
keys = (cs.year / 100,)
|
keys = (cs.year / 100,)
|
||||||
cs.si.dates = tuple(filter(lambda s: CSI.DATE.has_key(s), keys))
|
cs.si.dates = tuple(filter(lambda s: s in CSI.DATE, keys))
|
||||||
for s in cs.si.dates:
|
for s in cs.si.dates:
|
||||||
self.registered_dates[s] = self.registered_dates.get(s, 0) + 1
|
self.registered_dates[s] = self.registered_dates.get(s, 0) + 1
|
||||||
#
|
#
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
##
|
##
|
||||||
##---------------------------------------------------------------------------##
|
##---------------------------------------------------------------------------##
|
||||||
|
|
||||||
import sys, os
|
import os
|
||||||
|
|
||||||
n_ = lambda x: x # for gettext
|
n_ = lambda x: x # for gettext
|
||||||
|
|
||||||
|
|
|
@ -91,14 +91,12 @@ __all__ = ['cardsFaceUp',
|
||||||
]
|
]
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import time, types
|
import types
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Struct, kwdefault, SubclassResponsibility
|
from mfxutil import Struct, kwdefault, SubclassResponsibility
|
||||||
from util import Timer
|
from util import ACE, KING
|
||||||
from util import ACE, KING, SUITS
|
|
||||||
from util import ANY_SUIT, ANY_COLOR, ANY_RANK, NO_RANK
|
from util import ANY_SUIT, ANY_COLOR, ANY_RANK, NO_RANK
|
||||||
from util import NO_REDEAL, UNLIMITED_REDEALS, VARIABLE_REDEALS
|
|
||||||
from pysoltk import EVENT_HANDLED, EVENT_PROPAGATE
|
from pysoltk import EVENT_HANDLED, EVENT_PROPAGATE
|
||||||
from pysoltk import CURSOR_DRAG, CURSOR_DOWN_ARROW, CURSOR_CAN_MOVE, CURSOR_NO_MOVE
|
from pysoltk import CURSOR_DRAG, CURSOR_DOWN_ARROW, CURSOR_CAN_MOVE, CURSOR_NO_MOVE
|
||||||
from pysoltk import ANCHOR_NW, ANCHOR_SE
|
from pysoltk import ANCHOR_NW, ANCHOR_SE
|
||||||
|
@ -271,12 +269,12 @@ class Stack:
|
||||||
min_cards = 0, # total number of cards this stack at least requires
|
min_cards = 0, # total number of cards this stack at least requires
|
||||||
)
|
)
|
||||||
model.cap.update(cap)
|
model.cap.update(cap)
|
||||||
assert type(model.cap.suit) is types.IntType
|
assert isinstance(model.cap.suit, int)
|
||||||
assert type(model.cap.color) is types.IntType
|
assert isinstance(model.cap.color, int)
|
||||||
assert type(model.cap.rank) is types.IntType
|
assert isinstance(model.cap.rank, int)
|
||||||
assert type(model.cap.base_suit) is types.IntType
|
assert isinstance(model.cap.base_suit, int)
|
||||||
assert type(model.cap.base_color) is types.IntType
|
assert isinstance(model.cap.base_color, int)
|
||||||
assert type(model.cap.base_rank) is types.IntType
|
assert isinstance(model.cap.base_rank, int)
|
||||||
#
|
#
|
||||||
# view
|
# view
|
||||||
#
|
#
|
||||||
|
@ -354,11 +352,11 @@ class Stack:
|
||||||
assert self.cap.max_move <= 1
|
assert self.cap.max_move <= 1
|
||||||
# prepare some variables
|
# prepare some variables
|
||||||
ox, oy = self.CARD_XOFFSET, self.CARD_YOFFSET
|
ox, oy = self.CARD_XOFFSET, self.CARD_YOFFSET
|
||||||
if type(ox) is types.IntType:
|
if isinstance(ox, int):
|
||||||
self.CARD_XOFFSET = (ox,)
|
self.CARD_XOFFSET = (ox,)
|
||||||
else:
|
else:
|
||||||
self.CARD_XOFFSET = tuple(map(int, map(round, ox)))
|
self.CARD_XOFFSET = tuple(map(int, map(round, ox)))
|
||||||
if type(oy) is types.IntType:
|
if isinstance(oy, int):
|
||||||
self.CARD_YOFFSET = (oy,)
|
self.CARD_YOFFSET = (oy,)
|
||||||
else:
|
else:
|
||||||
self.CARD_YOFFSET = tuple(map(int, map(round, oy)))
|
self.CARD_YOFFSET = tuple(map(int, map(round, oy)))
|
||||||
|
@ -385,7 +383,7 @@ class Stack:
|
||||||
## # and the images don't match
|
## # and the images don't match
|
||||||
## self.max_shadow_cards = 1
|
## self.max_shadow_cards = 1
|
||||||
if (self.game.app.opt.shrink_face_down and
|
if (self.game.app.opt.shrink_face_down and
|
||||||
type(ox) is int and type(oy) is int):
|
isinstance(ox, int) and isinstance(oy, int)):
|
||||||
# no shrink if xoffset/yoffset too small
|
# no shrink if xoffset/yoffset too small
|
||||||
f = self.SHRINK_FACTOR
|
f = self.SHRINK_FACTOR
|
||||||
if ((ox == 0 and oy >= self.game.app.images.CARD_YOFFSET/f) or
|
if ((ox == 0 and oy >= self.game.app.images.CARD_YOFFSET/f) or
|
||||||
|
@ -689,7 +687,7 @@ class Stack:
|
||||||
self.moveMove(ncards, to_stack, frames=frames, shadow=shadow)
|
self.moveMove(ncards, to_stack, frames=frames, shadow=shadow)
|
||||||
if not self.game.checkForWin():
|
if not self.game.checkForWin():
|
||||||
# let the player put cards back from the foundations
|
# let the player put cards back from the foundations
|
||||||
if not self in self.game.s.foundations:
|
if self not in self.game.s.foundations:
|
||||||
self.game.autoPlay()
|
self.game.autoPlay()
|
||||||
self.game.finishMove()
|
self.game.finishMove()
|
||||||
|
|
||||||
|
@ -990,7 +988,7 @@ class Stack:
|
||||||
def __motionEventHandler(self, event):
|
def __motionEventHandler(self, event):
|
||||||
##if not self.game.drag.stack:
|
##if not self.game.drag.stack:
|
||||||
## self._setMotionCursor(event)
|
## self._setMotionCursor(event)
|
||||||
if not self.game.drag.stack or not self is self.game.drag.stack:
|
if not self.game.drag.stack or self is not self.game.drag.stack:
|
||||||
return EVENT_PROPAGATE
|
return EVENT_PROPAGATE
|
||||||
if self.game.demo:
|
if self.game.demo:
|
||||||
self.game.stopDemo(event)
|
self.game.stopDemo(event)
|
||||||
|
@ -2472,7 +2470,7 @@ class ArbitraryStack(OpenStack):
|
||||||
self.singleCardMove(index, to_stack, frames=frames, shadow=shadow)
|
self.singleCardMove(index, to_stack, frames=frames, shadow=shadow)
|
||||||
if not self.game.checkForWin():
|
if not self.game.checkForWin():
|
||||||
# let the player put cards back from the foundations
|
# let the player put cards back from the foundations
|
||||||
if not self in self.game.s.foundations:
|
if self not in self.game.s.foundations:
|
||||||
self.game.autoPlay()
|
self.game.autoPlay()
|
||||||
self.game.finishMove()
|
self.game.finishMove()
|
||||||
|
|
||||||
|
@ -2513,7 +2511,7 @@ class ArbitraryStack(OpenStack):
|
||||||
# self.cap override any call-time cap
|
# self.cap override any call-time cap
|
||||||
class StackWrapper:
|
class StackWrapper:
|
||||||
def __init__(self, stack_class, **cap):
|
def __init__(self, stack_class, **cap):
|
||||||
assert type(stack_class) is types.ClassType
|
assert isinstance(stack_class, types.ClassType)
|
||||||
assert issubclass(stack_class, Stack)
|
assert issubclass(stack_class, Stack)
|
||||||
self.stack_class = stack_class
|
self.stack_class = stack_class
|
||||||
self.cap = cap
|
self.cap = cap
|
||||||
|
|
|
@ -35,11 +35,10 @@
|
||||||
|
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, sys, time, types
|
import time
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import format_time
|
from mfxutil import format_time
|
||||||
from settings import PACKAGE, VERSION
|
|
||||||
from gamedb import GI
|
from gamedb import GI
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +120,7 @@ class PysolStatsFormatter:
|
||||||
def getLogResults(self, player, prev_games):
|
def getLogResults(self, player, prev_games):
|
||||||
twon, tlost = 0, 0
|
twon, tlost = 0, 0
|
||||||
for pg in prev_games:
|
for pg in prev_games:
|
||||||
if type(pg) is not types.TupleType:
|
if not isinstance(pg, tuple):
|
||||||
continue
|
continue
|
||||||
if len(pg) == 5:
|
if len(pg) == 5:
|
||||||
pg = pg + ("", None, None, 1)
|
pg = pg + ("", None, None, 1)
|
||||||
|
@ -132,7 +131,7 @@ class PysolStatsFormatter:
|
||||||
if len(pg) < 8:
|
if len(pg) < 8:
|
||||||
continue
|
continue
|
||||||
gameid = pg[0]
|
gameid = pg[0]
|
||||||
if type(gameid) is not types.IntType:
|
if not isinstance(gameid, int):
|
||||||
continue
|
continue
|
||||||
gi = self.app.getGameInfo(gameid)
|
gi = self.app.getGameInfo(gameid)
|
||||||
if not gi:
|
if not gi:
|
||||||
|
|
|
@ -260,7 +260,7 @@ class Paned(Widget):
|
||||||
subracted to each pane proportionally to its -weight
|
subracted to each pane proportionally to its -weight
|
||||||
"""
|
"""
|
||||||
def __init__(self, master=None, cnf={}, **kw):
|
def __init__(self, master=None, cnf={}, **kw):
|
||||||
if not kw.has_key('orient'):
|
if 'orient' not in kw:
|
||||||
kw['orient'] = 'horizontal'
|
kw['orient'] = 'horizontal'
|
||||||
##Widget.__init__(self, master, "ttk::paned", cnf, kw)
|
##Widget.__init__(self, master, "ttk::paned", cnf, kw)
|
||||||
Widget.__init__(self, master, "ttk::panedwindow", cnf, kw)
|
Widget.__init__(self, master, "ttk::panedwindow", cnf, kw)
|
||||||
|
|
|
@ -41,7 +41,7 @@ __all__ = ['Card']
|
||||||
from pysollib.acard import AbstractCard
|
from pysollib.acard import AbstractCard
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkconst import tkversion, TK_DASH_PATCH
|
from tkconst import TK_DASH_PATCH
|
||||||
from tkcanvas import MfxCanvasGroup, MfxCanvasImage
|
from tkcanvas import MfxCanvasGroup, MfxCanvasImage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,9 @@ class FontChooserDialog(MfxDialog):
|
||||||
self.font_weight = 'normal'
|
self.font_weight = 'normal'
|
||||||
self.font_slant = 'roman'
|
self.font_slant = 'roman'
|
||||||
|
|
||||||
if not init_font is None:
|
if init_font is not None:
|
||||||
assert 2 <= len(init_font) <= 4
|
assert 2 <= len(init_font) <= 4
|
||||||
assert type(init_font[1]) is types.IntType
|
assert isinstance(init_font[1], int)
|
||||||
self.font_family, self.font_size = init_font[:2]
|
self.font_family, self.font_size = init_font[:2]
|
||||||
if len(init_font) > 2:
|
if len(init_font) > 2:
|
||||||
if init_font[2] in ['bold', 'normal']:
|
if init_font[2] in ['bold', 'normal']:
|
||||||
|
@ -64,14 +64,14 @@ class FontChooserDialog(MfxDialog):
|
||||||
elif init_font[2] in ['italic', 'roman']:
|
elif init_font[2] in ['italic', 'roman']:
|
||||||
self.font_slant = init_font[2]
|
self.font_slant = init_font[2]
|
||||||
else:
|
else:
|
||||||
raise TypeError, 'invalid font style: '+ init_font[2]
|
raise ValueError('invalid font style: '+init_font[2])
|
||||||
if len(init_font) > 3:
|
if len(init_font) > 3:
|
||||||
if init_font[3] in ['bold', 'normal']:
|
if init_font[3] in ['bold', 'normal']:
|
||||||
self.font_weight = init_font[3]
|
self.font_weight = init_font[3]
|
||||||
elif init_font[2] in ['italic', 'roman']:
|
elif init_font[2] in ['italic', 'roman']:
|
||||||
self.font_slant = init_font[3]
|
self.font_slant = init_font[3]
|
||||||
else:
|
else:
|
||||||
raise TypeError, 'invalid font style: '+ init_font[3]
|
raise ValueError('invalid font style: '+init_font[3])
|
||||||
|
|
||||||
#self.family_var = Tkinter.StringVar()
|
#self.family_var = Tkinter.StringVar()
|
||||||
self.weight_var = Tkinter.BooleanVar()
|
self.weight_var = Tkinter.BooleanVar()
|
||||||
|
@ -177,7 +177,7 @@ class FontsDialog(MfxDialog):
|
||||||
Tkinter.Label(frame, text=title, anchor='w'
|
Tkinter.Label(frame, text=title, anchor='w'
|
||||||
).grid(row=row, column=0, sticky='we')
|
).grid(row=row, column=0, sticky='we')
|
||||||
if font:
|
if font:
|
||||||
title = ' '.join([str(i) for i in font if not i in ('roman', 'normal')])
|
title = ' '.join([str(i) for i in font if i not in ('roman', 'normal')])
|
||||||
elif font is None:
|
elif font is None:
|
||||||
title = 'Default'
|
title = 'Default'
|
||||||
l = Tkinter.Label(frame, font=font, text=title)
|
l = Tkinter.Label(frame, font=font, text=title)
|
||||||
|
@ -195,7 +195,7 @@ class FontsDialog(MfxDialog):
|
||||||
d = FontChooserDialog(self.top, _('Select font'), self.fonts[fn])
|
d = FontChooserDialog(self.top, _('Select font'), self.fonts[fn])
|
||||||
if d.status == 0 and d.button == 0:
|
if d.status == 0 and d.button == 0:
|
||||||
self.fonts[fn] = d.font
|
self.fonts[fn] = d.font
|
||||||
title = ' '.join([str(i) for i in d.font if not i in ('roman', 'normal')])
|
title = ' '.join([str(i) for i in d.font if i not in ('roman', 'normal')])
|
||||||
label.configure(font=d.font, text=title)
|
label.configure(font=d.font, text=title)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ class GameInfoDialog(MfxDialog):
|
||||||
fs = {}
|
fs = {}
|
||||||
for f in stacks:
|
for f in stacks:
|
||||||
cn = f.__class__.__name__
|
cn = f.__class__.__name__
|
||||||
if fs.has_key(cn):
|
if cn in fs:
|
||||||
fs[cn] += 1
|
fs[cn] += 1
|
||||||
else:
|
else:
|
||||||
fs[cn] = 1
|
fs[cn] = 1
|
||||||
|
|
|
@ -168,7 +168,7 @@ class MfxMenubar(Tkinter.Menu):
|
||||||
|
|
||||||
class MfxMenu(MfxMenubar):
|
class MfxMenu(MfxMenubar):
|
||||||
def __init__(self, master, label, underline=None, **kw):
|
def __init__(self, master, label, underline=None, **kw):
|
||||||
if kw.has_key('name'):
|
if 'name' in kw:
|
||||||
name, label_underline = kw['name'], -1
|
name, label_underline = kw['name'], -1
|
||||||
else:
|
else:
|
||||||
name, label, label_underline = self.labeltoname(label)
|
name, label, label_underline = self.labeltoname(label)
|
||||||
|
@ -320,7 +320,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
|
|
||||||
# create a GTK-like path
|
# create a GTK-like path
|
||||||
def _addPath(self, path, menu, index, submenu):
|
def _addPath(self, path, menu, index, submenu):
|
||||||
if not self.__menupath.has_key(path):
|
if path not in self.__menupath:
|
||||||
##print path, menu, index, submenu
|
##print path, menu, index, submenu
|
||||||
self.__menupath[path] = (menu, index, submenu)
|
self.__menupath[path] = (menu, index, submenu)
|
||||||
|
|
||||||
|
@ -693,7 +693,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
games = {}
|
games = {}
|
||||||
for gi in mahjongg_games:
|
for gi in mahjongg_games:
|
||||||
c = gettext(gi.short_name).strip()[0]
|
c = gettext(gi.short_name).strip()[0]
|
||||||
if games.has_key(c):
|
if c in games:
|
||||||
games[c].append(gi)
|
games[c].append(gi)
|
||||||
else:
|
else:
|
||||||
games[c] = [gi]
|
games[c] = [gi]
|
||||||
|
@ -1168,7 +1168,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
manager=self.app.tabletile_manager,
|
manager=self.app.tabletile_manager,
|
||||||
key=key)
|
key=key)
|
||||||
if d.status == 0 and d.button == 0:
|
if d.status == 0 and d.button == 0:
|
||||||
if type(d.key) is str:
|
if isinstance(d.key, str):
|
||||||
tile = self.app.tabletile_manager.get(0)
|
tile = self.app.tabletile_manager.get(0)
|
||||||
tile.color = d.key
|
tile.color = d.key
|
||||||
if self.app.setTile(0):
|
if self.app.setTile(0):
|
||||||
|
|
|
@ -331,7 +331,7 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
##(_('Number of cards:'), str(cardset.ncards)),
|
##(_('Number of cards:'), str(cardset.ncards)),
|
||||||
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
||||||
):
|
):
|
||||||
if not t is None:
|
if t is not None:
|
||||||
l = Tkinter.Label(info_frame, text=n,
|
l = Tkinter.Label(info_frame, text=n,
|
||||||
anchor='w', justify='left')
|
anchor='w', justify='left')
|
||||||
l.grid(row=row, column=0, sticky='nw', padx=4)
|
l.grid(row=row, column=0, sticky='nw', padx=4)
|
||||||
|
|
|
@ -518,7 +518,7 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
||||||
category = gettext(CSI.TYPE[gi.category])
|
category = gettext(CSI.TYPE[gi.category])
|
||||||
type = ''
|
type = ''
|
||||||
if GI.TYPE_NAMES.has_key(gi.si.game_type):
|
if gi.si.game_type in GI.TYPE_NAMES:
|
||||||
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
||||||
sl = {
|
sl = {
|
||||||
GI.SL_LUCK: _('Luck only'),
|
GI.SL_LUCK: _('Luck only'),
|
||||||
|
|
|
@ -79,7 +79,7 @@ class SelectTileData(SelectDialogTreeData):
|
||||||
self.all_objects = filter(lambda obj: not obj.error, self.all_objects)
|
self.all_objects = filter(lambda obj: not obj.error, self.all_objects)
|
||||||
self.all_objects = filter(lambda tile: tile.index > 0 and tile.filename, self.all_objects)
|
self.all_objects = filter(lambda tile: tile.index > 0 and tile.filename, self.all_objects)
|
||||||
self.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ]
|
self.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ]
|
||||||
e1 = type(key) is types.StringType or len(self.all_objects) <=17
|
e1 = isinstance(key, str) or len(self.all_objects) <=17
|
||||||
e2 = 1
|
e2 = 1
|
||||||
self.rootnodes = (
|
self.rootnodes = (
|
||||||
SelectTileNode(None, _("Solid Colors"), (
|
SelectTileNode(None, _("Solid Colors"), (
|
||||||
|
@ -167,7 +167,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
|
|
||||||
def mDone(self, button):
|
def mDone(self, button):
|
||||||
if button == 0: # "OK" or double click
|
if button == 0: # "OK" or double click
|
||||||
if type(self.tree.selection_key) in types.StringTypes:
|
if isinstance(self.tree.selection_key, basestring):
|
||||||
self.key = str(self.tree.selection_key)
|
self.key = str(self.tree.selection_key)
|
||||||
else:
|
else:
|
||||||
self.key = self.tree.selection_key
|
self.key = self.tree.selection_key
|
||||||
|
@ -191,7 +191,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
return
|
return
|
||||||
canvas = self.preview.canvas
|
canvas = self.preview.canvas
|
||||||
canvas.deleteAllItems()
|
canvas.deleteAllItems()
|
||||||
if type(key) is str:
|
if isinstance(key, str):
|
||||||
# solid color
|
# solid color
|
||||||
canvas.config(bg=key)
|
canvas.config(bg=key)
|
||||||
canvas.setTile(None)
|
canvas.setTile(None)
|
||||||
|
|
|
@ -78,7 +78,7 @@ class SelectDialogTreeNode(MfxTreeNode):
|
||||||
if self.subnodes is not None:
|
if self.subnodes is not None:
|
||||||
return self.subnodes
|
return self.subnodes
|
||||||
##print self.whoami()
|
##print self.whoami()
|
||||||
if type(self.select_func) in (types.TupleType, types.ListType):
|
if isinstance(self.select_func, (tuple, list)):
|
||||||
return self.select_func
|
return self.select_func
|
||||||
return self._getContents()
|
return self._getContents()
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ class MfxStatusbar:
|
||||||
label["text"] = unicode(v)
|
label["text"] = unicode(v)
|
||||||
|
|
||||||
def configLabel(self, name, **kw):
|
def configLabel(self, name, **kw):
|
||||||
if kw.has_key('fg'):
|
if 'fg' in kw:
|
||||||
kw['foreground'] = kw['fg']
|
kw['foreground'] = kw['fg']
|
||||||
del kw['fg']
|
del kw['fg']
|
||||||
label = getattr(self, name + "_label")
|
label = getattr(self, name + "_label")
|
||||||
|
|
|
@ -67,7 +67,7 @@ class MfxCanvasGroup(Canvas.Group):
|
||||||
def __init__(self, canvas, tag=None):
|
def __init__(self, canvas, tag=None):
|
||||||
Canvas.Group.__init__(self, canvas=canvas, tag=tag)
|
Canvas.Group.__init__(self, canvas=canvas, tag=tag)
|
||||||
# register ourself so that we can unbind from the canvas
|
# register ourself so that we can unbind from the canvas
|
||||||
assert not self.canvas.items.has_key(self.id)
|
assert self.id not in self.canvas.items
|
||||||
self.canvas.items[self.id] = self
|
self.canvas.items[self.id] = self
|
||||||
def addtag(self, tag, option="withtag"):
|
def addtag(self, tag, option="withtag"):
|
||||||
self.canvas.addtag(tag, option, self.id)
|
self.canvas.addtag(tag, option, self.id)
|
||||||
|
@ -80,10 +80,10 @@ class MfxCanvasGroup(Canvas.Group):
|
||||||
class MfxCanvasImage(Canvas.ImageItem):
|
class MfxCanvasImage(Canvas.ImageItem):
|
||||||
def __init__(self, canvas, *args, **kwargs):
|
def __init__(self, canvas, *args, **kwargs):
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
if kwargs.has_key('image'):
|
if 'image' in kwargs:
|
||||||
self._image = kwargs['image']
|
self._image = kwargs['image']
|
||||||
Canvas.ImageItem.__init__(self, canvas, *args, **kwargs)
|
Canvas.ImageItem.__init__(self, canvas, *args, **kwargs)
|
||||||
if group:
|
if group:
|
||||||
|
@ -101,7 +101,7 @@ MfxCanvasLine = Canvas.Line
|
||||||
class MfxCanvasRectangle(Canvas.Rectangle):
|
class MfxCanvasRectangle(Canvas.Rectangle):
|
||||||
def __init__(self, canvas, *args, **kwargs):
|
def __init__(self, canvas, *args, **kwargs):
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
Canvas.Rectangle.__init__(self, canvas, *args, **kwargs)
|
Canvas.Rectangle.__init__(self, canvas, *args, **kwargs)
|
||||||
|
@ -114,10 +114,10 @@ class MfxCanvasText(Canvas.CanvasText):
|
||||||
preview = canvas.preview
|
preview = canvas.preview
|
||||||
if preview > 1:
|
if preview > 1:
|
||||||
return
|
return
|
||||||
if not kwargs.has_key("fill"):
|
if "fill" not in kwargs:
|
||||||
kwargs["fill"] = canvas._text_color
|
kwargs["fill"] = canvas._text_color
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
Canvas.CanvasText.__init__(self, canvas, x, y, **kwargs)
|
Canvas.CanvasText.__init__(self, canvas, x, y, **kwargs)
|
||||||
|
@ -252,7 +252,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
def deleteAllItems(self):
|
def deleteAllItems(self):
|
||||||
self._text_items = []
|
self._text_items = []
|
||||||
for id in self.items.keys():
|
for id in self.items.keys():
|
||||||
assert not id in self.__tiles # because the tile is created by id
|
assert id not in self.__tiles # because the tile is created by id
|
||||||
unbind_destroy(self.items[id])
|
unbind_destroy(self.items[id])
|
||||||
self.items[id].delete()
|
self.items[id].delete()
|
||||||
assert self.items == {}
|
assert self.items == {}
|
||||||
|
@ -286,7 +286,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
def setTextColor(self, color):
|
def setTextColor(self, color):
|
||||||
if color is None:
|
if color is None:
|
||||||
c = self.cget("bg")
|
c = self.cget("bg")
|
||||||
if type(c) is not types.StringType or c[0] != "#" or len(c) != 7:
|
if not isinstance(c, str) or c[0] != "#" or len(c) != 7:
|
||||||
return
|
return
|
||||||
v = []
|
v = []
|
||||||
for i in (1, 3, 5):
|
for i in (1, 3, 5):
|
||||||
|
@ -323,7 +323,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
|
|
||||||
def setTopImage(self, image, cw=0, ch=0):
|
def setTopImage(self, image, cw=0, ch=0):
|
||||||
try:
|
try:
|
||||||
if image and type(image) is types.StringType:
|
if image and isinstance(image, str):
|
||||||
image = loadImage(file=image)
|
image = loadImage(file=image)
|
||||||
except Tkinter.TclError:
|
except Tkinter.TclError:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -155,7 +155,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
if font:
|
if font:
|
||||||
##print "start_font(%s)" % `font`
|
##print "start_font(%s)" % `font`
|
||||||
self.font_mark = self.text.index("insert")
|
self.font_mark = self.text.index("insert")
|
||||||
if self.fontmap.has_key(font[0]):
|
if font[0] in self.fontmap:
|
||||||
self.font = font[0]
|
self.font = font[0]
|
||||||
elif font[3]:
|
elif font[3]:
|
||||||
self.font = "pre"
|
self.font = "pre"
|
||||||
|
@ -457,7 +457,7 @@ to open the following URL:
|
||||||
##self.frame.config(cursor=self.defcursor)
|
##self.frame.config(cursor=self.defcursor)
|
||||||
|
|
||||||
def addHistory(self, url, xview=0, yview=0):
|
def addHistory(self, url, xview=0, yview=0):
|
||||||
if not url in self.visited_urls:
|
if url not in self.visited_urls:
|
||||||
self.visited_urls.append(url)
|
self.visited_urls.append(url)
|
||||||
if self.history.index > 0:
|
if self.history.index > 0:
|
||||||
u, xv, yv = self.history.list[self.history.index-1]
|
u, xv, yv = self.history.list[self.history.index-1]
|
||||||
|
@ -501,7 +501,7 @@ to open the following URL:
|
||||||
strings=(_("&OK"),), default=0)
|
strings=(_("&OK"),), default=0)
|
||||||
|
|
||||||
def getImage(self, fn):
|
def getImage(self, fn):
|
||||||
if self.images.has_key(fn):
|
if fn in self.images:
|
||||||
return self.images[fn]
|
return self.images[fn]
|
||||||
try:
|
try:
|
||||||
img = Tkinter.PhotoImage(master=self.parent, file=fn)
|
img = Tkinter.PhotoImage(master=self.parent, file=fn)
|
||||||
|
|
|
@ -394,7 +394,7 @@ class AllGames_StatsDialog(MfxDialog):
|
||||||
def mDone(self, button):
|
def mDone(self, button):
|
||||||
sel = self.tree.selection()
|
sel = self.tree.selection()
|
||||||
if sel and len(sel) == 1:
|
if sel and len(sel) == 1:
|
||||||
if self.games.has_key(sel[0]):
|
if sel[0] in self.games:
|
||||||
self.selected_game = self.games[sel[0]]
|
self.selected_game = self.games[sel[0]]
|
||||||
MfxDialog.mDone(self, button)
|
MfxDialog.mDone(self, button)
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ class AllGames_StatsDialog(MfxDialog):
|
||||||
sel = self.tree.selection()
|
sel = self.tree.selection()
|
||||||
run_button = self.buttons[0]
|
run_button = self.buttons[0]
|
||||||
if sel and len(sel) == 1:
|
if sel and len(sel) == 1:
|
||||||
if not self.games.has_key(sel[0]): # "Total"
|
if sel[0] not in self.games: # "Total"
|
||||||
run_button.config(state='disabled')
|
run_button.config(state='disabled')
|
||||||
else:
|
else:
|
||||||
run_button.config(state='normal')
|
run_button.config(state='normal')
|
||||||
|
@ -607,8 +607,8 @@ class Top_StatsDialog(MfxDialog):
|
||||||
frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH, padx=5, pady=10)
|
frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH, padx=5, pady=10)
|
||||||
frame.columnconfigure(0, weight=1)
|
frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
if (app.stats.games_stats.has_key(player) and
|
if (player in app.stats.games_stats and
|
||||||
app.stats.games_stats[player].has_key(gameid) and
|
gameid in app.stats.games_stats[player] and
|
||||||
app.stats.games_stats[player][gameid].time_result.top):
|
app.stats.games_stats[player][gameid].time_result.top):
|
||||||
|
|
||||||
Tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1, padx=4)
|
Tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1, padx=4)
|
||||||
|
|
|
@ -34,13 +34,12 @@
|
||||||
##---------------------------------------------------------------------------##
|
##---------------------------------------------------------------------------##
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, string, types
|
import os
|
||||||
import Tile as Tkinter
|
import Tile as Tkinter
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkutil import bind
|
from tkutil import bind
|
||||||
from tkwidget import MfxScrolledCanvas
|
from tkwidget import MfxScrolledCanvas
|
||||||
from pysollib.settings import WIN_SYSTEM
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
|
@ -338,7 +337,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
|
||||||
l1 = self.keys.get(self.selection_key, [])
|
l1 = self.keys.get(self.selection_key, [])
|
||||||
l2 = self.keys.get(key, [])
|
l2 = self.keys.get(key, [])
|
||||||
for node in l1:
|
for node in l1:
|
||||||
if node.selected and not node in l2:
|
if node.selected and node not in l2:
|
||||||
node.selected = 0
|
node.selected = 0
|
||||||
node.updateSymbol()
|
node.updateSymbol()
|
||||||
node.updateText()
|
node.updateText()
|
||||||
|
@ -364,7 +363,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
|
||||||
class DirectoryBrowser(MfxTreeInCanvas):
|
class DirectoryBrowser(MfxTreeInCanvas):
|
||||||
def __init__(self, parent, dirs):
|
def __init__(self, parent, dirs):
|
||||||
nodes = []
|
nodes = []
|
||||||
if type(dirs) is types.StringType:
|
if isinstance(dirs, str):
|
||||||
dirs = (dirs,)
|
dirs = (dirs,)
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
self.addNode(nodes, None, dir, dir)
|
self.addNode(nodes, None, dir, dir)
|
||||||
|
|
|
@ -96,7 +96,7 @@ def wm_get_geometry(window):
|
||||||
g = window.wm_geometry()
|
g = window.wm_geometry()
|
||||||
m = __wm_get_geometry_re.search(g)
|
m = __wm_get_geometry_re.search(g)
|
||||||
if not m:
|
if not m:
|
||||||
raise Tkinter.TclError, "invalid geometry " + str(g)
|
raise Tkinter.TclError("invalid geometry "+str(g))
|
||||||
l = map(int, m.groups())
|
l = map(int, m.groups())
|
||||||
if window.wm_state() == "zoomed":
|
if window.wm_state() == "zoomed":
|
||||||
# workaround as Tk returns the "unzoomed" origin
|
# workaround as Tk returns the "unzoomed" origin
|
||||||
|
@ -215,7 +215,7 @@ def bind(widget, sequence, func, add=None):
|
||||||
##add = add and "+" or ""
|
##add = add and "+" or ""
|
||||||
funcid = widget.bind(sequence, func, add)
|
funcid = widget.bind(sequence, func, add)
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __mfx_bindings.has_key(k):
|
if k in __mfx_bindings:
|
||||||
__mfx_bindings[k].append((sequence, funcid))
|
__mfx_bindings[k].append((sequence, funcid))
|
||||||
else:
|
else:
|
||||||
__mfx_bindings[k] = [(sequence, funcid)]
|
__mfx_bindings[k] = [(sequence, funcid)]
|
||||||
|
@ -224,7 +224,7 @@ def unbind_destroy(widget):
|
||||||
if widget is None:
|
if widget is None:
|
||||||
return
|
return
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __mfx_bindings.has_key(k):
|
if k in __mfx_bindings:
|
||||||
for sequence, funcid in __mfx_bindings[k]:
|
for sequence, funcid in __mfx_bindings[k]:
|
||||||
##print widget, sequence, funcid
|
##print widget, sequence, funcid
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -67,6 +67,7 @@ from tkcanvas import MfxCanvas
|
||||||
class MfxDialog: # ex. _ToplevelDialog
|
class MfxDialog: # ex. _ToplevelDialog
|
||||||
img = {}
|
img = {}
|
||||||
button_img = {}
|
button_img = {}
|
||||||
|
|
||||||
def __init__(self, parent, title="", resizable=0, default=-1):
|
def __init__(self, parent, title="", resizable=0, default=-1):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.status = 0
|
self.status = 0
|
||||||
|
@ -82,7 +83,6 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
##w, h = self.top.winfo_screenwidth(), self.top.winfo_screenheight()
|
##w, h = self.top.winfo_screenwidth(), self.top.winfo_screenheight()
|
||||||
##self.top.wm_maxsize(w-4, h-32)
|
##self.top.wm_maxsize(w-4, h-32)
|
||||||
bind(self.top, "WM_DELETE_WINDOW", self.wmDeleteWindow)
|
bind(self.top, "WM_DELETE_WINDOW", self.wmDeleteWindow)
|
||||||
#
|
|
||||||
|
|
||||||
def mainloop(self, focus=None, timeout=0, transient=True):
|
def mainloop(self, focus=None, timeout=0, transient=True):
|
||||||
bind(self.top, "<Escape>", self.mCancel)
|
bind(self.top, "<Escape>", self.mCancel)
|
||||||
|
@ -130,7 +130,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
|
|
||||||
def altKeyEvent(self, event):
|
def altKeyEvent(self, event):
|
||||||
widget = None
|
widget = None
|
||||||
if self.accel_keys.has_key(event.keysym):
|
if event.keysym in self.accel_keys:
|
||||||
widget = self.accel_keys[event.keysym]
|
widget = self.accel_keys[event.keysym]
|
||||||
else:
|
else:
|
||||||
key = event.char
|
key = event.char
|
||||||
|
@ -144,7 +144,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
else:
|
else:
|
||||||
key = key.lower()
|
key = key.lower()
|
||||||
widget = self.accel_keys.get(key)
|
widget = self.accel_keys.get(key)
|
||||||
if not widget is None:
|
if widget is not None:
|
||||||
widget.event_generate('<<Invoke>>')
|
widget.event_generate('<<Invoke>>')
|
||||||
|
|
||||||
def initKw(self, kw):
|
def initKw(self, kw):
|
||||||
|
@ -179,7 +179,8 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
if kw.bitmap: ## in ("error", "info", "question", "warning")
|
if kw.bitmap: ## in ("error", "info", "question", "warning")
|
||||||
img = self.img.get(kw.bitmap)
|
img = self.img.get(kw.bitmap)
|
||||||
b = Tkinter.Label(frame, image=img)
|
b = Tkinter.Label(frame, image=img)
|
||||||
b.pack(side=kw.bitmap_side, padx=kw.bitmap_padx, pady=kw.bitmap_pady)
|
b.pack(side=kw.bitmap_side,
|
||||||
|
padx=kw.bitmap_padx, pady=kw.bitmap_pady)
|
||||||
elif kw.image:
|
elif kw.image:
|
||||||
b = Tkinter.Label(frame, image=kw.image)
|
b = Tkinter.Label(frame, image=kw.image)
|
||||||
b.pack(side=kw.image_side, padx=kw.image_padx, pady=kw.image_pady)
|
b.pack(side=kw.image_side, padx=kw.image_padx, pady=kw.image_pady)
|
||||||
|
@ -196,7 +197,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
sep_column = 0
|
sep_column = 0
|
||||||
strings = kw.strings
|
strings = kw.strings
|
||||||
for s in strings:
|
for s in strings:
|
||||||
if type(s) is tuple:
|
if isinstance(s, tuple):
|
||||||
s = s[0]
|
s = s[0]
|
||||||
if s:
|
if s:
|
||||||
s = s.replace('&', '')
|
s = s.replace('&', '')
|
||||||
|
@ -214,7 +215,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
if s == 'sep':
|
if s == 'sep':
|
||||||
column += 1
|
column += 1
|
||||||
continue
|
continue
|
||||||
if type(s) is tuple:
|
if isinstance(s, tuple):
|
||||||
assert len(s) == 2
|
assert len(s) == 2
|
||||||
button = int(s[1])
|
button = int(s[1])
|
||||||
s = s[0]
|
s = s[0]
|
||||||
|
@ -230,7 +231,8 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
widget = Tkinter.Button(frame, text=s, state="disabled")
|
widget = Tkinter.Button(frame, text=s, state="disabled")
|
||||||
else:
|
else:
|
||||||
widget = Tkinter.Button(frame, text=s, default="normal",
|
widget = Tkinter.Button(frame, text=s, default="normal",
|
||||||
command=(lambda self=self, button=button: self.mDone(button)))
|
command = lambda self=self, button=button: \
|
||||||
|
self.mDone(button))
|
||||||
if button == kw.default:
|
if button == kw.default:
|
||||||
focus = widget
|
focus = widget
|
||||||
focus.config(default="active")
|
focus.config(default="active")
|
||||||
|
@ -720,25 +722,25 @@ class StackDesc:
|
||||||
|
|
||||||
class MyPysolScale:
|
class MyPysolScale:
|
||||||
def __init__(self, parent, **kw):
|
def __init__(self, parent, **kw):
|
||||||
if kw.has_key('resolution'):
|
if 'resolution' in kw:
|
||||||
self.resolution = kw['resolution']
|
self.resolution = kw['resolution']
|
||||||
del kw['resolution']
|
del kw['resolution']
|
||||||
else:
|
else:
|
||||||
self.resolution = 1
|
self.resolution = 1
|
||||||
if kw.has_key('from_'):
|
if 'from_' in kw:
|
||||||
kw['from_'] = kw['from_']/self.resolution
|
kw['from_'] = kw['from_']/self.resolution
|
||||||
if kw.has_key('to'):
|
if 'to' in kw:
|
||||||
kw['to'] = kw['to']/self.resolution
|
kw['to'] = kw['to']/self.resolution
|
||||||
if kw.has_key('command'):
|
if 'command' in kw:
|
||||||
self.command = kw['command']
|
self.command = kw['command']
|
||||||
else:
|
else:
|
||||||
self.command = None
|
self.command = None
|
||||||
if kw.has_key('variable'):
|
if 'variable' in kw:
|
||||||
self.variable = kw['variable']
|
self.variable = kw['variable']
|
||||||
del kw['variable']
|
del kw['variable']
|
||||||
else:
|
else:
|
||||||
self.variable = None
|
self.variable = None
|
||||||
if kw.has_key('value'):
|
if 'value' in kw:
|
||||||
value = kw['value']
|
value = kw['value']
|
||||||
del kw['value']
|
del kw['value']
|
||||||
if self.variable:
|
if self.variable:
|
||||||
|
@ -750,7 +752,7 @@ class MyPysolScale:
|
||||||
if self.variable:
|
if self.variable:
|
||||||
self.variable.trace('w', self._trace_var)
|
self.variable.trace('w', self._trace_var)
|
||||||
kw['command'] = self._scale_command
|
kw['command'] = self._scale_command
|
||||||
if kw.has_key('label'):
|
if 'label' in kw:
|
||||||
self.label_text = kw['label']
|
self.label_text = kw['label']
|
||||||
del kw['label']
|
del kw['label']
|
||||||
else:
|
else:
|
||||||
|
@ -764,7 +766,7 @@ class MyPysolScale:
|
||||||
self.scale = Tkinter.Scale(self.frame, **kw)
|
self.scale = Tkinter.Scale(self.frame, **kw)
|
||||||
self.scale.pack(side=side, expand=True, fill='both', pady=4)
|
self.scale.pack(side=side, expand=True, fill='both', pady=4)
|
||||||
|
|
||||||
if not value is None:
|
if value is not None:
|
||||||
if self.variable:
|
if self.variable:
|
||||||
self.variable.set(self._round(value))
|
self.variable.set(self._round(value))
|
||||||
self._set_text(self._round(value))
|
self._set_text(self._round(value))
|
||||||
|
@ -801,7 +803,7 @@ class MyPysolScale:
|
||||||
|
|
||||||
class TkinterScale(Tk.Scale):
|
class TkinterScale(Tk.Scale):
|
||||||
def __init__(self, parent, **kw):
|
def __init__(self, parent, **kw):
|
||||||
if kw.has_key('value'):
|
if 'value' in kw:
|
||||||
del kw['value']
|
del kw['value']
|
||||||
Tk.Scale.__init__(self, parent, **kw)
|
Tk.Scale.__init__(self, parent, **kw)
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ class MfxCheckMenuItem(Tkinter.BooleanVar):
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
if not value or value == "false": value = 0
|
if not value or value == "false": value = 0
|
||||||
##print value, type(value)
|
##print value, type(value)
|
||||||
##assert type(value) is types.IntType and 0 <= value <= 1
|
|
||||||
Tkinter.BooleanVar.set(self, value)
|
Tkinter.BooleanVar.set(self, value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +69,6 @@ class MfxRadioMenuItem(Tkinter.IntVar):
|
||||||
def __init__(self, menubar, path=None):
|
def __init__(self, menubar, path=None):
|
||||||
Tkinter.IntVar.__init__(self)
|
Tkinter.IntVar.__init__(self)
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
##assert type(value) is types.IntType and 0 <= value
|
|
||||||
Tkinter.IntVar.set(self, value)
|
Tkinter.IntVar.set(self, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
__all__ = ['PysolToolbar'] #, 'TOOLBAR_BUTTONS']
|
__all__ = ['PysolToolbar'] #, 'TOOLBAR_BUTTONS']
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, sys, types
|
import os
|
||||||
import traceback
|
|
||||||
import Tkinter as Tk
|
|
||||||
import Tile as Tkinter
|
import Tile as Tkinter
|
||||||
try:
|
try:
|
||||||
# PIL
|
# PIL
|
||||||
|
|
|
@ -41,7 +41,7 @@ __all__ = ['Card']
|
||||||
from pysollib.acard import AbstractCard
|
from pysollib.acard import AbstractCard
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkconst import tkversion, TK_DASH_PATCH
|
from tkconst import TK_DASH_PATCH
|
||||||
from tkcanvas import MfxCanvasGroup, MfxCanvasImage
|
from tkcanvas import MfxCanvasGroup, MfxCanvasImage
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ class FontChooserDialog(MfxDialog):
|
||||||
self.font_weight = 'normal'
|
self.font_weight = 'normal'
|
||||||
self.font_slant = 'roman'
|
self.font_slant = 'roman'
|
||||||
|
|
||||||
if not init_font is None:
|
if init_font is not None:
|
||||||
assert 2 <= len(init_font) <= 4
|
assert 2 <= len(init_font) <= 4
|
||||||
assert type(init_font[1]) is types.IntType
|
assert isinstance(init_font[1], int)
|
||||||
self.font_family, self.font_size = init_font[:2]
|
self.font_family, self.font_size = init_font[:2]
|
||||||
if len(init_font) > 2:
|
if len(init_font) > 2:
|
||||||
if init_font[2] in ['bold', 'normal']:
|
if init_font[2] in ['bold', 'normal']:
|
||||||
|
@ -62,14 +62,14 @@ class FontChooserDialog(MfxDialog):
|
||||||
elif init_font[2] in ['italic', 'roman']:
|
elif init_font[2] in ['italic', 'roman']:
|
||||||
self.font_slant = init_font[2]
|
self.font_slant = init_font[2]
|
||||||
else:
|
else:
|
||||||
raise TypeError, 'invalid font style: '+ init_font[2]
|
raise ValueError('invalid font style: '+init_font[2])
|
||||||
if len(init_font) > 3:
|
if len(init_font) > 3:
|
||||||
if init_font[3] in ['bold', 'normal']:
|
if init_font[3] in ['bold', 'normal']:
|
||||||
self.font_weight = init_font[3]
|
self.font_weight = init_font[3]
|
||||||
elif init_font[2] in ['italic', 'roman']:
|
elif init_font[2] in ['italic', 'roman']:
|
||||||
self.font_slant = init_font[3]
|
self.font_slant = init_font[3]
|
||||||
else:
|
else:
|
||||||
raise TypeError, 'invalid font style: '+ init_font[3]
|
raise ValueError('invalid font style: '+init_font[3])
|
||||||
|
|
||||||
#self.family_var = Tkinter.StringVar()
|
#self.family_var = Tkinter.StringVar()
|
||||||
self.weight_var = Tkinter.BooleanVar()
|
self.weight_var = Tkinter.BooleanVar()
|
||||||
|
@ -178,7 +178,7 @@ class FontsDialog(MfxDialog):
|
||||||
Tkinter.Label(frame, text=title, anchor='w'
|
Tkinter.Label(frame, text=title, anchor='w'
|
||||||
).grid(row=row, column=0, sticky='we')
|
).grid(row=row, column=0, sticky='we')
|
||||||
if font:
|
if font:
|
||||||
title = ' '.join([str(i) for i in font if not i in ('roman', 'normal')])
|
title = ' '.join([str(i) for i in font if i not in ('roman', 'normal')])
|
||||||
elif font is None:
|
elif font is None:
|
||||||
title = 'Default'
|
title = 'Default'
|
||||||
l = Tkinter.Label(frame, font=font, text=title)
|
l = Tkinter.Label(frame, font=font, text=title)
|
||||||
|
@ -196,7 +196,7 @@ class FontsDialog(MfxDialog):
|
||||||
d = FontChooserDialog(self.top, _('Select font'), self.fonts[fn])
|
d = FontChooserDialog(self.top, _('Select font'), self.fonts[fn])
|
||||||
if d.status == 0 and d.button == 0:
|
if d.status == 0 and d.button == 0:
|
||||||
self.fonts[fn] = d.font
|
self.fonts[fn] = d.font
|
||||||
title = ' '.join([str(i) for i in d.font if not i in ('roman', 'normal')])
|
title = ' '.join([str(i) for i in d.font if i not in ('roman', 'normal')])
|
||||||
label.configure(font=d.font, text=title)
|
label.configure(font=d.font, text=title)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ class GameInfoDialog(MfxDialog):
|
||||||
fs = {}
|
fs = {}
|
||||||
for f in stacks:
|
for f in stacks:
|
||||||
cn = f.__class__.__name__
|
cn = f.__class__.__name__
|
||||||
if fs.has_key(cn):
|
if cn in fs:
|
||||||
fs[cn] += 1
|
fs[cn] += 1
|
||||||
else:
|
else:
|
||||||
fs[cn] = 1
|
fs[cn] = 1
|
||||||
|
|
|
@ -167,7 +167,7 @@ class MfxMenubar(Tkinter.Menu):
|
||||||
|
|
||||||
class MfxMenu(MfxMenubar):
|
class MfxMenu(MfxMenubar):
|
||||||
def __init__(self, master, label, underline=None, **kw):
|
def __init__(self, master, label, underline=None, **kw):
|
||||||
if kw.has_key('name'):
|
if 'name' in kw:
|
||||||
name, label_underline = kw['name'], -1
|
name, label_underline = kw['name'], -1
|
||||||
else:
|
else:
|
||||||
name, label, label_underline = self.labeltoname(label)
|
name, label, label_underline = self.labeltoname(label)
|
||||||
|
@ -317,7 +317,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
|
|
||||||
# create a GTK-like path
|
# create a GTK-like path
|
||||||
def _addPath(self, path, menu, index, submenu):
|
def _addPath(self, path, menu, index, submenu):
|
||||||
if not self.__menupath.has_key(path):
|
if path not in self.__menupath:
|
||||||
##print path, menu, index, submenu
|
##print path, menu, index, submenu
|
||||||
self.__menupath[path] = (menu, index, submenu)
|
self.__menupath[path] = (menu, index, submenu)
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
games = {}
|
games = {}
|
||||||
for gi in mahjongg_games:
|
for gi in mahjongg_games:
|
||||||
c = gettext(gi.short_name).strip()[0]
|
c = gettext(gi.short_name).strip()[0]
|
||||||
if games.has_key(c):
|
if c in games:
|
||||||
games[c].append(gi)
|
games[c].append(gi)
|
||||||
else:
|
else:
|
||||||
games[c] = [gi]
|
games[c] = [gi]
|
||||||
|
@ -1173,7 +1173,7 @@ class PysolMenubar(PysolMenubarActions):
|
||||||
manager=self.app.tabletile_manager,
|
manager=self.app.tabletile_manager,
|
||||||
key=key)
|
key=key)
|
||||||
if d.status == 0 and d.button == 0:
|
if d.status == 0 and d.button == 0:
|
||||||
if type(d.key) is str:
|
if isinstance(d.key, str):
|
||||||
tile = self.app.tabletile_manager.get(0)
|
tile = self.app.tabletile_manager.get(0)
|
||||||
tile.color = d.key
|
tile.color = d.key
|
||||||
if self.app.setTile(0):
|
if self.app.setTile(0):
|
||||||
|
|
|
@ -340,7 +340,7 @@ class CardsetInfoDialog(MfxDialog):
|
||||||
##(_('Number of cards:'), str(cardset.ncards)),
|
##(_('Number of cards:'), str(cardset.ncards)),
|
||||||
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
(_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
|
||||||
):
|
):
|
||||||
if not t is None:
|
if t is not None:
|
||||||
l = Tkinter.Label(info_frame, text=n,
|
l = Tkinter.Label(info_frame, text=n,
|
||||||
anchor='w', justify='left')
|
anchor='w', justify='left')
|
||||||
l.grid(row=row, column=0, sticky='nw')
|
l.grid(row=row, column=0, sticky='nw')
|
||||||
|
|
|
@ -527,7 +527,7 @@ class SelectGameDialogWithPreview(SelectGameDialog):
|
||||||
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
altnames = '\n'.join([gettext(n) for n in gi.altnames])
|
||||||
category = gettext(CSI.TYPE[gi.category])
|
category = gettext(CSI.TYPE[gi.category])
|
||||||
type = ''
|
type = ''
|
||||||
if GI.TYPE_NAMES.has_key(gi.si.game_type):
|
if gi.si.game_type in GI.TYPE_NAMES:
|
||||||
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
type = gettext(GI.TYPE_NAMES[gi.si.game_type])
|
||||||
sl = {
|
sl = {
|
||||||
GI.SL_LUCK: _('Luck only'),
|
GI.SL_LUCK: _('Luck only'),
|
||||||
|
|
|
@ -78,7 +78,7 @@ class SelectTileData(SelectDialogTreeData):
|
||||||
self.all_objects = filter(lambda obj: not obj.error, self.all_objects)
|
self.all_objects = filter(lambda obj: not obj.error, self.all_objects)
|
||||||
self.all_objects = filter(lambda tile: tile.index > 0 and tile.filename, self.all_objects)
|
self.all_objects = filter(lambda tile: tile.index > 0 and tile.filename, self.all_objects)
|
||||||
self.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ]
|
self.no_contents = [ SelectTileLeaf(None, None, _("(no tiles)"), key=None), ]
|
||||||
e1 = type(key) is types.StringType or len(self.all_objects) <=17
|
e1 = isinstance(key, str) or len(self.all_objects) <=17
|
||||||
e2 = 1
|
e2 = 1
|
||||||
self.rootnodes = (
|
self.rootnodes = (
|
||||||
SelectTileNode(None, _("Solid Colors"), (
|
SelectTileNode(None, _("Solid Colors"), (
|
||||||
|
@ -167,7 +167,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
|
|
||||||
def mDone(self, button):
|
def mDone(self, button):
|
||||||
if button == 0: # "OK" or double click
|
if button == 0: # "OK" or double click
|
||||||
if type(self.tree.selection_key) in types.StringTypes:
|
if isinstance(self.tree.selection_key, basestring):
|
||||||
self.key = str(self.tree.selection_key)
|
self.key = str(self.tree.selection_key)
|
||||||
else:
|
else:
|
||||||
self.key = self.tree.selection_key
|
self.key = self.tree.selection_key
|
||||||
|
@ -191,7 +191,7 @@ class SelectTileDialogWithPreview(MfxDialog):
|
||||||
return
|
return
|
||||||
canvas = self.preview.canvas
|
canvas = self.preview.canvas
|
||||||
canvas.deleteAllItems()
|
canvas.deleteAllItems()
|
||||||
if type(key) is str:
|
if isinstance(key, str):
|
||||||
# solid color
|
# solid color
|
||||||
canvas.config(bg=key)
|
canvas.config(bg=key)
|
||||||
canvas.setTile(None)
|
canvas.setTile(None)
|
||||||
|
|
|
@ -77,7 +77,7 @@ class SelectDialogTreeNode(MfxTreeNode):
|
||||||
if self.subnodes is not None:
|
if self.subnodes is not None:
|
||||||
return self.subnodes
|
return self.subnodes
|
||||||
##print self.whoami()
|
##print self.whoami()
|
||||||
if type(self.select_func) in (types.TupleType, types.ListType):
|
if isinstance(self.select_func, (tuple, list)):
|
||||||
return self.select_func
|
return self.select_func
|
||||||
return self._getContents()
|
return self._getContents()
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class MfxCanvasGroup(Canvas.Group):
|
||||||
def __init__(self, canvas, tag=None):
|
def __init__(self, canvas, tag=None):
|
||||||
Canvas.Group.__init__(self, canvas=canvas, tag=tag)
|
Canvas.Group.__init__(self, canvas=canvas, tag=tag)
|
||||||
# register ourself so that we can unbind from the canvas
|
# register ourself so that we can unbind from the canvas
|
||||||
assert not self.canvas.items.has_key(self.id)
|
assert self.id not in self.canvas.items
|
||||||
self.canvas.items[self.id] = self
|
self.canvas.items[self.id] = self
|
||||||
def addtag(self, tag, option="withtag"):
|
def addtag(self, tag, option="withtag"):
|
||||||
self.canvas.addtag(tag, option, self.id)
|
self.canvas.addtag(tag, option, self.id)
|
||||||
|
@ -79,10 +79,10 @@ class MfxCanvasGroup(Canvas.Group):
|
||||||
class MfxCanvasImage(Canvas.ImageItem):
|
class MfxCanvasImage(Canvas.ImageItem):
|
||||||
def __init__(self, canvas, *args, **kwargs):
|
def __init__(self, canvas, *args, **kwargs):
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
if kwargs.has_key('image'):
|
if 'image' in kwargs:
|
||||||
self._image = kwargs['image']
|
self._image = kwargs['image']
|
||||||
Canvas.ImageItem.__init__(self, canvas, *args, **kwargs)
|
Canvas.ImageItem.__init__(self, canvas, *args, **kwargs)
|
||||||
if group:
|
if group:
|
||||||
|
@ -100,7 +100,7 @@ MfxCanvasLine = Canvas.Line
|
||||||
class MfxCanvasRectangle(Canvas.Rectangle):
|
class MfxCanvasRectangle(Canvas.Rectangle):
|
||||||
def __init__(self, canvas, *args, **kwargs):
|
def __init__(self, canvas, *args, **kwargs):
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
Canvas.Rectangle.__init__(self, canvas, *args, **kwargs)
|
Canvas.Rectangle.__init__(self, canvas, *args, **kwargs)
|
||||||
|
@ -113,10 +113,10 @@ class MfxCanvasText(Canvas.CanvasText):
|
||||||
preview = canvas.preview
|
preview = canvas.preview
|
||||||
if preview > 1:
|
if preview > 1:
|
||||||
return
|
return
|
||||||
if not kwargs.has_key("fill"):
|
if "fill" not in kwargs:
|
||||||
kwargs["fill"] = canvas._text_color
|
kwargs["fill"] = canvas._text_color
|
||||||
group = None
|
group = None
|
||||||
if kwargs.has_key('group'):
|
if 'group' in kwargs:
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
Canvas.CanvasText.__init__(self, canvas, x, y, **kwargs)
|
Canvas.CanvasText.__init__(self, canvas, x, y, **kwargs)
|
||||||
|
@ -251,7 +251,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
def deleteAllItems(self):
|
def deleteAllItems(self):
|
||||||
self._text_items = []
|
self._text_items = []
|
||||||
for id in self.items.keys():
|
for id in self.items.keys():
|
||||||
assert not id in self.__tiles # because the tile is created by id
|
assert id not in self.__tiles # because the tile is created by id
|
||||||
unbind_destroy(self.items[id])
|
unbind_destroy(self.items[id])
|
||||||
self.items[id].delete()
|
self.items[id].delete()
|
||||||
assert self.items == {}
|
assert self.items == {}
|
||||||
|
@ -285,7 +285,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
def setTextColor(self, color):
|
def setTextColor(self, color):
|
||||||
if color is None:
|
if color is None:
|
||||||
c = self.cget("bg")
|
c = self.cget("bg")
|
||||||
if type(c) is not types.StringType or c[0] != "#" or len(c) != 7:
|
if not isinstance(c, str) or c[0] != "#" or len(c) != 7:
|
||||||
return
|
return
|
||||||
v = []
|
v = []
|
||||||
for i in (1, 3, 5):
|
for i in (1, 3, 5):
|
||||||
|
@ -322,7 +322,7 @@ class MfxCanvas(Tkinter.Canvas):
|
||||||
|
|
||||||
def setTopImage(self, image, cw=0, ch=0):
|
def setTopImage(self, image, cw=0, ch=0):
|
||||||
try:
|
try:
|
||||||
if image and type(image) is types.StringType:
|
if image and isinstance(image, str):
|
||||||
image = loadImage(file=image)
|
image = loadImage(file=image)
|
||||||
except Tkinter.TclError:
|
except Tkinter.TclError:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -155,7 +155,7 @@ class tkHTMLWriter(formatter.NullWriter):
|
||||||
if font:
|
if font:
|
||||||
##print "start_font(%s)" % `font`
|
##print "start_font(%s)" % `font`
|
||||||
self.font_mark = self.text.index("insert")
|
self.font_mark = self.text.index("insert")
|
||||||
if self.fontmap.has_key(font[0]):
|
if font[0] in self.fontmap:
|
||||||
self.font = font[0]
|
self.font = font[0]
|
||||||
elif font[3]:
|
elif font[3]:
|
||||||
self.font = "pre"
|
self.font = "pre"
|
||||||
|
@ -456,7 +456,7 @@ to open the following URL:
|
||||||
##self.frame.config(cursor=self.defcursor)
|
##self.frame.config(cursor=self.defcursor)
|
||||||
|
|
||||||
def addHistory(self, url, xview=0, yview=0):
|
def addHistory(self, url, xview=0, yview=0):
|
||||||
if not url in self.visited_urls:
|
if url not in self.visited_urls:
|
||||||
self.visited_urls.append(url)
|
self.visited_urls.append(url)
|
||||||
if self.history.index > 0:
|
if self.history.index > 0:
|
||||||
u, xv, yv = self.history.list[self.history.index-1]
|
u, xv, yv = self.history.list[self.history.index-1]
|
||||||
|
@ -500,7 +500,7 @@ to open the following URL:
|
||||||
strings=(_("&OK"),), default=0)
|
strings=(_("&OK"),), default=0)
|
||||||
|
|
||||||
def getImage(self, fn):
|
def getImage(self, fn):
|
||||||
if self.images.has_key(fn):
|
if fn in self.images:
|
||||||
return self.images[fn]
|
return self.images[fn]
|
||||||
try:
|
try:
|
||||||
img = Tkinter.PhotoImage(master=self.parent, file=fn)
|
img = Tkinter.PhotoImage(master=self.parent, file=fn)
|
||||||
|
|
|
@ -723,8 +723,8 @@ class Top_StatsDialog(MfxDialog):
|
||||||
frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH, padx=5, pady=10)
|
frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH, padx=5, pady=10)
|
||||||
frame.columnconfigure(0, weight=1)
|
frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
if (app.stats.games_stats.has_key(player) and
|
if (player in app.stats.games_stats and
|
||||||
app.stats.games_stats[player].has_key(gameid) and
|
gameid in app.stats.games_stats[player] and
|
||||||
app.stats.games_stats[player][gameid].time_result.top):
|
app.stats.games_stats[player][gameid].time_result.top):
|
||||||
|
|
||||||
Tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1)
|
Tkinter.Label(frame, text=_('Minimum')).grid(row=0, column=1)
|
||||||
|
|
|
@ -34,13 +34,12 @@
|
||||||
##---------------------------------------------------------------------------##
|
##---------------------------------------------------------------------------##
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import os, string, types
|
import os
|
||||||
import Tkinter
|
import Tkinter
|
||||||
|
|
||||||
# Toolkit imports
|
# Toolkit imports
|
||||||
from tkutil import bind
|
from tkutil import bind
|
||||||
from tkwidget import MfxScrolledCanvas
|
from tkwidget import MfxScrolledCanvas
|
||||||
from pysollib.settings import WIN_SYSTEM
|
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
|
@ -239,9 +238,6 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
|
||||||
self.font = None
|
self.font = None
|
||||||
self.linestyle = "gray50"
|
self.linestyle = "gray50"
|
||||||
self.linecolor = "black"
|
self.linecolor = "black"
|
||||||
if WIN_SYSTEM == "win32":
|
|
||||||
self.linestyle = "" # Tk bug ?
|
|
||||||
self.linecolor = "gray50"
|
|
||||||
|
|
||||||
def __init__(self, parent, rootnodes, **kw):
|
def __init__(self, parent, rootnodes, **kw):
|
||||||
bg = kw["bg"] = kw.get("bg") or parent.cget("bg")
|
bg = kw["bg"] = kw.get("bg") or parent.cget("bg")
|
||||||
|
@ -339,7 +335,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
|
||||||
l1 = self.keys.get(self.selection_key, [])
|
l1 = self.keys.get(self.selection_key, [])
|
||||||
l2 = self.keys.get(key, [])
|
l2 = self.keys.get(key, [])
|
||||||
for node in l1:
|
for node in l1:
|
||||||
if node.selected and not node in l2:
|
if node.selected and node not in l2:
|
||||||
node.selected = 0
|
node.selected = 0
|
||||||
node.updateSymbol()
|
node.updateSymbol()
|
||||||
node.updateText()
|
node.updateText()
|
||||||
|
@ -365,7 +361,7 @@ class MfxTreeInCanvas(MfxScrolledCanvas):
|
||||||
class DirectoryBrowser(MfxTreeInCanvas):
|
class DirectoryBrowser(MfxTreeInCanvas):
|
||||||
def __init__(self, parent, dirs):
|
def __init__(self, parent, dirs):
|
||||||
nodes = []
|
nodes = []
|
||||||
if type(dirs) is types.StringType:
|
if isinstance(dirs, str):
|
||||||
dirs = (dirs,)
|
dirs = (dirs,)
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
self.addNode(nodes, None, dir, dir)
|
self.addNode(nodes, None, dir, dir)
|
||||||
|
|
|
@ -96,7 +96,7 @@ def wm_get_geometry(window):
|
||||||
g = window.wm_geometry()
|
g = window.wm_geometry()
|
||||||
m = __wm_get_geometry_re.search(g)
|
m = __wm_get_geometry_re.search(g)
|
||||||
if not m:
|
if not m:
|
||||||
raise Tkinter.TclError, "invalid geometry " + str(g)
|
raise Tkinter.TclError("invalid geometry "+str(g))
|
||||||
l = map(int, m.groups())
|
l = map(int, m.groups())
|
||||||
if window.wm_state() == "zoomed":
|
if window.wm_state() == "zoomed":
|
||||||
# workaround as Tk returns the "unzoomed" origin
|
# workaround as Tk returns the "unzoomed" origin
|
||||||
|
@ -215,7 +215,7 @@ def bind(widget, sequence, func, add=None):
|
||||||
##add = add and "+" or ""
|
##add = add and "+" or ""
|
||||||
funcid = widget.bind(sequence, func, add)
|
funcid = widget.bind(sequence, func, add)
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __mfx_bindings.has_key(k):
|
if k in __mfx_bindings:
|
||||||
__mfx_bindings[k].append((sequence, funcid))
|
__mfx_bindings[k].append((sequence, funcid))
|
||||||
else:
|
else:
|
||||||
__mfx_bindings[k] = [(sequence, funcid)]
|
__mfx_bindings[k] = [(sequence, funcid)]
|
||||||
|
@ -224,7 +224,7 @@ def unbind_destroy(widget):
|
||||||
if widget is None:
|
if widget is None:
|
||||||
return
|
return
|
||||||
k = id(widget)
|
k = id(widget)
|
||||||
if __mfx_bindings.has_key(k):
|
if k in __mfx_bindings:
|
||||||
for sequence, funcid in __mfx_bindings[k]:
|
for sequence, funcid in __mfx_bindings[k]:
|
||||||
##print widget, sequence, funcid
|
##print widget, sequence, funcid
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -149,7 +149,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
key = unicode(key, 'utf-8')
|
key = unicode(key, 'utf-8')
|
||||||
key = key.lower()
|
key = key.lower()
|
||||||
button = self.accel_keys.get(key)
|
button = self.accel_keys.get(key)
|
||||||
if not button is None:
|
if button is not None:
|
||||||
self.mDone(button)
|
self.mDone(button)
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,10 +198,9 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
focus = None
|
focus = None
|
||||||
max_len = 0
|
max_len = 0
|
||||||
for s in kw.strings:
|
for s in kw.strings:
|
||||||
if type(s) is types.TupleType:
|
if isinstance(s, tuple):
|
||||||
s = s[0]
|
s = s[0]
|
||||||
if s:
|
if s:
|
||||||
##s = re.sub(r"[\s\.\,]", "", s)
|
|
||||||
#if os.name == 'posix':
|
#if os.name == 'posix':
|
||||||
# s = s.replace('...', '.')
|
# s = s.replace('...', '.')
|
||||||
s = s.replace('&', '')
|
s = s.replace('&', '')
|
||||||
|
@ -216,7 +215,7 @@ class MfxDialog: # ex. _ToplevelDialog
|
||||||
#
|
#
|
||||||
for s in kw.strings:
|
for s in kw.strings:
|
||||||
xbutton = button = button + 1
|
xbutton = button = button + 1
|
||||||
if type(s) is types.TupleType:
|
if isinstance(s, tuple):
|
||||||
assert len(s) == 2
|
assert len(s) == 2
|
||||||
button = int(s[1])
|
button = int(s[1])
|
||||||
s = s[0]
|
s = s[0]
|
||||||
|
|
|
@ -63,7 +63,6 @@ class MfxCheckMenuItem(Tkinter.BooleanVar):
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
if not value or value == "false": value = 0
|
if not value or value == "false": value = 0
|
||||||
##print value, type(value)
|
##print value, type(value)
|
||||||
##assert type(value) is types.IntType and 0 <= value <= 1
|
|
||||||
Tkinter.BooleanVar.set(self, value)
|
Tkinter.BooleanVar.set(self, value)
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +70,6 @@ class MfxRadioMenuItem(Tkinter.IntVar):
|
||||||
def __init__(self, menubar, path=None):
|
def __init__(self, menubar, path=None):
|
||||||
Tkinter.IntVar.__init__(self)
|
Tkinter.IntVar.__init__(self)
|
||||||
def set(self, value):
|
def set(self, value):
|
||||||
##assert type(value) is types.IntType and 0 <= value
|
|
||||||
Tkinter.IntVar.set(self, value)
|
Tkinter.IntVar.set(self, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,10 @@ __all__ = ['SUITS',
|
||||||
]
|
]
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
import sys, os, re, time, types
|
import sys, os, re, time
|
||||||
|
|
||||||
# PySol imports
|
# PySol imports
|
||||||
from mfxutil import Pickler, Unpickler, UnpicklingError
|
from settings import DATA_DIRS
|
||||||
from mfxutil import Struct, EnvError
|
|
||||||
from settings import DATA_DIRS, PACKAGE, VERSION, VERSION_TUPLE
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // constants
|
# // constants
|
||||||
|
@ -149,9 +147,9 @@ class Timer:
|
||||||
class DataLoader:
|
class DataLoader:
|
||||||
def __init__(self, argv0, filenames, path=[]):
|
def __init__(self, argv0, filenames, path=[]):
|
||||||
self.dir = None
|
self.dir = None
|
||||||
if type(filenames) is types.StringType:
|
if isinstance(filenames, str):
|
||||||
filenames = (filenames,)
|
filenames = (filenames,)
|
||||||
assert type(filenames) in (types.TupleType, types.ListType)
|
assert isinstance(filenames, (tuple, list))
|
||||||
#$ init path
|
#$ init path
|
||||||
path = path[:]
|
path = path[:]
|
||||||
head, tail = os.path.split(argv0)
|
head, tail = os.path.split(argv0)
|
||||||
|
@ -171,7 +169,7 @@ class DataLoader:
|
||||||
for p in path:
|
for p in path:
|
||||||
if not p: continue
|
if not p: continue
|
||||||
np = os.path.abspath(p)
|
np = os.path.abspath(p)
|
||||||
if np and (not np in self.path) and os.path.isdir(np):
|
if np and (np not in self.path) and os.path.isdir(np):
|
||||||
self.path.append(np)
|
self.path.append(np)
|
||||||
# now try to find all filenames along path
|
# now try to find all filenames along path
|
||||||
for p in self.path:
|
for p in self.path:
|
||||||
|
@ -186,14 +184,14 @@ class DataLoader:
|
||||||
self.dir = p
|
self.dir = p
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise os.error, str(argv0) + ": DataLoader could not find " + str(filenames)
|
raise OSError(str(argv0)+": DataLoader could not find "+str(filenames))
|
||||||
##print path, self.path, self.dir
|
##print path, self.path, self.dir
|
||||||
|
|
||||||
|
|
||||||
def __findFile(self, func, filename, subdirs=None, do_raise=1):
|
def __findFile(self, func, filename, subdirs=None, do_raise=1):
|
||||||
if subdirs is None:
|
if subdirs is None:
|
||||||
subdirs = ("",)
|
subdirs = ("",)
|
||||||
elif type(subdirs) is types.StringType:
|
elif isinstance(subdirs, str):
|
||||||
subdirs = (subdirs,)
|
subdirs = (subdirs,)
|
||||||
for dir in subdirs:
|
for dir in subdirs:
|
||||||
f = os.path.join(self.dir, dir, filename)
|
f = os.path.join(self.dir, dir, filename)
|
||||||
|
@ -201,7 +199,7 @@ class DataLoader:
|
||||||
if func(f):
|
if func(f):
|
||||||
return f
|
return f
|
||||||
if do_raise:
|
if do_raise:
|
||||||
raise os.error, "DataLoader could not find " + filename + " in " + self.dir + " " + str(subdirs)
|
raise OSError("DataLoader could not find "+filename+" in "+self.dir+" "+str(subdirs))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def findFile(self, filename, subdirs=None):
|
def findFile(self, filename, subdirs=None):
|
||||||
|
@ -212,7 +210,7 @@ class DataLoader:
|
||||||
f = self.__findFile(os.path.isfile, filename+ext, subdirs, 0)
|
f = self.__findFile(os.path.isfile, filename+ext, subdirs, 0)
|
||||||
if f:
|
if f:
|
||||||
return f
|
return f
|
||||||
raise os.error, "DataLoader could not find image " + filename + " in " + self.dir + " " + str(subdirs)
|
raise OSError("DataLoader could not find image "+filename+" in "+self.dir+" "+str(subdirs))
|
||||||
|
|
||||||
def findIcon(self, filename=None, subdirs=None):
|
def findIcon(self, filename=None, subdirs=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
|
|
Loading…
Add table
Reference in a new issue