[Sugar-devel] [PATCH 4/6] Port to sugar-toolkit-gtk3

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


- changed sugar imports to sugar3
- changed set_flags(Gtk.CAN_FOCUS) to set_can_focus(True)
- changed GtkWindow 'expose-event' to 'draw'
- commented the pointer movement because is not working

The test activity is running now.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 sugargame/canvas.py  |    4 ++--
 sugargame/event.py   |   30 ++++++++++++++++++------------
 test/TestActivity.py |   12 ++++++------
 test/setup.py        |    2 +-
 4 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/sugargame/canvas.py b/sugargame/canvas.py
index d070a96..1ce0250 100644
--- a/sugargame/canvas.py
+++ b/sugargame/canvas.py
@@ -23,7 +23,7 @@ class PygameCanvas(Gtk.EventBox):
         
         self._mainwindow = mainwindow
 
-        self.set_flags(Gtk.CAN_FOCUS)
+        self.set_can_focus(True)
         
         self._socket = Gtk.Socket()
         self.add(self._socket)
@@ -45,7 +45,7 @@ class PygameCanvas(Gtk.EventBox):
         pygame.init()
         
         # Restore the default cursor.
-        self._socket.window.set_cursor(None)
+        self._socket.props.window.set_cursor(None)
 
         # Initialize the Pygame window.
         r = self.get_allocation()
diff --git a/sugargame/event.py b/sugargame/event.py
index 0aeee50..dd31924 100644
--- a/sugargame/event.py
+++ b/sugargame/event.py
@@ -1,4 +1,5 @@
 from gi.repository import Gtk
+from gi.repository import Gdk
 from gi.repository import GObject
 import pygame
 import pygame.event
@@ -58,8 +59,8 @@ class Translator(object):
             Gdk.EventMask.BUTTON_RELEASE_MASK 
         )
 
-        self._mainwindow.set_flags(Gtk.CAN_FOCUS)
-        self._inner_evb.set_flags(Gtk.CAN_FOCUS)
+        self._mainwindow.set_can_focus(True)
+        self._inner_evb.set_can_focus(True)
         
         # Callback functions to link the event systems
         self._mainwindow.connect('unrealize', self._quit_cb)
@@ -68,7 +69,7 @@ class Translator(object):
         self._inner_evb.connect('button_press_event', self._mousedown_cb)
         self._inner_evb.connect('button_release_event', self._mouseup_cb)
         self._inner_evb.connect('motion-notify-event', self._mousemove_cb)
-        self._inner_evb.connect('expose-event', self._expose_cb)
+        self._inner_evb.connect('draw', self._expose_cb)
         self._inner_evb.connect('configure-event', self._resize_cb)
         
         # Internal data
@@ -185,15 +186,20 @@ class Translator(object):
         return True
         
     def _mousemove_cb(self, widget, event):
-        # From http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
-        # if this is a hint, then let's get all the necessary 
-        # information, if not it's all we need.
-        if event.is_hint:
-            x, y, state = event.window.get_pointer()
-        else:
-            x = event.x
-            y = event.y
-            state = event.get_state()
+        # FIXME, GdkWindow.get_pointer() is not returning the right values
+
+        # # From http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
+        # # if this is a hint, then let's get all the necessary 
+        # # information, if not it's all we need.
+        # if event.is_hint:
+        #     x, y, state = event.window.get_pointer()
+        # else:
+        #     x = event.x
+        #     y = event.y
+        #     state = event.get_state()
+        x = event.x
+        y = event.y
+        state = event.get_state()
 
         rel = (x - self.__mouse_pos[0], y - self.__mouse_pos[1])
         self.__mouse_pos = (x, y)
diff --git a/test/TestActivity.py b/test/TestActivity.py
index 4670873..d7c1695 100644
--- a/test/TestActivity.py
+++ b/test/TestActivity.py
@@ -4,11 +4,11 @@ import sys
 from gi.repository import Gtk
 import pygame
 
-import sugar.activity.activity
-from sugar.graphics.toolbarbox import ToolbarBox
-from sugar.activity.widgets import ActivityToolbarButton
-from sugar.graphics.toolbutton import ToolButton
-from sugar.activity.widgets import StopButton
+import sugar3.activity.activity
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.activity.widgets import ActivityToolbarButton
+from sugar3.graphics.toolbutton import ToolButton
+from sugar3.activity.widgets import StopButton
 
 
 sys.path.append('..') # Import sugargame package from top directory.
@@ -16,7 +16,7 @@ import sugargame.canvas
 
 import TestGame
 
-class TestActivity(sugar.activity.activity.Activity):
+class TestActivity(sugar3.activity.activity.Activity):
     def __init__(self, handle):
         super(TestActivity, self).__init__(handle)
         
diff --git a/test/setup.py b/test/setup.py
index 6ed89aa..d290fe6 100755
--- a/test/setup.py
+++ b/test/setup.py
@@ -1,4 +1,4 @@
 #!/usr/bin/env python
-from sugar.activity import bundlebuilder
+from sugar3.activity import bundlebuilder
 bundlebuilder.start()
 
-- 
1.7.7.6



More information about the Sugar-devel mailing list