Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2010-06-27 17:18:58 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2010-06-27 17:18:58 (GMT)
commitd3f13b941ac97695fdf83efb272f41f468c88bf7 (patch)
tree6a894df59b58aa27ac3c58c6bed89ad48be29213
parenta330a055320aad2c726243e39a0bb9bfe7f71f6f (diff)
Fixes for event handling issues. Also clean up the test activity slightly.
-rw-r--r--sugargame/canvas.py14
-rw-r--r--sugargame/event.py6
-rw-r--r--test/TestActivity.py4
3 files changed, 16 insertions, 8 deletions
diff --git a/sugargame/canvas.py b/sugargame/canvas.py
index cf99a13..980cb73 100644
--- a/sugargame/canvas.py
+++ b/sugargame/canvas.py
@@ -7,13 +7,20 @@ import event
CANVAS = None
class PygameCanvas(gtk.EventBox):
- def __init__(self, mainwindow):
+
+ """
+ mainwindow is the activity intself.
+ """
+ def __init__(self, mainwindow, pointer_hint = True):
gtk.EventBox.__init__(self)
global CANVAS
assert CANVAS == None, "Only one PygameCanvas can be created, ever."
CANVAS = self
+ # Initialize Events translator before widget gets "realized".
+ self.translator = event.Translator(mainwindow, self)
+
self._mainwindow = mainwindow
self.set_flags(gtk.CAN_FOCUS)
@@ -38,15 +45,14 @@ class PygameCanvas(gtk.EventBox):
pygame.init()
# Restore the default cursor.
- self._socket.get_window().set_cursor(None)
+ self._socket.window.set_cursor(None)
# Initialize the Pygame window.
r = self.get_allocation()
pygame.display.set_mode((r.width, r.height), pygame.RESIZABLE)
# Hook certain Pygame functions with GTK equivalents.
- translator = event.Translator(self._mainwindow, self)
- translator.hook_pygame()
+ self.translator.hook_pygame()
# Run the Pygame main loop.
main_fn()
diff --git a/sugargame/event.py b/sugargame/event.py
index 52ca4ab..4cc3be8 100644
--- a/sugargame/event.py
+++ b/sugargame/event.py
@@ -44,7 +44,8 @@ class Translator(object):
self._inner_evb = inner_evb
# Enable events
- self._mainwindow.set_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 \
)
@@ -88,7 +89,8 @@ class Translator(object):
pygame.mouse.get_pos = self._get_mouse_pos
def _expose_cb(self, event, widget):
- pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE))
+ if pygame.display.get_init():
+ pygame.event.post(pygame.event.Event(pygame.VIDEOEXPOSE))
return True
def _resize_cb(self, widget, event):
diff --git a/test/TestActivity.py b/test/TestActivity.py
index ccc0e35..fcd4262 100644
--- a/test/TestActivity.py
+++ b/test/TestActivity.py
@@ -26,10 +26,11 @@ class TestActivity(sugar.activity.activity.Activity):
# Build the Pygame canvas.
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
+
# Note that set_canvas implicitly calls read_file when resuming from the Journal.
self.set_canvas(self._pygamecanvas)
- # Start the game running.
+ # Start the game running (self.game.run is called when the activity constructor returns).
self._pygamecanvas.run_pygame(self.game.run)
def build_toolbar(self):
@@ -40,7 +41,6 @@ class TestActivity(sugar.activity.activity.Activity):
toolbar = gtk.Toolbar()
toolbar.insert(stop_play, 0)
- toolbar.insert(gtk.SeparatorToolItem(), 1)
toolbox = sugar.activity.activity.ActivityToolbox(self)
toolbox.add_toolbar(_("Pygame"), toolbar)