From 6be1dada2fde0e8e06220c9c509338c350123f0d Mon Sep 17 00:00:00 2001 From: Gary Martin Date: Wed, 06 Oct 2010 17:56:32 +0000 Subject: Watch for focus events so that pygame run loop is more gracefully idle when in background. --- (limited to 'activity.py') 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")) -- cgit v0.9.1