Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorAlex Levenson <alexlevenson@laptop.org>2008-07-16 16:35:17 (GMT)
committer Alex Levenson <alexlevenson@laptop.org>2008-07-16 16:35:17 (GMT)
commitc4d15dae7b5163d0397a14d33f80b3bd8383ae7f (patch)
tree7ad81ae2c543c044666258caceb1b3604e7ba4cd /activity.py
parent86439036069b5e35c8dc89235f95631e0a382494 (diff)
Automated toolbar -- not perfect yet
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py89
1 files changed, 17 insertions, 72 deletions
diff --git a/activity.py b/activity.py
index a052605..1d0cda7 100644
--- a/activity.py
+++ b/activity.py
@@ -1,3 +1,4 @@
+import tools
import olpcgames
import pygame
from sugar.graphics.radiotoolbutton import RadioToolButton
@@ -21,54 +22,21 @@ class PhysicsActivity(olpcgames.PyGameActivity):
self.blocklist = []
# make a 'create' toolbar
create_toolbar = gtk.Toolbar()
- # make + add the creation buttons
- self.box = RadioToolButton(named_icon='box')
- self.box.set_tooltip(_("Box"))
- self.blocklist[len(self.blocklist):] = [self.box.connect('clicked',self._box_cb)]
- create_toolbar.insert(self.box,-1)
- self.box.show()
-
- self.circle = RadioToolButton(group=self.box, named_icon='circle')
- self.circle.set_tooltip(_("Circle"))
- self.circle.connect('clicked',self._circle_cb)
- create_toolbar.insert(self.circle,-1)
- self.circle.show()
-
- self.triangle = RadioToolButton(group=self.box, named_icon='triangle')
- self.triangle.set_tooltip(_("Triangle"))
- self.triangle.connect('clicked',self._triangle_cb)
- create_toolbar.insert(self.triangle,-1)
- self.triangle.show()
-
- self.polygon = RadioToolButton(group=self.box, named_icon='polygon')
- self.polygon.set_tooltip(_("Polygon"))
- self.polygon.connect('clicked',self._polygon_cb)
- create_toolbar.insert(self.polygon,-1)
- self.polygon.show()
-
- self.magicpen = RadioToolButton(group=self.box, named_icon='magicpen')
- self.magicpen.set_tooltip(_("Magic Pen"))
- self.magicpen.connect('clicked',self._magicpen_cb)
- create_toolbar.insert(self.magicpen,-1)
- self.magicpen.show()
- self.grab = RadioToolButton(group=self.box, named_icon='grab')
- self.grab.set_tooltip(_("Grab"))
- self.grab.connect('clicked',self._grab_cb)
- create_toolbar.insert(self.grab,-1)
- self.grab.show()
-
- self.joint = RadioToolButton(group=self.box, named_icon='joint')
- self.joint.set_tooltip(_("Joint"))
- self.joint.connect('clicked',self._joint_cb)
- create_toolbar.insert(self.joint,-1)
- self.joint.show()
-
- self.destroy = RadioToolButton(group=self.box, named_icon='destroy')
- self.destroy.set_tooltip(_("Destroy"))
- self.destroy.connect('clicked',self._destroy_cb)
- create_toolbar.insert(self.destroy,-1)
- self.destroy.show()
+ # get a list of all component classes
+ componentsList = tools.local_classes
+ componentsList.remove(tools.Tool)
+ #hack (For now)
+ componentsList.remove(pygame.Rect)
+ # make + add the component buttons
+ self.radioList = {}
+ for c in componentsList:
+ button = RadioToolButton(named_icon=c.icon)
+ button.set_tooltip(_(c.toolTip))
+ button.connect('clicked',self.radioClicked)
+ create_toolbar.insert(button,-1)
+ button.show()
+ self.radioList[button] = c.name
# add the toolbars to the toolbox
toolbox.add_toolbar("Create",create_toolbar)
@@ -78,29 +46,6 @@ class PhysicsActivity(olpcgames.PyGameActivity):
self.set_toolbox(toolbox)
toolbox.set_current_toolbar(1)
return activity_toolbar
-
- def _box_cb(self,button):
- pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='box'))
- #self.box.handler_block(self.blocklist[0])
- #self.box.set_active(True)
- #print "Hello!"
- #self.box.handler_unblock(self.blocklist[0])
- #self.box.do_toggled(self.box)
-
- def _circle_cb(self,button):
- pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action='circle'))
- #self.circle.set_active(True)
-
- 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'))
+ def radioClicked(self,button):
+ pygame.event.post(olpcgames.eventwrap.Event(pygame.USEREVENT, action=self.radioList[button])) \ No newline at end of file