Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: 63b031aa6e2b36bcb3c60ce2bd5085245e901601 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#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