Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcgames/gtkEvent.py
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-03-27 13:15:10 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-03-28 18:05:22 (GMT)
commit335ad73456ba3ec8f56811abddcaca4650199db1 (patch)
treedb788baba57c7656c9bdb73eb9003a70dc87d59a /olpcgames/gtkEvent.py
parent6deeb3f569e6c9a1c02a32a011b7a96a58fa8443 (diff)
Save and restore state of the game
Ability to 'save' (when the user closes the Activity) and 'restore' (when the user launch it from the Journal or the Home without holding Alt) the state of the game. For this ability I had to upgrade 'olpcgames' to 1.6 because 'olpcgames.FILE_READ_REQUEST' and 'olpcgames.FILE_WRITE_REQUEST' events are added in that version and those events are needed for this. The data is saved (as JSON, with json module) in the 'event.metadata["state"]' and the timestamp state is saved in 'event.filename'. This commit solves ticket #2393: * http://bugs.sugarlabs.org/ticket/2393 Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
Diffstat (limited to 'olpcgames/gtkEvent.py')
-rw-r--r--olpcgames/gtkEvent.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/olpcgames/gtkEvent.py b/olpcgames/gtkEvent.py
index ce4f9eb..6b20102 100644
--- a/olpcgames/gtkEvent.py
+++ b/olpcgames/gtkEvent.py
@@ -7,7 +7,7 @@ import pygame
from olpcgames import eventwrap
import logging
log = logging.getLogger( 'olpcgames.gtkevent' )
-#log.setLevel( logging.DEBUG )
+##log.setLevel( logging.DEBUG )
class _MockEvent(object):
"""Used to inject key-repeat events on the gtk side."""
@@ -98,13 +98,29 @@ class Translator(object):
self.__tick_id = None
#print "translator initialized"
- mainwindow.connect( 'expose-event', self.do_expose_event )
+ self._inner_evb.connect( 'expose-event', self.do_expose_event )
+# screen = gtk.gdk.screen_get_default()
+# screen.connect( 'size-changed', self.do_resize_event )
+ self._inner_evb.connect( 'configure-event', self.do_resize_event )
def do_expose_event(self, event, widget):
"""Handle exposure event (trigger redraw by gst)"""
log.info( 'Expose event: %s', event )
from olpcgames import eventwrap
eventwrap.post( eventwrap.Event( eventwrap.pygame.VIDEOEXPOSE ))
return True
+ def do_resize_event( self, activity, event ):
+ """Our screen (actually, the default screen) has resized"""
+ log.info( 'Resize event: %s %s', activity, event )
+ log.info( 'Event values: %s', (event.width,event.height) )
+# from olpcgames import eventwrap
+# # shouldn't the activity's window have this information too?
+# eventwrap.post(
+# eventwrap.Event(
+# eventwrap.pygame.VIDEORESIZE,
+# dict(size=(event.width,event.height), width=event.width, height=event.height)
+# )
+# )
+ return False # continue processing
def hook_pygame(self):
"""Hook the various Pygame features so that we implement the event APIs"""
# Pygame should be initialized. Hijack their key and mouse methods
@@ -164,6 +180,9 @@ class Translator(object):
keycode = getattr(pygame, 'K_'+key.upper())
elif hasattr(pygame, 'K_'+key.lower()):
keycode = getattr(pygame, 'K_'+key.lower())
+ elif key == 'XF86Start':
+ # view source request, specially handled...
+ self._mainwindow.view_source()
else:
print 'Key %s unrecognized'%key