#This python module is part of the Jam2Jam XO Activity, March, 2010 # #Copyright (C) 2010 Thorin Kerr & Andrew Brown # #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation; either version 2 of the License, or any #later version. # #This program is distributed in the hope that it will be useful, but #WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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