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
|
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()
toolbar.share.props.visible = False # hide the share dropdown
# Add buttons
toolbar.box = ToolButton('box')
toolbar.box.set_tooltip(_('Box'))
toolbar.box.connect('clicked', self._box_cb)
toolbar.insert(toolbar.box, 1)
toolbar.box.show()
toolbar.circle = ToolButton('circle')
toolbar.circle.set_tooltip(_('Circle'))
toolbar.circle.connect('clicked', self._circle_cb)
toolbar.insert(toolbar.circle, 1)
toolbar.circle.show()
toolbar.triangle = ToolButton('triangle')
toolbar.triangle.set_tooltip(_('Triangle'))
toolbar.triangle.connect('clicked', self._triangle_cb)
toolbar.insert(toolbar.triangle, 1)
toolbar.triangle.show()
toolbar.polygon = ToolButton('polygon')
toolbar.polygon.set_tooltip(_('Polygon'))
toolbar.polygon.connect('clicked', self._polygon_cb)
toolbar.insert(toolbar.polygon, 1)
toolbar.polygon.show()
toolbar.magicpen = ToolButton('magicpen')
toolbar.magicpen.set_tooltip(_('Magic Pen'))
toolbar.magicpen.connect('clicked', self._magicpen_cb)
toolbar.insert(toolbar.magicpen, 1)
toolbar.magicpen.show()
toolbar.grab = ToolButton('grab')
toolbar.grab.set_tooltip(_('Grab'))
toolbar.grab.connect('clicked', self._grab_cb)
toolbar.insert(toolbar.grab, 1)
toolbar.grab.show()
toolbar.joint = ToolButton('joint')
toolbar.joint.set_tooltip(_('Joint'))
toolbar.joint.connect('clicked', self._joint_cb)
toolbar.insert(toolbar.joint, 1)
toolbar.joint.show()
toolbar.destroy = ToolButton('destroy')
toolbar.destroy.set_tooltip(_('Destroy'))
toolbar.destroy.connect('clicked', self._destroy_cb)
toolbar.insert(toolbar.destroy, 1)
toolbar.destroy.show()
return toolbar
def _box_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='box'))
def _circle_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='circle'))
def _triangle_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='triangle'))
def _polygon_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='polygon'))
def _magicpen_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='magicpen'))
def _grab_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='grab'))
def _joint_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='joint'))
def _destroy_cb(self, button):
pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='destroy'))
|