From 02a2727f8a11784dad9b711b0684ff2f2b261363 Mon Sep 17 00:00:00 2001 From: Pro-Panda Date: Sun, 11 Mar 2018 13:51:11 +0530 Subject: [PATCH] Port to Python3 --- CowBulls.py | 1 + activity.py | 4 ++-- activity/activity.info | 2 +- sugargame/canvas.py | 4 ++-- sugargame/event.py | 4 ++-- utils.py | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CowBulls.py b/CowBulls.py index 6828d3c..78aad11 100644 --- a/CowBulls.py +++ b/CowBulls.py @@ -246,6 +246,7 @@ def change_level(self, level): self.compare_list = [] self.score = 0 self.parent.update_score(self.score) + self.next_button.set_sensitive(False) def nextRound(self): g.screen.fill((0, 0, 0)) diff --git a/activity.py b/activity.py index 60de231..5df6d8d 100644 --- a/activity.py +++ b/activity.py @@ -33,7 +33,7 @@ import CowBulls -class CowBullsActivtiy(activity.Activity): +class CowBullsActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) @@ -153,7 +153,7 @@ def update_score(self, score): def _svg_str_to_pixbuf(self, svg_string): ''' Load pixbuf from SVG string ''' pl = GdkPixbuf.PixbufLoader.new_with_type('svg') - pl.write(svg_string) + pl.write(svg_string.encode()) pl.close() pixbuf = pl.get_pixbuf() return pixbuf diff --git a/activity/activity.info b/activity/activity.info index a2d711f..c4ab30f 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -5,7 +5,7 @@ host_version = 1 bundle_id = org.laptop.community.CowBulls icon = activity show_launcher = yes -exec = sugar-activity activity.CowBullsActivtiy +exec = sugar-activity3 activity.CowBullsActivity license = GPLv3+ category = maths game summary = "CowBulls Math Puzzle game" diff --git a/sugargame/canvas.py b/sugargame/canvas.py index c4324cf..22fce06 100644 --- a/sugargame/canvas.py +++ b/sugargame/canvas.py @@ -4,7 +4,7 @@ from gi.repository import GLib from sugar3.activity.activity import PREVIEW_SIZE import pygame -import event +import sugargame.event as event CANVAS = None @@ -78,7 +78,7 @@ def get_preview(self): _surface = pygame.transform.scale(self._screen, (width, height)) pygame.image.save(_surface, _file_path) - f = open(_file_path, 'r') + f = open(_file_path, 'rb') preview = f.read() f.close() os.remove(_file_path) diff --git a/sugargame/event.py b/sugargame/event.py index 28b716c..0939815 100644 --- a/sugargame/event.py +++ b/sugargame/event.py @@ -139,7 +139,7 @@ def _keyup_cb(self, widget, event): def _keymods(self): mod = 0 - for key_val, mod_val in self.mod_map.iteritems(): + for key_val, mod_val in self.mod_map.items(): mod |= self.__keystate[key_val] and mod_val return mod @@ -168,7 +168,7 @@ def _keyevent(self, widget, event, type): self.__keystate[keycode] = type == pygame.KEYDOWN if type == pygame.KEYUP: mod = self._keymods() - ukey = unichr(Gdk.keyval_to_unicode(event.keyval)) + ukey = chr(Gdk.keyval_to_unicode(event.keyval)) if ukey == '\000': ukey = '' evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod) diff --git a/utils.py b/utils.py index 95cba44..72661c2 100644 --- a/utils.py +++ b/utils.py @@ -47,9 +47,9 @@ def get_num(level): num = [0] while num[0] == 0: if level == 3: - num = random.sample(range(0, 10), 3) + num = random.sample(list(range(0, 10)), 3) else: - num = [random.choice(range(0, 10)) for x in range(level)] + num = [random.choice(list(range(0, 10))) for x in range(level)] return num