Skip to content

Commit 17d06ae

Browse files
committed
port to python 3
1 parent 95aaa6d commit 17d06ae

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

SliderPuzzleActivity.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import logging
3939
import os
4040
import sys
41-
import md5
41+
import hashlib
4242

4343
logger = logging.getLogger('sliderpuzzle-activity')
4444

@@ -48,11 +48,11 @@
4848
# game tube
4949
import zlib
5050
import time
51-
from cStringIO import StringIO
51+
from io import StringIO
5252

5353
from dbus import Interface, DBusException
5454
from dbus.service import method, signal
55-
from dbus.gobject_service import ExportedGObject
55+
from dbus.service import Object as ExportedGObject
5656

5757
from mamamedia_modules import GAME_IDLE, GAME_STARTED, GAME_FINISHED, GAME_QUIT
5858
import logging
@@ -226,7 +226,7 @@ def sync(self, *args):
226226
if self._lock:
227227
return
228228
logger.debug("sync'ing game state")
229-
self.frozen = json.write(self.slider_ui._freeze(journal=False))
229+
self.frozen = json.dumps(self.slider_ui._freeze(journal=False))
230230

231231
def apply(self):
232232
""" Apply the saved state to the running game """
@@ -373,7 +373,7 @@ def read_file(self, file_path):
373373
self.ui._thaw(json.read(session_data))
374374

375375
def write_file(self, file_path):
376-
session_data = json.write(self.ui._freeze())
376+
session_data = json.dumps(self.ui._freeze())
377377
f = open(file_path, 'w')
378378
try:
379379
f.write(session_data)

SliderPuzzleUI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from SliderPuzzleWidget import SliderPuzzleWidget
3939
from time import time
4040
import os
41-
import md5
41+
import hashlib
4242
from sugar3.activity.activity import get_bundle_path
4343
from sugar3 import mime
4444
from sugar3.graphics.objectchooser import ObjectChooser
@@ -491,11 +491,11 @@ def _thaw(self, obj):
491491
if not obj[1]['image']:
492492
return
493493

494-
if not obj[1].has_key('image'):
494+
if 'image' not in obj[1]:
495495
self.game.load_image(self.pbb)
496496
self.set_nr_pieces(None, obj[2])
497-
logging.debug(obj[1].keys())
498-
wimg = obj[1].has_key('image')
497+
logging.debug(list(obj[1].keys()))
498+
wimg = 'image' in obj[1]
499499
self.game._thaw(obj[1])
500500
if wimg:
501501
logging.debug("Forcing thumb image from the one in game")

SliderPuzzleWidget.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
#
2020

2121
from gi.repository import Gtk, GObject, Pango, GdkPixbuf, Gdk
22-
import md5
22+
import hashlib
2323
import logging
2424
import tempfile
2525
from mamamedia_modules import utils
2626

2727
#from utils import load_image, calculate_matrix, debug, SliderCreator, trace
2828

29-
from types import TupleType, ListType
29+
TupleType = tuple
30+
ListType = list
3031
from random import random
3132
from time import time
3233
from math import sqrt
33-
from cStringIO import StringIO
34+
from io import StringIO
3435
import os
3536

3637
###
@@ -113,7 +114,7 @@ def prepare_stringed(self, rows, cols):
113114
# if c > 0 and r > 0:
114115
# pm.draw_line(gc, px, 0, px, self.height-1)
115116
# pm.draw_line(gc, 0, py, self.width-1, py)
116-
pangolayout.set_text(str(item.next()))
117+
pangolayout.set_text(str(next(item)))
117118
pe = pangolayout.get_pixel_extents()
118119
pe = pe[1][2] / 2, pe[1][3] / 2
119120
pm.draw_layout(gc, px + (sw / 2) -
@@ -194,7 +195,7 @@ def __init__(self, pieces=9, move_cb=None):
194195

195196
def reset(self, pieces=9):
196197
self.pieces, self.rowsize, self.colsize = calculate_matrix(pieces)
197-
pieces_map = range(1, self.pieces + 1)
198+
pieces_map = list(range(1, self.pieces + 1))
198199
self.pieces_map = []
199200
for i in range(self.rowsize):
200201
self.pieces_map.append(
@@ -399,7 +400,7 @@ def _freeze(self):
399400
'pieces_map': self.pieces_map, 'hole_pos_freeze': self.hole_pos._freeze()}
400401

401402
def _thaw(self, obj):
402-
for k in obj.keys():
403+
for k in list(obj.keys()):
403404
if hasattr(self, k):
404405
setattr(self, k, obj[k])
405406
self.hole_pos._thaw(obj.get('hole_pos_freeze', None))
@@ -605,7 +606,7 @@ def _thaw(self, obj):
605606
""" retrieves a frozen status from a python object, as per _freeze """
606607
logging.debug(obj['jumbler'])
607608
self.jumbler._thaw(obj['jumbler'])
608-
if obj.has_key('image') and obj['image'] is not None:
609+
if 'image' in obj and obj['image'] is not None:
609610
self.set_image_from_str(obj['image'])
610611
del obj['image']
611612
self.full_refresh()

activity/activity.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Activity]
22
name = Slider Puzzle
33
bundle_id = org.worldwideworkshop.olpc.SliderPuzzle
4-
exec = sugar-activity SliderPuzzleActivity.SliderPuzzleActivity
4+
exec = sugar-activity3 SliderPuzzleActivity.SliderPuzzleActivity
55
icon = activity-sliderpuzzle
66
activity_version = 10
77
show_launcher = yes

mmm_modules/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from borderframe import *
2-
from timer import *
3-
from image_category import *
4-
from i18n import *
1+
from .borderframe import *
2+
from .timer import *
3+
from .image_category import *
4+
from .i18n import *
55
#from notebook_reader import *
6-
from buddy_panel import *
7-
from tube_helper import *
8-
import utils
6+
from .buddy_panel import *
7+
from .tube_helper import *
8+
from .utils import *
99
import json

mmm_modules/buddy_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import logging
2626

27-
from tube_helper import GAME_IDLE, GAME_STARTED, GAME_FINISHED, GAME_QUIT
27+
from .tube_helper import GAME_IDLE, GAME_STARTED, GAME_FINISHED, GAME_QUIT
2828

2929
#from sugar.graphics.icon import CanvasIcon
3030

mmm_modules/image_category.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import os
2626
from glob import glob
2727
import logging
28-
import md5
28+
import hashlib
2929
from sugar3.activity.activity import Activity, get_bundle_path
30-
from utils import load_image, resize_image, RESIZE_CUT
31-
from borderframe import BorderFrame
30+
from .utils import load_image, resize_image, RESIZE_CUT
31+
from .borderframe import BorderFrame
3232
from gettext import gettext as _
3333

3434
THUMB_SIZE = 48

mmm_modules/timer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
mmmpath = cwd
4545
iconpath = os.path.join(mmmpath, 'icons')
4646

47-
from utils import load_image
47+
from .utils import load_image
4848

4949

5050
class TimerWidget (Gtk.HBox):

mmm_modules/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ def resize_image(pb, width=-1, height=-1, method=RESIZE_CUT):
162162

163163
def trace(func):
164164
def wrapped(*args, **kwargs):
165-
logging.debug("TRACE %s %s %s" % (func.func_name, args, kwargs))
165+
logging.debug("TRACE %s %s %s" % (func.__name__, args, kwargs))
166166
return func(*args, **kwargs)
167167
return wrapped

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
# Copyright (C) 2006, Red Hat, Inc.
44
#

0 commit comments

Comments
 (0)