diff options
author | Gary Martin <gary@garycmartin.com> | 2010-10-06 17:56:32 (GMT) |
---|---|---|
committer | Gary Martin <gary@garycmartin.com> | 2010-10-06 17:56:32 (GMT) |
commit | 6be1dada2fde0e8e06220c9c509338c350123f0d (patch) | |
tree | 11843e9e6241b55e9b2666b9f46d7b851f0932e4 /activity.py | |
parent | a45bd81c6e7bf30d7c598c291578960a2f9b2db8 (diff) |
Watch for focus events so that pygame run loop is more gracefully idle when in background.
Diffstat (limited to 'activity.py')
-rw-r--r-- | activity.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/activity.py b/activity.py index bf6ac0f..a718257 100644 --- a/activity.py +++ b/activity.py @@ -44,6 +44,7 @@ class PhysicsActivity(olpcgames.PyGameActivity): def __init__(self, handle): super(PhysicsActivity, self).__init__(handle) self.metadata['mime_type'] = 'application/x-physics-activity' + self.connect('visibility-notify-event', self._focus_event) def get_preview(self): """Custom preview code to get image from pygame. @@ -173,3 +174,10 @@ class PhysicsActivity(olpcgames.PyGameActivity): pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action=self.radioList[button])) + def _focus_event(self, event, data=None): + """Send focus events to pygame to allow it to more gracefully idle when in the background. + """ + if data.state == gtk.gdk.VISIBILITY_FULLY_OBSCURED: + pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action="focus_out")) + else: + pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action="focus_in")) |