Skip to content

Commit 745691c

Browse files
committed
port to python 3
- Replaced cStringIO with io. - Used hashlib instead of md5, as md5 is no longer available as a standalone module. - Fixed DBus import issues to align with Python 3 changes. - Updated JSON handling by replacing json.write() with json.dumps() for proper serialization. - Modified the exec command for correct execution in Python 3.
1 parent 95aaa6d commit 745691c

File tree

10 files changed

+34
-30
lines changed

10 files changed

+34
-30
lines changed

SliderPuzzleActivity.py

Lines changed: 3 additions & 3 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

SliderPuzzleUI.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# If you find this activity useful or end up using parts of it in one of your
1818
# own creations we would love to hear from you at [email protected] !
1919
#
20+
import gi
21+
gi.require_version('Gtk', '3.0')
2022
from gi.repository import Gtk, GObject, Pango, Gdk
2123

2224
from mamamedia_modules import utils
@@ -38,7 +40,7 @@
3840
from SliderPuzzleWidget import SliderPuzzleWidget
3941
from time import time
4042
import os
41-
import md5
43+
import hashlib
4244
from sugar3.activity.activity import get_bundle_path
4345
from sugar3 import mime
4446
from sugar3.graphics.objectchooser import ObjectChooser
@@ -491,11 +493,11 @@ def _thaw(self, obj):
491493
if not obj[1]['image']:
492494
return
493495

494-
if not obj[1].has_key('image'):
496+
if 'image' not in obj[1]:
495497
self.game.load_image(self.pbb)
496498
self.set_nr_pieces(None, obj[2])
497-
logging.debug(obj[1].keys())
498-
wimg = obj[1].has_key('image')
499+
logging.debug(list(obj[1].keys()))
500+
wimg = 'image' in obj[1]
499501
self.game._thaw(obj[1])
500502
if wimg:
501503
logging.debug("Forcing thumb image from the one in game")

SliderPuzzleWidget.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717
# If you find this activity useful or end up using parts of it in one of your
1818
# own creations we would love to hear from you at [email protected] !
1919
#
20-
20+
import gi
21+
gi.require_version('Gtk', '3.0')
2122
from gi.repository import Gtk, GObject, Pango, GdkPixbuf, Gdk
22-
import md5
23+
import hashlib
2324
import logging
2425
import tempfile
2526
from mamamedia_modules import utils
2627

2728
#from utils import load_image, calculate_matrix, debug, SliderCreator, trace
2829

29-
from types import TupleType, ListType
30+
TupleType = tuple
31+
ListType = list
3032
from random import random
3133
from time import time
3234
from math import sqrt
33-
from cStringIO import StringIO
35+
from io import StringIO
3436
import os
3537

3638
###
@@ -113,7 +115,7 @@ def prepare_stringed(self, rows, cols):
113115
# if c > 0 and r > 0:
114116
# pm.draw_line(gc, px, 0, px, self.height-1)
115117
# pm.draw_line(gc, 0, py, self.width-1, py)
116-
pangolayout.set_text(str(item.next()))
118+
pangolayout.set_text(str(next(item)))
117119
pe = pangolayout.get_pixel_extents()
118120
pe = pe[1][2] / 2, pe[1][3] / 2
119121
pm.draw_layout(gc, px + (sw / 2) -
@@ -194,7 +196,7 @@ def __init__(self, pieces=9, move_cb=None):
194196

195197
def reset(self, pieces=9):
196198
self.pieces, self.rowsize, self.colsize = calculate_matrix(pieces)
197-
pieces_map = range(1, self.pieces + 1)
199+
pieces_map = list(range(1, self.pieces + 1))
198200
self.pieces_map = []
199201
for i in range(self.rowsize):
200202
self.pieces_map.append(
@@ -399,7 +401,7 @@ def _freeze(self):
399401
'pieces_map': self.pieces_map, 'hole_pos_freeze': self.hole_pos._freeze()}
400402

401403
def _thaw(self, obj):
402-
for k in obj.keys():
404+
for k in list(obj.keys()):
403405
if hasattr(self, k):
404406
setattr(self, k, obj[k])
405407
self.hole_pos._thaw(obj.get('hole_pos_freeze', None))
@@ -605,7 +607,7 @@ def _thaw(self, obj):
605607
""" retrieves a frozen status from a python object, as per _freeze """
606608
logging.debug(obj['jumbler'])
607609
self.jumbler._thaw(obj['jumbler'])
608-
if obj.has_key('image') and obj['image'] is not None:
610+
if 'image' in obj and obj['image'] is not None:
609611
self.set_image_from_str(obj['image'])
610612
del obj['image']
611613
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)