From ccd9a98c36b00ff63a9f6e1386c128f227cc23e4 Mon Sep 17 00:00:00 2001
From: Raphael Groner <projects.rg@smart.ms>
Date: Fri, 25 Dec 2015 21:53:39 +0100
Subject: [PATCH] 2to3 modifications
---
apx/board.py | 16 ++++++++--------
apx/game.py | 2 +-
apx/lib/graphics.py | 17 +++++++++--------
apx/lib/layout.py | 2 +-
apx/lib/pytweener.py | 12 ++++++------
apx/scores.py | 8 ++++----
apx/screens.py | 12 ++++++------
apx/splash.py | 6 +++---
apx/sprites.py | 12 ++++++------
9 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/apx/board.py b/apx/board.py
index fe790c8..fb8fd19 100644
--- a/apx/board.py
+++ b/apx/board.py
@@ -8,14 +8,14 @@
import itertools
-import board
-import sprites
+from . import board
+from . import sprites
-from lib import game_utils
-from lib import graphics
-from lib import layout
-from lib import utils
-from lib.pytweener import Easing
+from .lib import game_utils
+from .lib import graphics
+from .lib import layout
+from .lib import utils
+from .lib.pytweener import Easing
class StatePanel(layout.VBox):
@@ -298,7 +298,7 @@ def _handle_keys(self, keys_down, game):
# find the furthest step we can take for the next game polygon dot
# when not drawing that's as far as we can go on current line
# when drawing, that's the closest border within step
- for speed in reversed(range(self.cube.speed)):
+ for speed in reversed(list(range(self.cube.speed))):
game_x = x if direction in ("up", "down") else x + (speed + 1) * speed_direction
game_y = y if direction in ("left", "right") else y + (speed + 1) * speed_direction
diff --git a/apx/game.py b/apx/game.py
index cd0f2ce..9ad1722 100644
--- a/apx/game.py
+++ b/apx/game.py
@@ -4,7 +4,7 @@
import datetime as dt
from gi.repository import GObject as gobject
-from lib import game_utils
+from .lib import game_utils
from collections import defaultdict
class Game(gobject.GObject):
diff --git a/apx/lib/graphics.py b/apx/lib/graphics.py
index 3613fd0..d751039 100644
--- a/apx/lib/graphics.py
+++ b/apx/lib/graphics.py
@@ -10,6 +10,7 @@
import datetime as dt
import gi
+import collections
gi.require_version('Gtk', '3.0')
gi.require_version('PangoCairo', '1.0')
@@ -25,7 +26,7 @@
import re
try:
- import pytweener
+ from . import pytweener
except: # we can also live without tweener. Scene.animate will not work
pytweener = None
@@ -64,7 +65,7 @@ def parse(self, color):
assert color is not None
#parse color into rgb values
- if isinstance(color, basestring):
+ if isinstance(color, str):
match = self.hex_color_long.match(color)
if match:
color = [int(color, 16) / 65535.0 for color in match.groups()]
@@ -155,7 +156,7 @@ def on_done(sprite=None):
if len(steps) > 2:
params['on_complete'] = on_done
- if callable(obj):
+ if isinstance(obj, collections.Callable):
obj(**params)
else:
obj.animate(**params)
@@ -679,10 +680,10 @@ def log(self, *lines):
"""will print out the lines in console if debug is enabled for the
specific sprite"""
if getattr(self, "debug", False):
- print dt.datetime.now().time(),
+ print(dt.datetime.now().time(), end=' ')
for line in lines:
- print line,
- print
+ print(line, end=' ')
+ print()
def _add(self, sprite, index = None):
"""add one sprite at a time. used by add_child. split them up so that
@@ -1174,7 +1175,7 @@ def animate(self, duration = None, easing = None, on_complete = None,
return scene.animate(self, duration, easing, on_complete,
on_update, round, **kwargs)
else:
- for key, val in kwargs.items():
+ for key, val in list(kwargs.items()):
setattr(self, key, val)
return None
@@ -1492,7 +1493,7 @@ def __init__(self, text = "", size = None, color = None,
def __setattr__(self, name, val):
if name == "font_desc":
- if isinstance(val, basestring):
+ if isinstance(val, str):
val = pango.FontDescription(val)
elif isinstance(val, pango.FontDescription):
val = val.copy()
diff --git a/apx/lib/layout.py b/apx/lib/layout.py
index 24a74e7..4f734f3 100644
--- a/apx/lib/layout.py
+++ b/apx/lib/layout.py
@@ -12,7 +12,7 @@
from gi.repository import Pango as pango
from collections import defaultdict
-import graphics
+from . import graphics
class Widget(graphics.Sprite):
diff --git a/apx/lib/pytweener.py b/apx/lib/pytweener.py
index 39d11e2..6cb2334 100644
--- a/apx/lib/pytweener.py
+++ b/apx/lib/pytweener.py
@@ -135,7 +135,7 @@ def __init__(self, obj, duration, delay, easing, on_complete, on_update, round,
# list of (property, start_value, delta)
self.tweenables = set()
- for key, value in kwargs.items():
+ for key, value in list(kwargs.items()):
self.tweenables.add((key, Tweenable(getattr(self.target, key), value)))
self.delta = 0
@@ -227,7 +227,7 @@ def color_update(fraction):
self.start_value = self.decode_func(start_value)
self.change = self.decode_func(target_value) - self.start_value
- elif isinstance(start_value, basestring) \
+ elif isinstance(start_value, str) \
and (self.hex_color_normal.match(start_value) or self.hex_color_short.match(start_value)):
self.update = color_update
if self.hex_color_normal.match(start_value):
@@ -357,17 +357,17 @@ def __init__(self, a, b, c):
total = dt.datetime.now()
t = dt.datetime.now()
- print "Adding %d tweens..." % object_count
+ print("Adding %d tweens..." % object_count)
for i, o in enumerate(objects):
tweener.add_tween(o, a = i,
b = i,
c = i,
duration = 0.1 * update_times,
easing=Easing.Circ.ease_in_out)
- print dt.datetime.now() - t
+ print(dt.datetime.now() - t)
t = dt.datetime.now()
- print "Updating %d times......" % update_times
+ print("Updating %d times......" % update_times)
for i in range(update_times): #update 1000 times
tweener.update(0.1)
- print dt.datetime.now() - t
+ print(dt.datetime.now() - t)
diff --git a/apx/scores.py b/apx/scores.py
index 7e32dbb..fc82fac 100644
--- a/apx/scores.py
+++ b/apx/scores.py
@@ -19,11 +19,11 @@ def __init_db_file(self):
from xdg.BaseDirectory import xdg_data_home
database_dir = os.path.realpath(os.path.join(xdg_data_home, "apx"))
except ImportError:
- print "Could not import xdg - will store apx.sqlite in the home folder"
+ print("Could not import xdg - will store apx.sqlite in the home folder")
database_dir = os.path.realpath(os.path.expanduser("~"))
if not os.path.exists(database_dir):
- os.makedirs(database_dir, 0744)
+ os.makedirs(database_dir, 0o744)
# handle the move to xdg_data_home
db_path = os.path.join(database_dir, "apx.sqlite")
@@ -45,7 +45,7 @@ def __init_db_file(self):
copyfile(os.path.join(data_dir, 'apx.sqlite'), db_path)
#change also permissions - sometimes they are 444
- os.chmod(db_path, 0664)
+ os.chmod(db_path, 0o664)
return db_path
@@ -54,7 +54,7 @@ def get_scores(self):
scores = self.fetch("""select date, name, level, score, duration from scores
order by score desc;
""")
- return [dict(zip(("date", "name", "level", "score", "duration"), row)) for row in scores]
+ return [dict(list(zip(("date", "name", "level", "score", "duration"), row))) for row in scores]
def save_score(self, player_name, game):
diff --git a/apx/screens.py b/apx/screens.py
index b8abee3..d830f45 100644
--- a/apx/screens.py
+++ b/apx/screens.py
@@ -7,13 +7,13 @@
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
-import scores
-import sprites
+from . import scores
+from . import sprites
-from lib import graphics
-from lib import layout
-from lib import utils
-from lib.pytweener import Easing
+from .lib import graphics
+from .lib import layout
+from .lib import utils
+from .lib.pytweener import Easing
class PauseScreen(layout.Container):
def __init__(self, id):
diff --git a/apx/splash.py b/apx/splash.py
index 1a8b54b..e4af49b 100644
--- a/apx/splash.py
+++ b/apx/splash.py
@@ -11,10 +11,10 @@
from gi.repository import GObject as gobject
from gi.repository import Pango as pango
-from lib import graphics
-from lib.pytweener import Easing
+from .lib import graphics
+from .lib.pytweener import Easing
-import sprites
+from . import sprites
class Point(gobject.GObject):
__gsignals__ = {
diff --git a/apx/sprites.py b/apx/sprites.py
index 1c6af1c..36b9aec 100644
--- a/apx/sprites.py
+++ b/apx/sprites.py
@@ -6,13 +6,13 @@
from gi.repository import GObject as gobject
-from lib import graphics
-from lib.pytweener import Easing
+from .lib import graphics
+from .lib.pytweener import Easing
-from lib import game_utils
-from lib import layout
+from .lib import game_utils
+from .lib import layout
-import colors
+from . import colors
class Label(layout.Label):
def __init__(self, *args, **kwargs):
@@ -59,7 +59,7 @@ def on_render(self, sprite):
@property
def current_speed(self):
- for speed_name, speed in self._speeds.iteritems():
+ for speed_name, speed in self._speeds.items():
if speed == self.drawing_speed:
return speed_name
return "fast"