From e447f92baa4727b9fa246f2282f68803ee0e0c69 Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Fri, 21 Dec 2012 01:53:07 +0000 Subject: All the files Signed-off-by: Daniel Francis --- (limited to 'activity.py') diff --git a/activity.py b/activity.py index f63e686..e54bbd1 100644 --- a/activity.py +++ b/activity.py @@ -17,7 +17,8 @@ """ import tools -import olpcgames +import sugargame +import sugargame.canvas import pygame from sugar.graphics.radiotoolbutton import RadioToolButton from sugar.graphics.toolbutton import ToolButton @@ -25,6 +26,7 @@ from sugar.activity import activity from gettext import gettext as _ import gtk +import physics try: # >= 0.86 toolbars @@ -36,11 +38,7 @@ except ImportError: pass -class PhysicsActivity(olpcgames.PyGameActivity): - game_name = 'physics' - game_title = _('Physics') - game_size = None # Olpcgame will choose size - +class PhysicsActivity(activity.Activity): def __init__(self, handle): super(PhysicsActivity, self).__init__(handle) self.metadata['mime_type'] = 'application/x-physics-activity' @@ -48,6 +46,17 @@ class PhysicsActivity(olpcgames.PyGameActivity): gtk.gdk.VISIBILITY_NOTIFY_MASK) self.connect('visibility-notify-event', self._focus_event) self.connect('window-state-event', self._window_event) + # Build the Pygame canvas. + self._canvas = sugargame.canvas.PygameCanvas(self) + self.game = physics.main(self) + self.build_toolbar() + + # Note that set_canvas implicitly calls read_file when resuming from the Journal. + self.set_canvas(self._canvas) + + # Start the game running. + self._canvas.run_pygame(self.game.run) + def get_preview(self): """Custom preview code to get image from pygame. @@ -150,8 +159,8 @@ class PhysicsActivity(olpcgames.PyGameActivity): self.radioList[button] = c.name def stop_play_cb(self, button): - pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, - action="stop_start_toggle")) + pygame.event.post(sugargame.eventwrap.Event(pygame.USEREVENT, + action="stop_start_toggle")) self.stop_play_state = not self.stop_play_state # Update button if self.stop_play_state: @@ -162,22 +171,22 @@ class PhysicsActivity(olpcgames.PyGameActivity): self.stop_play.set_tooltip(_("Start")) def radioClicked(self, button): - pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, + pygame.event.post(sugargame.eventwrap.Event(pygame.USEREVENT, action=self.radioList[button])) def _focus_event(self, event, data=None): """Send focus events to pygame to allow it to idle when in background. """ if data.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: - pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, + pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="focus_out")) else: - pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, + pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="focus_in")) def _window_event(self, window, event): """Send focus out event to pygame when switching to a desktop view. """ if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: - pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, + pygame.event.post(pygame.event.Event(pygame.USEREVENT, action="focus_out")) -- cgit v0.9.1