diff options
author | Thorin <toz@thorin-kerrs-macbook-3.local> | 2010-03-19 03:51:27 (GMT) |
---|---|---|
committer | Thorin <toz@thorin-kerrs-macbook-3.local> | 2010-03-19 03:51:27 (GMT) |
commit | 76ca747b364bbfa06bf0869f7e62df2947672d48 (patch) | |
tree | 8e8dea41a08bf99af0a98dcf82e8ddcc5f95098f /activity.py |
Create repository and load
Diffstat (limited to 'activity.py')
-rwxr-xr-x | activity.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/activity.py b/activity.py new file mode 100755 index 0000000..bba8d80 --- /dev/null +++ b/activity.py @@ -0,0 +1,86 @@ +import pygame +import olpcgames +from sugar.graphics.toolbutton import ToolButton +import sugar.activity +from sugar.activity.activity import Activity, ActivityToolbox +from olpcgames import activity +from J2JToolbar import Jam2JamToolBar + +from gettext import gettext as _ +import logging, os +log = logging.getLogger( 'City run' ) +log.setLevel( logging.DEBUG ) + +log.info( """ LOG From activity.py!!""") + +from olpcgames import mesh, util + +class Activity(activity.PyGameActivity): + """Your Sugar activity""" + game_name = 'run:main' + game_title = _('Jam2Jam') + game_size = None + _ScenePath = (os.path.dirname(os.path.abspath(__file__)) + "/City/Scenes") + + def __init__(self, handle): + activity.PyGameActivity.__init__(self, handle) + self.snap_store = [] + self.cameras_loaded = [] + self.playArea = None + self.jamScene = None + + def load_image(self, picpath): + picsurf = pygame.image.load(picpath) + picsurf = picsurf.convert() + picsurfwidth = picsurf.get_width() + destwidth = self.playArea.width + scale = float(destwidth) / picsurfwidth + newarea = (picsurfwidth * scale, picsurf.get_height() * scale) + picsurf = pygame.transform.scale(picsurf, newarea) + self.snap_store.append(picsurf) + + + def build_toolbar(self): + log.info ("building toolbar") + toolbox = ActivityToolbox(self) + #remove the 'keep' button. We've no need to save data at the moment. + activityToolbar = toolbox.get_activity_toolbar() + activityToolbar.keep.props.visible = False + self.J2JToolbar = Jam2JamToolBar(self) + toolbox.add_toolbar("Transform", self.J2JToolbar) + self.set_toolbox(toolbox) + self.J2JToolbar.show() + toolbox.show() + self.toolbox.set_current_toolbar(1) + def shared_cb(*args, **kwargs): + log.info( 'Shared CB: %s, %s', args, kwargs ) + try: + mesh.activity_shared(self) + except Exception, err: + log.error( """Failure signaling activity sharing to mesh module: %s""", util.get_traceback(err) ) + else: + log.info( 'mesh activity shared message sent, trying to grab focus' ) + try: + self._pgc.grab_focus() + except Exception, err: + log.warn( 'Focus failed: %s', err ) + else: + log.info( 'asserting focus' ) + assert self._pgc.is_focus(), """Did not successfully set pygame canvas focus""" + sharermessage = "Shared:StartBeat" + olpcgames.eventwrap.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action=sharermessage)) + log.info( 'callback finished' ) + def joined_cb(*args, **kwargs): + log.info( 'joined CB: %s, %s', args, kwargs ) + mesh.activity_joined(self) + self._pgc.grab_focus() + joinedmessage = "Joined:CeasePlayer" + olpcgames.eventwrap.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action=joinedmessage)) + self.connect("shared", shared_cb) + self.connect("joined", joined_cb) + if self.get_shared(): + joined_cb() + log.info ("FINISHED building toolbar") + return toolbox + + |