From 95d395e27a129fcec35057a76b68f6bf613ed472 Mon Sep 17 00:00:00 2001 From: Gary Martin Date: Sun, 23 Aug 2009 18:51:18 +0000 Subject: Use a user event for stop/start rather than injecting a key event. --- diff --git a/activity.py b/activity.py index eafb155..b7f0d33 100644 --- a/activity.py +++ b/activity.py @@ -68,7 +68,7 @@ class PhysicsActivity(olpcgames.PyGameActivity): return activity_toolbar def stop_play_cb(self, button): - pygame.event.post(olpcgames.eventwrap.Event(pygame.KEYDOWN, key=pygame.K_SPACE)) + pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action="stop_start_toggle")) self.stop_play_state = not self.stop_play_state # Update button if self.stop_play_state: diff --git a/tools.py b/tools.py index 136896b..c768da2 100644 --- a/tools.py +++ b/tools.py @@ -26,20 +26,19 @@ class Tool(object): if event.type == QUIT: # bye bye! Hope you had fun! self.game.running = False - elif event.type == KEYDOWN: - if event.key == K_SPACE: - #space pauses - self.game.world.run_physics = not self.game.world.run_physics - elif event.type == USEREVENT: if hasattr(event,"action"): - if self.game.toolList.has_key(event.action): self.game.setTool(event.action) - if hasattr(event,"code"): + if event.action == "stop_start_toggle": + # stop/start simulation + self.game.world.run_physics = not self.game.world.run_physics + elif self.game.toolList.has_key(event.action): + self.game.setTool(event.action) + elif hasattr(event,"code"): if event.code == olpcgames.FILE_WRITE_REQUEST: #saving to journal self.game.world.add.remove_mouseJoint() self.game.world.json_save(event.filename) - if event.code == olpcgames.FILE_READ_REQUEST: + elif event.code == olpcgames.FILE_READ_REQUEST: #loading from journal self.game.world.json_load(event.filename) elif event.type == MOUSEBUTTONDOWN and event.button == 1: -- cgit v0.9.1