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
|
#!/usr/bin/python
"""
This file is part of the 'Bridge' Project
Code: http://git.sugarlabs.org/bridge
git clone git://git.sugarlabs.org/bridge/mainline.git
This activity is built on:
Physics is a 2D Physics Playground for Kids (supporting Box2D2)
Physics Copyright (C) 2008, Alex Levenson, Brian Jordan
Elements Copyright (C) 2008, The Elements Team, <elements@linuxuser.at>
Wiki: http://wiki.laptop.org/wiki/Bridge
Code: http://git.sugarlabs.org/physics
git clone git://git.sugarlabs.org/physics/mainline.git
License: GPLv3 http://gplv3.fsf.org/
"""
# tools provides the buttons for the toolbar
import tools
# provides all of the code to implement a game activity
import olpcgames
import pygame
# provides the classes from sugar
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.activity import activity
# The following import is used for translation of strings to native languages
from gettext import gettext as _
import gtk
class BridgeActivity(olpcgames.PyGameActivity):
"""
This class is the instance of the activity.
It actually does very little itself. The game_name variable
specifies that physics.py has the majority of the activity code.
game_size specifies the screen size, but in this case None allows
the software to set itself to full screen.
The other thing that this code does is set up the toolbar across
the top of the activity.
The tools are things like the bridge girder, joint, grab, and destroy;
all of these are used in the gameplay.
"""
game_name = 'physics'
game_title = 'Bridge'
game_size = None # olpcgame will choose size
def __init__(self):
self.blocklist = []
self.radiolist = {}
# setup the toolbar
def build_toolbar(self):
"""build_toolbar gets the activity toolbar and inserts
icons for each tool in the tools package, which is a part
of the bridge activity.
"""
# make a toolbox
toolbox = activity.ActivityToolbox(self)
# modify the Activity tab
activity_toolbar = toolbox.get_activity_toolbar()
activity_toolbar.share.props.visible = False
self.blocklist = []
# make a 'create' toolbar
create_toolbar = gtk.Toolbar()
# make + add the component buttons
self.radiolist = {}
for tool in tools.ALLTOOLS:
button = RadioToolButton(named_icon=tool.icon)
button.set_tooltip(_(tool.toolTip))
button.connect('clicked', self.radioclicked)
create_toolbar.insert(button, -1)
button.show()
self.radiolist[button] = tool.name
# add the toolbars to the toolbox
toolbox.add_toolbar("Create", create_toolbar)
create_toolbar.show()
toolbox.show()
self.set_toolbox(toolbox)
toolbox.set_current_toolbar(1)
return activity_toolbar
def radioclicked(self, button):
"""radioclicked is an event handler for a tool button click.
It is connected to the buttons in build_toolbar above.
"""
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT,
action=self.radiolist[button]))
|