diff --git a/pysollib/images.py b/pysollib/images.py
index c47de503..954063e9 100644
--- a/pysollib/images.py
+++ b/pysollib/images.py
@@ -1,38 +1,37 @@
#!/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 os
-import traceback
# PySol imports
from pysollib.resource import CSI
-from pysollib.settings import TOOLKIT
from pysollib.mfxutil import Image, ImageTk, USE_PIL
# Toolkit imports
-from pysollib.pysoltk import loadImage, copyImage, createImage, shadowImage, createBottom, resizeBottom
+from pysollib.pysoltk import loadImage, copyImage, createImage, \
+ shadowImage, createBottom
# ************************************************************************
# * Images
@@ -41,7 +40,8 @@ from pysollib.pysoltk import loadImage, copyImage, createImage, shadowImage, cre
class ImagesCardback:
def __init__(self, index, name, image, menu_image=None):
- if menu_image is None: menu_image = image
+ if menu_image is None:
+ menu_image = image
self.index = index
self.name = name
self.image = image
@@ -60,14 +60,16 @@ class Images:
self._setSize()
self._card = []
self._back = []
- self._bottom = [] # bottom of stack (link to _bottom_negative/_bottom_positive)
+ # bottom of stack (link to _bottom_negative/_bottom_positive)
+ self._bottom = []
self._bottom_negative = [] # negative bottom of stack (white)
self._bottom_positive = [] # positive bottom of stack (black)
self._blank_bottom = None # blank (transparent) bottom of stack
self._letter = [] # images of letter
self._letter_negative = []
self._letter_positive = []
- self._shadow = [] # vertical shadow of card (used when we drag a card)
+ # vertical shadow of card (used when we drag a card)
+ self._shadow = []
self._xshadow = [] # horizontal shadow of card
self._pil_shadow = {} # key: (width, height)
self._highlight = [] # highlight of card (tip)
@@ -78,7 +80,7 @@ class Images:
pass
def __loadCard(self, filename, check_w=1, check_h=1):
- ##print '__loadCard:', filename
+ # print '__loadCard:', filename
f = os.path.join(self.cs.dir, filename)
if not os.path.exists(f):
return None
@@ -91,7 +93,7 @@ class Images:
self.CARDW, self.CARDH = w, h
else:
if ((check_w and w != self.CARDW) or
- (check_h and h != self.CARDH)):
+ (check_h and h != self.CARDH)):
raise ValueError("Invalid size %dx%d of image %s" % (w, h, f))
return img
@@ -107,7 +109,8 @@ class Images:
# load image
img = self.__loadCard(filename+self.cs.ext, check_w, check_h)
if USE_PIL:
- # we have no bottom images (data/images/cards/bottoms/)
+ # we have no bottom images
+ # (data/images/cards/bottoms/)
img = img.resize(self._xfactor, self._yfactor)
return img
# create image
@@ -158,56 +161,70 @@ class Images:
ext = self.cs.ext[1:]
pstep = 0
if progress:
- pstep = self.cs.ncards + len(self.cs.backnames) + self.cs.nbottoms + self.cs.nletters
- pstep += self.cs.nshadows + 1 # shadows & shade
+ pstep = self.cs.ncards + len(self.cs.backnames) + \
+ self.cs.nbottoms + self.cs.nletters
+ pstep += self.cs.nshadows + 1 # shadows & shade
pstep = max(0, (80.0 - progress.percent) / pstep)
# load face cards
for n in self.cs.getFaceCardNames():
self._card.append(self.__loadCard(n + self.cs.ext))
self._card[-1].filename = n
- if progress: progress.update(step=pstep)
+ if progress:
+ progress.update(step=pstep)
assert len(self._card) == self.cs.ncards
# load backgrounds
for name in self.cs.backnames:
if name:
im = self.__loadCard(name)
self.__addBack(im, name)
- if progress: progress.update(step=1)
+ if progress:
+ progress.update(step=1)
# load bottoms
for i in range(self.cs.nbottoms):
name = "bottom%02d" % (i + 1)
- self._bottom_positive.append(self.__loadBottom(name, color='black'))
- if progress: progress.update(step=pstep)
+ self._bottom_positive.append(
+ self.__loadBottom(name, color='black'))
+ if progress:
+ progress.update(step=pstep)
# load negative bottoms
name = "bottom%02d-n" % (i + 1)
- self._bottom_negative.append(self.__loadBottom(name, color='white'))
- if progress: progress.update(step=pstep)
+ self._bottom_negative.append(
+ self.__loadBottom(name, color='white'))
+ if progress:
+ progress.update(step=pstep)
# load letters
for rank in range(self.cs.nletters):
name = "l%02d" % (rank + 1)
- self._letter_positive.append(self.__loadBottom(name, color='black'))
- if progress: progress.update(step=pstep)
+ self._letter_positive.append(
+ self.__loadBottom(name, color='black'))
+ if progress:
+ progress.update(step=pstep)
# load negative letters
name = "l%02d-n" % (rank + 1)
- self._letter_negative.append(self.__loadBottom(name, color='white'))
- if progress: progress.update(step=pstep)
+ self._letter_negative.append(
+ self.__loadBottom(name, color='white'))
+ if progress:
+ progress.update(step=pstep)
# shadow
if not USE_PIL:
for i in range(self.cs.nshadows):
name = "shadow%02d.%s" % (i, ext)
im = self.__loadCard(name, check_w=0, check_h=0)
self._shadow.append(im)
- if i > 0: # skip 0
+ if i > 0: # skip 0
name = "xshadow%02d.%s" % (i, ext)
im = self.__loadCard(name, check_w=0, check_h=0)
self._xshadow.append(im)
- if progress: progress.update(step=pstep)
+ if progress:
+ progress.update(step=pstep)
# shade
if USE_PIL:
- self._highlight.append(self._getHighlight(self._card[0], None, '#3896f8'))
+ self._highlight.append(
+ self._getHighlight(self._card[0], None, '#3896f8'))
else:
self._highlight.append(self.__loadCard("shade." + ext))
- if progress: progress.update(step=pstep)
+ if progress:
+ progress.update(step=pstep)
# create missing
self._createMissingImages()
#
@@ -218,7 +235,7 @@ class Images:
def getFace(self, deck, suit, rank):
index = suit * len(self.cs.ranks) + rank
- ##print "getFace:", suit, rank, index
+ # print "getFace:", suit, rank, index
return self._card[index % self.cs.ncards]
def getBack(self, update=False):
@@ -238,7 +255,8 @@ class Images:
def getSuitBottom(self, suit=-1):
assert isinstance(suit, int)
- if suit == -1: return self._bottom[1] # any suit
+ if suit == -1:
+ return self._bottom[1] # any suit
i = 3 + suit
if i >= len(self._bottom):
# Trump (for Tarock type games)
@@ -257,7 +275,7 @@ class Images:
def getShadow(self, ncards):
if ncards >= 0:
if ncards >= len(self._shadow):
- ##ncards = len(self._shadow) - 1
+ # ncards = len(self._shadow) - 1
return None
return self._shadow[ncards]
else:
@@ -275,8 +293,8 @@ class Images:
x1 += cw
y1 += ch
w, h = x1-x0, y1-y0
- if (w,h) in self._pil_shadow:
- return self._pil_shadow[(w,h)]
+ if (w, h) in self._pil_shadow:
+ return self._pil_shadow[(w, h)]
# create mask
mask = Image.new('RGBA', (w, h))
for c in cards:
@@ -285,15 +303,15 @@ class Images:
im = c._active_image._pil_image
mask.paste(im, (x, y), im)
# create shadow
- sh_color = (0x00,0x00,0x00,0x50)
+ sh_color = (0x00, 0x00, 0x00, 0x50)
shadow = Image.new('RGBA', (w, h))
shadow.paste(sh_color, (0, 0, w, h), mask)
sx, sy = self.SHADOW_XOFFSET, self.SHADOW_YOFFSET
- mask = mask.crop((sx,sy,w,h))
- tmp = Image.new('RGBA', (w-sx,h-sy))
- shadow.paste(tmp, (0,0), mask)
+ mask = mask.crop((sx, sy, w, h))
+ tmp = Image.new('RGBA', (w-sx, h-sy))
+ shadow.paste(tmp, (0, 0), mask)
shadow = ImageTk.PhotoImage(shadow)
- self._pil_shadow[(w,h)] = shadow
+ self._pil_shadow[(w, h)] = shadow
return shadow
def getShade(self):
@@ -357,7 +375,7 @@ class Images:
self.CARD_DX, self.CARD_DY = cs.CARD_DX, cs.CARD_DY
def _setSize(self, xf=1, yf=1):
- #print 'image._setSize', xf, yf
+ # print 'image._setSize', xf, yf
self._xfactor = xf
self._yfactor = yf
cs = self.cs
@@ -373,21 +391,23 @@ class Images:
def getSize(self):
return (int(self.CARDW * self._xfactor),
int(self.CARDH * self._yfactor))
+
def getOffsets(self):
return (int(self.CARD_XOFFSET * self._xfactor),
int(self.CARD_YOFFSET * self._yfactor))
+
def getDelta(self):
return (int(self.CARD_DX * self._xfactor),
int(self.CARD_DY * self._yfactor))
def resize(self, xf, yf):
- #print 'Images.resize:', xf, yf, self._card[0].width(), self.CARDW
+ # print 'Images.resize:', xf, yf, self._card[0].width(), self.CARDW
if self._xfactor == xf and self._yfactor == yf:
- #print 'no resize'
+ # print 'no resize'
return
self._xfactor = xf
self._yfactor = yf
- #???self._setSize(xf, yf)
+ # ???self._setSize(xf, yf)
self.setOffsets()
# cards
cards = []
@@ -404,27 +424,32 @@ class Images:
self._bottom_positive = []
for i in range(self.cs.nbottoms):
name = "bottom%02d" % (i + 1)
- self._bottom_positive.append(self.__loadBottom(name, color='black'))
+ self._bottom_positive.append(
+ self.__loadBottom(name, color='black'))
name = "bottom%02d-n" % (i + 1)
- self._bottom_negative.append(self.__loadBottom(name, color='white'))
+ self._bottom_negative.append(
+ self.__loadBottom(name, color='white'))
# letters
self._letter_positive = []
self._letter_negative = []
for rank in range(self.cs.nletters):
name = "l%02d" % (rank + 1)
- self._letter_positive.append(self.__loadBottom(name, color='black'))
+ self._letter_positive.append(
+ self.__loadBottom(name, color='black'))
name = "l%02d-n" % (rank + 1)
- self._letter_negative.append(self.__loadBottom(name, color='white'))
+ self._letter_negative.append(
+ self.__loadBottom(name, color='white'))
self._createMissingImages()
self.setNegative(neg)
#
self._highlighted_images = {}
self._highlight = []
- self._highlight.append(self._getHighlight(self._card[0], None, '#3896f8'))
+ self._highlight.append(
+ self._getHighlight(self._card[0], None, '#3896f8'))
self._pil_shadow = {}
def reset(self):
- print 'Image.reset'
+ print('Image.reset')
self.resize(1, 1)
@@ -448,11 +473,12 @@ class SubsampledImages(Images):
self._back.append(None)
else:
im = _back.image.subsample(r)
- self._back.append(ImagesCardback(len(self._back), _back.name, im, im))
+ self._back.append(
+ ImagesCardback(len(self._back), _back.name, im, im))
#
CW, CH = self.CARDW, self.CARDH
for im in images._highlight:
- ##self._highlight.append(None)
+ # self._highlight.append(None)
self._highlight.append(copyImage(im, 0, 0, CW, CH))
def getShadow(self, ncards):
@@ -466,4 +492,3 @@ class SubsampledImages(Images):
else:
s.append(im.subsample(r))
return s
-
diff --git a/pysollib/init.py b/pysollib/init.py
index fa0318cb..3f17ff7e 100644
--- a/pysollib/init.py
+++ b/pysollib/init.py
@@ -1,30 +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, os, locale, subprocess
-import traceback
+import sys
+import os
+import locale
+import subprocess
-from pysollib.mygettext import _, n_
import gettext
import pysollib.settings
@@ -41,10 +42,10 @@ def init():
os.environ['LANG'] = l[0]
except:
pass
- ##locale.setlocale(locale.LC_ALL, '')
+ # locale.setlocale(locale.LC_ALL, '')
- ## install gettext
- ##locale_dir = 'locale'
+ # install gettext
+ # locale_dir = 'locale'
locale_dir = None
if os.path.isdir(sys.path[0]):
d = os.path.join(sys.path[0], 'locale')
@@ -53,23 +54,23 @@ def init():
d = os.path.join(os.path.dirname(sys.path[0]), 'locale')
if os.path.exists(d) and os.path.isdir(d):
locale_dir = d
- ##if locale_dir: locale_dir = os.path.normpath(locale_dir)
- #gettext.install('pysol', locale_dir, unicode=True) # ngettext don't work
+ # if locale_dir: locale_dir = os.path.normpath(locale_dir)
+ # gettext.install('pysol', locale_dir, unicode=True) # ngettext don't work
gettext.bindtextdomain('pysol', locale_dir)
gettext.textdomain('pysol')
- ## debug
+ # debug
if 'PYSOL_CHECK_GAMES' in os.environ or 'PYSOL_DEBUG' in os.environ:
pysollib.settings.CHECK_GAMES = True
- print 'PySol debugging: set CHECK_GAMES to True'
+ print('PySol debugging: set CHECK_GAMES to True')
if 'PYSOL_DEBUG' in os.environ:
try:
pysollib.settings.DEBUG = int(os.environ['PYSOL_DEBUG'])
except:
pysollib.settings.DEBUG = 1
- print 'PySol debugging: set DEBUG to', pysollib.settings.DEBUG
+ print('PySol debugging: set DEBUG to', pysollib.settings.DEBUG)
- ## init toolkit
+ # init toolkit
if '--gtk' in sys.argv:
pysollib.settings.TOOLKIT = 'gtk'
sys.argv.remove('--gtk')
@@ -106,16 +107,17 @@ def init():
else:
pysollib.settings.USE_TILE = True
# "can't invoke event <>: application has been destroyed"
- #root.destroy()
+ # root.destroy()
Tkinter._default_root = None
# check FreeCell-Solver
pysollib.settings.USE_FREECELL_SOLVER = False
if os.name == 'nt':
- if sys.path[0] and not os.path.isdir(sys.path[0]): # i.e. library.zip
+ if sys.path[0] and not os.path.isdir(sys.path[0]): # i.e. library.zip
d = os.path.dirname(sys.path[0])
os.chdir(d) # for read presets
- fcs_command = os.path.join('freecell-solver', 'bin', 'fc-solve.exe')
+ fcs_command = os.path.join(
+ 'freecell-solver', 'bin', 'fc-solve.exe')
pysollib.settings.FCS_COMMAND = fcs_command
f = os.path.join('freecell-solver', 'presetrc')
os.environ['FREECELL_SOLVER_PRESETRC'] = f
@@ -124,7 +126,7 @@ def init():
kw = {'shell': True,
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
- 'stdin': subprocess.PIPE,}
+ 'stdin': subprocess.PIPE, }
if os.name != 'nt':
kw['close_fds'] = True
p = subprocess.Popen(pysollib.settings.FCS_COMMAND+' --help', **kw)
@@ -134,7 +136,7 @@ def init():
if os.name == 'posix':
os.wait() # kill zombi
except:
- #traceback.print_exc()
+ # traceback.print_exc()
pass
os.environ['FREECELL_SOLVER_QUIET'] = '1'
@@ -142,4 +144,3 @@ def init():
if '--no-games-menu' in sys.argv:
sys.argv.remove('--no-games-menu')
pysollib.settings.SELECT_GAME_MENU = False
-
diff --git a/tests/style/py-flake8.t b/tests/style/py-flake8.t
index fe750956..1ca3996c 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-h]*.py') );
+my $cmd = shell_quote( 'flake8', glob('./pysollib/[a-i]*.py') );
# TEST
eq_or_diff( scalar(`$cmd`), '', "flake8 is happy with the code." );