diff --git a/pysollib/games/special/__init__.py b/pysollib/games/special/__init__.py
index 5486a9c7..81eb9fc1 100644
--- a/pysollib/games/special/__init__.py
+++ b/pysollib/games/special/__init__.py
@@ -25,3 +25,6 @@ import memory
import pegged
import poker
import tarock
+
+def no_use():
+ pass
diff --git a/pysollib/main.py b/pysollib/main.py
index 0e7b9192..a2ffa0bb 100644
--- a/pysollib/main.py
+++ b/pysollib/main.py
@@ -1,41 +1,44 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-##---------------------------------------------------------------------------##
-##
-## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
-## Copyright (C) 2003 Mt. Hood Playing Card Co.
-## Copyright (C) 2005-2009 Skomoroh
-##
-## This program is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program. If not, see .
-##
-##---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------##
+#
+# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
+# Copyright (C) 2003 Mt. Hood Playing Card Co.
+# Copyright (C) 2005-2009 Skomoroh
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ---------------------------------------------------------------------------##
# imports
-import sys, os
+import os
+import sys
import traceback
import getopt
# PySol imports
-from pysollib.mygettext import _, n_
+from pysollib.mygettext import _
from pysollib.util import DataLoader
from pysollib.mfxutil import print_err
from pysollib.resource import Tile
from pysollib.app import Application
from pysollib.gamedb import GAME_DB
-from pysollib.pysolaudio import AbstractAudioClient, PysolSoundServerModuleClient
-from pysollib.pysolaudio import Win32AudioClient, OSSAudioClient, PyGameAudioClient
+from pysollib.pysolaudio import AbstractAudioClient, \
+ PysolSoundServerModuleClient
+from pysollib.pysolaudio import Win32AudioClient, OSSAudioClient, \
+ PyGameAudioClient
from pysollib.settings import TITLE, SOUND_MOD
from pysollib.winsystems import init_root_window
@@ -52,15 +55,15 @@ from pysollib.pysoltk import PysolProgressBar
def fatal_no_cardsets(app):
app.wm_withdraw()
- d = MfxMessageDialog(app.top, title=_("%s installation error") % TITLE,
- text=_('''No cardsets were found !!!
+ MfxMessageDialog(app.top, title=_("%s installation error") % TITLE,
+ text=_('''No cardsets were found !!!
Main data directory is:
%s
Please check your %s installation.
''') % (app.dataloader.dir, TITLE),
- bitmap="error", strings=(_("&Quit"),))
+ bitmap="error", strings=(_("&Quit"),))
# ************************************************************************
@@ -77,17 +80,17 @@ def parse_option(argv):
"nosound",
"sound-mod=",
"help"])
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
print_err(_("%s\ntry %s --help for more information") %
(err, prog_name), 0)
return None
- opts = {"help" : False,
- "game" : None,
- "gameid" : None,
- "french-only" : False,
- "noplugins" : False,
- "nosound" : False,
- "sound-mod" : None,
+ opts = {"help": False,
+ "game": None,
+ "gameid": None,
+ "french-only": False,
+ "noplugins": False,
+ "nosound": False,
+ "sound-mod": None,
}
for i in optlist:
if i[0] in ("-h", "--help"):
@@ -107,7 +110,7 @@ def parse_option(argv):
opts["sound-mod"] = i[1]
if opts["help"]:
- print _("""Usage: %s [OPTIONS] [FILE]
+ print(_("""Usage: %s [OPTIONS] [FILE]
-g --game=GAMENAME start game GAMENAME
-i --gameid=GAMEID
--french-only
@@ -118,7 +121,7 @@ def parse_option(argv):
FILE - file name of a saved game
MOD - one of following: pss(default), pygame, oss, win
-""") % prog_name
+""") % prog_name)
return None
if len(args) > 1:
@@ -138,6 +141,7 @@ def parse_option(argv):
# *
# ************************************************************************
+
def pysol_init(app, args):
# init commandline options (undocumented)
@@ -160,15 +164,16 @@ def pysol_init(app, args):
app.dn.config,
app.dn.savegames,
os.path.join(app.dn.config, "music"),
- ##os.path.join(app.dn.config, "screenshots"),
+ # os.path.join(app.dn.config, "screenshots"),
os.path.join(app.dn.config, "tiles"),
os.path.join(app.dn.config, "tiles", "stretch"),
os.path.join(app.dn.config, "tiles", "save-aspect"),
os.path.join(app.dn.config, "cardsets"),
os.path.join(app.dn.config, "plugins"),
- ):
+ ):
if not os.path.exists(d):
- try: os.makedirs(d)
+ try:
+ os.makedirs(d)
except:
traceback.print_exc()
pass
@@ -218,6 +223,7 @@ def pysol_init(app, args):
import pysollib.games.ultra
import pysollib.games.mahjongg
import pysollib.games.special
+ pysollib.games.special.no_use()
# try to load plugins
if not opts["noplugins"]:
@@ -305,7 +311,7 @@ Please check your %s installation.
tile.filename = None
manager.register(tile)
app.initTiles()
- if app.opt.tabletile_name: ### and top.winfo_screendepth() > 8:
+ if app.opt.tabletile_name: # and top.winfo_screendepth() > 8:
for tile in manager.getAll():
if app.opt.tabletile_name == tile.basename:
app.tabletile_index = tile.index
diff --git a/pysollib/mfxutil.py b/pysollib/mfxutil.py
index 8652f25b..ecfe4f18 100644
--- a/pysollib/mfxutil.py
+++ b/pysollib/mfxutil.py
@@ -1,31 +1,47 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-##---------------------------------------------------------------------------##
-##
-## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
-## Copyright (C) 2003 Mt. Hood Playing Card Co.
-## Copyright (C) 2005-2009 Skomoroh
-##
-## This program is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program. If not, see .
-##
-##---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------##
+#
+# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
+# Copyright (C) 2003 Mt. Hood Playing Card Co.
+# Copyright (C) 2005-2009 Skomoroh
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ---------------------------------------------------------------------------##
+__all__ = [
+ 'BmpImagePlugin',
+ 'GifImagePlugin',
+ 'Image',
+ 'ImageOps',
+ 'ImageTk',
+ 'JpegImagePlugin',
+ 'PngImagePlugin',
+ 'PpmImagePlugin',
+ 'UnpicklingError',
+ ]
# imports
-import sys, os, time, types, locale
+import sys
+import os
+import time
+import types
+import locale
import webbrowser
+
try:
from cPickle import Pickler, Unpickler, UnpicklingError
except ImportError:
@@ -36,11 +52,11 @@ try:
except:
thread = None
-from pysollib.settings import PACKAGE, TOOLKIT, USE_TILE
+from pysollib.settings import PACKAGE, TOOLKIT
Image = ImageTk = ImageOps = None
if TOOLKIT == 'tk':
- try: # PIL
+ try: # PIL
from PIL import Image
from PIL import ImageTk
from PIL import ImageOps
@@ -58,14 +74,17 @@ USE_PIL = False
if TOOLKIT == 'tk' and Image and Image.VERSION >= '1.1.7':
USE_PIL = True
+if sys.version_info > (3,):
+ unicode = str
# debug
-#Image = None
-#USE_PIL = False
+# Image = None
+# USE_PIL = False
# ************************************************************************
# * exceptions
# ************************************************************************
+
class SubclassResponsibility(Exception):
pass
@@ -76,9 +95,9 @@ class SubclassResponsibility(Exception):
def latin1_to_ascii(n):
- #return n
+ # return n
n = n.encode('iso8859-1', 'replace')
- ## FIXME: rewrite this for better speed
+ # FIXME: rewrite this for better speed
n = (n.replace("\xc4", "Ae")
.replace("\xd6", "Oe")
.replace("\xdc", "Ue")
@@ -89,9 +108,11 @@ def latin1_to_ascii(n):
def format_time(t):
- ##print 'format_time:', t
- if t <= 0: return "0:00"
- if t < 3600: return "%d:%02d" % (t / 60, t % 60)
+ # print 'format_time:', t
+ if t <= 0:
+ return "0:00"
+ if t < 3600:
+ return "%d:%02d" % (t / 60, t % 60)
return "%d:%02d:%02d" % (t / 3600, (t % 3600) / 60, t % 60)
@@ -113,9 +134,9 @@ def print_err(s, level=1):
def getusername():
if os.name == "nt":
return win32_getusername()
- user = os.environ.get("USER","").strip()
+ user = os.environ.get("USER", "").strip()
if not user:
- user = os.environ.get("LOGNAME","").strip()
+ user = os.environ.get("LOGNAME", "").strip()
return user
@@ -138,14 +159,16 @@ if os.name == "posix":
# * MSWin util
# ************************************************************************
+
def win32_getusername():
- user = os.environ.get('USERNAME','').strip()
+ user = os.environ.get('USERNAME', '').strip()
try:
user = unicode(user, locale.getpreferredencoding())
except:
user = ''
return user
+
def win32_getprefdir(package):
portprefdir = 'config' # portable varsion
if os.path.isdir(portprefdir):
@@ -154,7 +177,7 @@ def win32_getprefdir(package):
hd = os.environ.get('APPDATA')
if not hd:
hd = os.path.expanduser('~')
- if hd == '~': # win9x
+ if hd == '~': # win9x
hd = os.path.abspath('/windows/Application Data')
if not os.path.exists(hd):
hd = os.path.abspath('/')
@@ -171,7 +194,7 @@ def destruct(obj):
assert isinstance(obj, types.InstanceType)
for k in obj.__dict__.keys():
obj.__dict__[k] = None
- ##del obj.__dict__[k]
+ # del obj.__dict__[k]
# ************************************************************************
@@ -268,10 +291,12 @@ def pickle(obj, filename, protocol=0):
f = open(filename, "wb")
p = Pickler(f, protocol)
p.dump(obj)
- f.close(); f = None
- ##print "Pickled", filename
+ f.close()
+ f = None
+ # print "Pickled", filename
finally:
- if f: f.close()
+ if f:
+ f.close()
def unpickle(filename):
@@ -280,11 +305,13 @@ def unpickle(filename):
f = open(filename, "rb")
p = Unpickler(f)
x = p.load()
- f.close(); f = None
+ f.close()
+ f = None
obj = x
- ##print "Unpickled", filename
+ # print "Unpickled", filename
finally:
- if f: f.close()
+ if f:
+ f.close()
return obj
@@ -300,4 +327,3 @@ def openURL(url):
except:
return 0
return 1
-
diff --git a/pysollib/move.py b/pysollib/move.py
index 39016292..cd7f183b 100644
--- a/pysollib/move.py
+++ b/pysollib/move.py
@@ -1,26 +1,31 @@
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
-##---------------------------------------------------------------------------##
-##
-## Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
-## Copyright (C) 2003 Mt. Hood Playing Card Co.
-## Copyright (C) 2005-2009 Skomoroh
-##
-## This program is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with this program. If not, see .
-##
-##---------------------------------------------------------------------------##
+# ---------------------------------------------------------------------------##
+#
+# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
+# Copyright (C) 2003 Mt. Hood Playing Card Co.
+# Copyright (C) 2005-2009 Skomoroh
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ---------------------------------------------------------------------------##
+import sys
+
+if sys.version_info > (3,):
+ def cmp(a, b):
+ return ((b > a)-(a > b))
# imports
@@ -29,14 +34,14 @@
# * moves (undo / redo)
# ************************************************************************
-## Currently we have the following atomic moves:
-## - move the top cards from one stack on the top of another
-## - flip the top card of a stack
-## - turn a whole stack onto another stack
-## - update the model or complete view a stack
-## - increase the round (the number of redeals)
-## - save the seed of game.random
-## - shuffle a stack
+# Currently we have the following atomic moves:
+# - move the top cards from one stack on the top of another
+# - flip the top card of a stack
+# - turn a whole stack onto another stack
+# - update the model or complete view a stack
+# - increase the round (the number of redeals)
+# - save the seed of game.random
+# - shuffle a stack
class AtomicMove:
@@ -45,6 +50,7 @@ class AtomicMove:
def __repr__(self):
return str(self.__dict__)
+
def __str__(self):
return str(self.__dict__)
@@ -69,7 +75,8 @@ class AMoveMove(AtomicMove):
# do the actual move
def _doMove(self, game, ncards, from_stack, to_stack):
if game.moves.state == game.S_PLAY:
- assert to_stack.acceptsCards(from_stack, from_stack.cards[-ncards:])
+ assert to_stack.acceptsCards(
+ from_stack, from_stack.cards[-ncards:])
frames = self.frames
if frames == -2 and game.moves.state not in (game.S_UNDO, game.S_REDO):
# don't use animation for drag-move
@@ -112,7 +119,7 @@ class AFlipMove(AtomicMove):
# do the actual move
def _doMove(self, game, stack):
card = stack.cards[-1]
- ##game.animatedFlip(stack)
+ # game.animatedFlip(stack)
if card.face_up:
card.showBack()
else:
@@ -127,6 +134,7 @@ class AFlipMove(AtomicMove):
def cmpForRedo(self, other):
return cmp(self.stack_id, other.stack_id)
+
# flip with animation
class ASingleFlipMove(AFlipMove):
def _doMove(self, game, stack):
@@ -137,6 +145,7 @@ class ASingleFlipMove(AFlipMove):
else:
card.showFace()
+
# flip and move one card
class AFlipAndMoveMove(AtomicMove):
@@ -228,15 +237,15 @@ class ATurnStackMove(AtomicMove):
assert len(to_stack.cards) == 0
l = len(from_stack.cards)
for i in range(l):
- ##unhide = (i >= l - 2)
+ # unhide = (i >= l - 2)
unhide = 1
- ##print 1, unhide, from_stack.getCard().__dict__
+ # print 1, unhide, from_stack.getCard().__dict__
card = from_stack.removeCard(unhide=unhide, update=0)
- ##print 2, unhide, card.__dict__
+ # print 2, unhide, card.__dict__
assert card.face_up
to_stack.addCard(card, unhide=unhide, update=0)
card.showBack(unhide=unhide)
- ##print 3, unhide, to_stack.getCard().__dict__
+ # print 3, unhide, to_stack.getCard().__dict__
from_stack.updateText()
to_stack.updateText()
@@ -247,7 +256,7 @@ class ATurnStackMove(AtomicMove):
assert len(to_stack.cards) == 0
l = len(from_stack.cards)
for i in range(l):
- ##unhide = (i >= l - 2)
+ # unhide = (i >= l - 2)
unhide = 1
card = from_stack.removeCard(unhide=unhide, update=0)
assert not card.face_up
@@ -299,7 +308,8 @@ class NEW_ATurnStackMove(AtomicMove):
to_stack = game.allstacks[self.to_stack_id]
if self.update_flags & 1:
assert to_stack is game.s.talon
- assert to_stack.round < to_stack.max_rounds or to_stack.max_rounds < 0
+ assert to_stack.round < to_stack.max_rounds or \
+ to_stack.max_rounds < 0
to_stack.round = to_stack.round + 1
self._doMove(from_stack, to_stack, 0)
@@ -349,7 +359,8 @@ class AUpdateStackMove(AtomicMove):
self._doMove(game, game.allstacks[self.stack_id], 1)
def cmpForRedo(self, other):
- return cmp(self.stack_id, other.stack_id) or cmp(self.flags, other.flags)
+ return cmp(self.stack_id, other.stack_id) or \
+ cmp(self.flags, other.flags)
AUpdateStackModelMove = AUpdateStackMove
@@ -484,7 +495,8 @@ class ASingleCardMove(AtomicMove):
to_stack = game.allstacks[self.to_stack_id]
from_pos = self.from_pos
if game.moves.state == game.S_PLAY:
- assert to_stack.acceptsCards(from_stack, [from_stack.cards[from_pos]])
+ assert to_stack.acceptsCards(
+ from_stack, [from_stack.cards[from_pos]])
card = from_stack.cards[from_pos]
card = from_stack.removeCard(card, update_positions=1)
if self.frames != 0:
@@ -492,19 +504,19 @@ class ASingleCardMove(AtomicMove):
game.animatedMoveTo(from_stack, to_stack, [card], x, y,
frames=self.frames, shadow=self.shadow)
to_stack.addCard(card)
- ##to_stack.refreshView()
+ # to_stack.refreshView()
def undo(self, game):
from_stack = game.allstacks[self.from_stack_id]
to_stack = game.allstacks[self.to_stack_id]
from_pos = self.from_pos
card = to_stack.removeCard()
-## if self.frames != 0:
-## x, y = to_stack.getPositionFor(card)
-## game.animatedMoveTo(from_stack, to_stack, [card], x, y,
-## frames=self.frames, shadow=self.shadow)
+ # if self.frames != 0:
+ # x, y = to_stack.getPositionFor(card)
+ # game.animatedMoveTo(from_stack, to_stack, [card], x, y,
+ # frames=self.frames, shadow=self.shadow)
from_stack.insertCard(card, from_pos)
- ##to_stack.refreshView()
+ # to_stack.refreshView()
def cmpForRedo(self, other):
return cmp((self.from_stack_id, self.to_stack_id, self.from_pos),
@@ -522,12 +534,13 @@ class AInnerMove(AtomicMove):
self.from_pos, self.to_pos = from_pos, to_pos
def redo(self, game):
- stack = game.allstacks[self.stack_id]
+ # stack = game.allstacks[self.stack_id]
+ pass
def undo(self, game):
- stack = game.allstacks[self.stack_id]
+ # stack = game.allstacks[self.stack_id]
+ pass
def cmpForRedo(self, other):
return cmp((self.stack_id, self.from_pos, self.to_pos),
(other.stack_id, other.from_pos, other.to_pos))
-
diff --git a/pysollib/mygettext.py b/pysollib/mygettext.py
index 0b51a7c5..85bc3cc9 100644
--- a/pysollib/mygettext.py
+++ b/pysollib/mygettext.py
@@ -2,10 +2,16 @@
# -*- mode: python; coding: utf-8; -*-
import gettext
+import sys
+
+if sys.version_info > (3,):
+ unicode = str
+
def n_(x):
return x
+
def fix_gettext():
def ugettext(message):
# unicoded gettext
@@ -19,6 +25,7 @@ def fix_gettext():
return message
return t.ugettext(message)
gettext.ugettext = ugettext
+
def ungettext(msgid1, msgid2, n):
# unicoded ngettext
if not isinstance(msgid1, unicode):
@@ -37,5 +44,6 @@ def fix_gettext():
return t.ungettext(msgid1, msgid2, n)
gettext.ungettext = ungettext
+
fix_gettext()
_ = gettext.ugettext
diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t
index a5b8565f..b44c9250 100644
--- a/tests/style/py-flake8.t
+++ b/tests/style/py-flake8.t
@@ -9,7 +9,7 @@ use Test::Differences qw( eq_or_diff );
use String::ShellQuote qw/ shell_quote /;
# my $cmd = shell_quote( 'flake8', '.' );
-my $cmd = shell_quote( 'flake8', glob('./pysollib/[a-l]*.py') );
+my $cmd = shell_quote( 'flake8', glob('./pysollib/[a-m]*.py') );
# TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );