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