Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2009-10-29 03:33:07 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2009-10-29 03:33:07 (GMT)
commite245a2fbca067dee091ae27c78cad063bd3ffbec (patch)
tree6a285e9563552afa5f6b989092388202d424036d /activity.py
parent3c152182fe74f379f2052d101ebef80c295e2353 (diff)
Replaced olpcgames with new sugargame module.pygame-testing
Sugargame is vastly simpler and cleaner than olpcgames, and integrates GTK and Pygame more elegantly. Some olpcgames features are still missing and there are likely bugs.
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py71
1 files changed, 42 insertions, 29 deletions
diff --git a/activity.py b/activity.py
index 2256d2c..be85085 100644
--- a/activity.py
+++ b/activity.py
@@ -1,34 +1,35 @@
-import tools
-import olpcgames
-import pygame
-from sugar.graphics.radiotoolbutton import RadioToolButton
-from sugar.graphics.toolbutton import ToolButton
-from sugar.activity import activity
from gettext import gettext as _
+
import gtk
-class PhysicsActivity(olpcgames.PyGameActivity):
- game_name = 'physics'
- game_title = _('Physics')
- game_size = None # olpcgame will choose size
-
+from sugar.activity import activity
+from sugar.graphics.radiotoolbutton import RadioToolButton
+from sugar.graphics.toolbutton import ToolButton
+
+import sugargame.activity
+
+import physics
+import tools
+
+class PhysicsActivity(sugargame.activity.PygameActivity):
def __init__(self, handle):
super(PhysicsActivity, self).__init__(handle)
+
self.metadata['mime_type'] = 'application/x-physics-activity'
+
+ self._resume_path = None
+
+ self.build_toolbar()
+ self.build_canvas()
- def write_file(self, file_path):
- """Over-ride olpcgames write_file so that title keeps working.
- """
- event = olpcgames.eventwrap.Event(
- type = pygame.USEREVENT,
- code = olpcgames.FILE_WRITE_REQUEST,
- filename = file_path,
- metadata = self.metadata)
- olpcgames.eventwrap.post(event)
- event.block()
- event.retire() # <- without this, title editing stops updating
+ self.game = physics.PhysicsGame(self.get_pygame_screen())
+ if self._resume_path:
+ self.read_file(self._resume_path)
+ self.run_pygame(self.run)
- # setup the toolbar
+ def run(self):
+ self.game.run()
+
def build_toolbar(self):
# make a toolbox
toolbox = activity.ActivityToolbox(self)
@@ -37,6 +38,7 @@ class PhysicsActivity(olpcgames.PyGameActivity):
activity_toolbar = toolbox.get_activity_toolbar()
activity_toolbar.share.props.visible = False
self.blocklist = []
+
# make a 'create' toolbar
create_toolbar = gtk.Toolbar()
@@ -65,13 +67,13 @@ class PhysicsActivity(olpcgames.PyGameActivity):
firstButton = button
button.set_tooltip(c.toolTip)
button.set_accelerator(c.toolAccelerator)
- button.connect('clicked',self.radioClicked)
+ button.connect('clicked',self.radio_clicked_cb)
create_toolbar.insert(button,-1)
button.show()
self.radioList[button] = c.name
# add the toolbars to the toolbox
- toolbox.add_toolbar(_("Create"),create_toolbar)
+ toolbox.add_toolbar(_("Create"), create_toolbar)
create_toolbar.show()
toolbox.show()
@@ -80,7 +82,7 @@ class PhysicsActivity(olpcgames.PyGameActivity):
return activity_toolbar
def stop_play_cb(self, button):
- pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action="stop_start_toggle"))
+ self.game.stop_start_toggle()
self.stop_play_state = not self.stop_play_state
# Update button
if self.stop_play_state:
@@ -89,6 +91,17 @@ class PhysicsActivity(olpcgames.PyGameActivity):
else:
self.stop_play.set_icon('media-playback-start')
self.stop_play.set_tooltip(_("Start"))
-
- def radioClicked(self,button):
- pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action=self.radioList[button])) \ No newline at end of file
+
+ def radio_clicked_cb(self,button):
+ self.game.set_tool(self.radioList[button])
+
+ def read_file(self, file_path):
+ # Read file is called before the constructor returns when game is not yet valid.
+ # Caching the file path seems to work in this specific instance.
+ if not self.game:
+ self._resume_path = file_path
+ else:
+ self.game.read_file(file_path)
+
+ def write_file(self, file_path):
+ self.game.write_file(file_path)