Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: 84fcc87a093381d64e6eb22cd4b9e3a64a9cb1ac (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
import olpcgames
import pygame
from sugar.graphics.toolbutton import ToolButton
from gettext import gettext as _

class PhysicsActivity(olpcgames.PyGameActivity):
    game_name = 'physics'
    game_title = 'Physics'
    game_size = None # olpcgame will choose size

    # custom toolbar
    def build_toolbar(self):
        toolbar = super(PhysicsActivity, self).build_toolbar()
        
        # Add buttons
        toolbar.button1 = ToolButton('activity-minus')
        toolbar.button1.set_tooltip(_('Button One'))
        toolbar.button1.connect('clicked', self._button1_cb)
        toolbar.insert(toolbar.button1, 2)
        toolbar.button1.show()
        
        toolbar.button2 = ToolButton('activity-plus')
        toolbar.button2.set_tooltip(_('button-2'))
        toolbar.button2.connect('clicked', self._button2_cb)
        toolbar.insert(toolbar.button2, 2)
        toolbar.button2.show()
        return toolbar

    def _button1_cb(self, button):
        pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='button1'))
        
    def _button2_cb(self, button):
        pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='button2'))