[Sugar-devel] [PATCH 3/6] Run pygi-convert.sh script for GTK+3 port

Manuel Quiñones manuq at laptop.org
Mon May 14 15:51:56 EDT 2012


Activity will not start in this commit.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 sugargame/canvas.py  |   14 +++++++-------
 sugargame/event.py   |   38 +++++++++++++++++++-------------------
 test/TestActivity.py |    4 ++--
 test/TestGame.py     |    6 +++---
 4 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/sugargame/canvas.py b/sugargame/canvas.py
index 980cb73..d070a96 100644
--- a/sugargame/canvas.py
+++ b/sugargame/canvas.py
@@ -1,18 +1,18 @@
 import os
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
 import pygame
 import event
 
 CANVAS = None
 
-class PygameCanvas(gtk.EventBox):
+class PygameCanvas(Gtk.EventBox):
     
     """
     mainwindow is the activity intself.
     """
     def __init__(self, mainwindow, pointer_hint = True):
-        gtk.EventBox.__init__(self)
+        GObject.GObject.__init__(self)
 
         global CANVAS
         assert CANVAS == None, "Only one PygameCanvas can be created, ever."
@@ -23,9 +23,9 @@ class PygameCanvas(gtk.EventBox):
         
         self._mainwindow = mainwindow
 
-        self.set_flags(gtk.CAN_FOCUS)
+        self.set_flags(Gtk.CAN_FOCUS)
         
-        self._socket = gtk.Socket()
+        self._socket = Gtk.Socket()
         self.add(self._socket)
         self.show_all()
 
@@ -34,7 +34,7 @@ class PygameCanvas(gtk.EventBox):
         # Sugar activity is not properly created until after its constructor returns.
         # If the Pygame main loop is called from the activity constructor, the 
         # constructor never returns and the activity freezes.
-        gobject.idle_add(self._run_pygame_cb, main_fn)
+        GObject.idle_add(self._run_pygame_cb, main_fn)
 
     def _run_pygame_cb(self, main_fn):
         assert pygame.display.get_surface() is None, "PygameCanvas.run_pygame can only be called once."
diff --git a/sugargame/event.py b/sugargame/event.py
index 4cc3be8..0aeee50 100644
--- a/sugargame/event.py
+++ b/sugargame/event.py
@@ -1,5 +1,5 @@
-import gtk
-import gobject
+from gi.repository import Gtk
+from gi.repository import GObject
 import pygame
 import pygame.event
 import logging 
@@ -46,20 +46,20 @@ class Translator(object):
         # Enable events
         # (add instead of set here because the main window is already realized)
         self._mainwindow.add_events(
-            gtk.gdk.KEY_PRESS_MASK | \
-            gtk.gdk.KEY_RELEASE_MASK \
+            Gdk.EventMask.KEY_PRESS_MASK | \
+            Gdk.EventMask.KEY_RELEASE_MASK \
         )
         
         self._inner_evb.set_events(
-            gtk.gdk.POINTER_MOTION_MASK | \
-            gtk.gdk.POINTER_MOTION_HINT_MASK | \
-            gtk.gdk.BUTTON_MOTION_MASK | \
-            gtk.gdk.BUTTON_PRESS_MASK | \
-            gtk.gdk.BUTTON_RELEASE_MASK 
+            Gdk.EventMask.POINTER_MOTION_MASK | \
+            Gdk.EventMask.POINTER_MOTION_HINT_MASK | \
+            Gdk.EventMask.BUTTON_MOTION_MASK | \
+            Gdk.EventMask.BUTTON_PRESS_MASK | \
+            Gdk.EventMask.BUTTON_RELEASE_MASK 
         )
 
-        self._mainwindow.set_flags(gtk.CAN_FOCUS)
-        self._inner_evb.set_flags(gtk.CAN_FOCUS)
+        self._mainwindow.set_flags(Gtk.CAN_FOCUS)
+        self._inner_evb.set_flags(Gtk.CAN_FOCUS)
         
         # Callback functions to link the event systems
         self._mainwindow.connect('unrealize', self._quit_cb)
@@ -133,7 +133,7 @@ class Translator(object):
         return mod
         
     def _keyevent(self, widget, event, type):
-        key = gtk.gdk.keyval_name(event.keyval)
+        key = Gdk.keyval_name(event.keyval)
         if key is None:
             # No idea what this key is.
             return False 
@@ -157,7 +157,7 @@ class Translator(object):
             self.__keystate[keycode] = type == pygame.KEYDOWN
             if type == pygame.KEYUP:
                 mod = self._keymods()
-            ukey = unichr(gtk.gdk.keyval_to_unicode(event.keyval))
+            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
             if ukey == '\000':
                 ukey = ''
             evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
@@ -193,15 +193,15 @@ class Translator(object):
         else:
             x = event.x
             y = event.y
-            state = event.state
+            state = event.get_state()
 
         rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1])
         self.__mouse_pos = (x, y)
         
         self.__button_state = [
-            state & gtk.gdk.BUTTON1_MASK and 1 or 0,
-            state & gtk.gdk.BUTTON2_MASK and 1 or 0,
-            state & gtk.gdk.BUTTON3_MASK and 1 or 0,
+            state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0,
+            state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0,
+            state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0,
         ]
         
         evt = pygame.event.Event(pygame.MOUSEMOTION,
@@ -224,9 +224,9 @@ class Translator(object):
         
     def _set_repeat(self, delay=None, interval=None):
         if delay is not None and self.__repeat[0] is None:
-            self.__tick_id = gobject.timeout_add(10, self._tick_cb)
+            self.__tick_id = GObject.timeout_add(10, self._tick_cb)
         elif delay is None and self.__repeat[0] is not None:
-            gobject.source_remove(self.__tick_id)
+            GObject.source_remove(self.__tick_id)
         self.__repeat = (delay, interval)
         
     def _get_mouse_pos(self):
diff --git a/test/TestActivity.py b/test/TestActivity.py
index 28c6f33..4670873 100644
--- a/test/TestActivity.py
+++ b/test/TestActivity.py
@@ -1,7 +1,7 @@
 from gettext import gettext as _
 
 import sys
-import gtk
+from gi.repository import Gtk
 import pygame
 
 import sugar.activity.activity
@@ -58,7 +58,7 @@ class TestActivity(sugar.activity.activity.Activity):
 
         # Blank space (separator) and Stop button at the end:
 
-        separator = gtk.SeparatorToolItem()
+        separator = Gtk.SeparatorToolItem()
         separator.props.draw = False
         separator.set_expand(True)
         toolbar_box.toolbar.insert(separator, -1)
diff --git a/test/TestGame.py b/test/TestGame.py
index d9dbc2e..7827cbf 100755
--- a/test/TestGame.py
+++ b/test/TestGame.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 import pygame
-import gtk
+from gi.repository import Gtk
 
 class TestGame:
     def __init__(self):
@@ -34,8 +34,8 @@ class TestGame:
 
         while self.running:
             # Pump GTK messages.
-            while gtk.events_pending():
-                gtk.main_iteration()
+            while Gtk.events_pending():
+                Gtk.main_iteration()
 
             # Pump PyGame messages.
             for event in pygame.event.get():
-- 
1.7.7.6



More information about the Sugar-devel mailing list