Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py89
-rw-r--r--tools.py61
2 files changed, 71 insertions, 79 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
diff --git a/tools.py b/tools.py
index a7d249a..5a19880 100644
--- a/tools.py
+++ b/tools.py
@@ -8,6 +8,9 @@ from pygame.locals import *
from helpers import *
# tools that can be used superlcass
class Tool(object):
+ name = "Tool"
+ icon = "icon"
+ toolTip = "Tool Tip"
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Tool"
@@ -56,7 +59,11 @@ class Tool(object):
pass
# The circle creation tool
-class CircleTool(Tool):
+class CircleTool(Tool):
+ name = "circle"
+ icon = "circle"
+ toolTip = "Circle"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Circle"
@@ -90,6 +97,10 @@ class CircleTool(Tool):
# The box creation tool
class BoxTool(Tool):
+ name = "box"
+ icon = "box"
+ toolTip = "Box"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Box"
@@ -120,7 +131,11 @@ class BoxTool(Tool):
self.rect = None
# The triangle creation tool
-class TriangleTool(Tool):
+class TriangleTool(Tool):
+ name = "triangle"
+ icon = "triangle"
+ toolTip = "Triangle"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Triangle"
@@ -150,7 +165,11 @@ class TriangleTool(Tool):
self.vertices = None
# The Polygon creation tool
-class PolygonTool(Tool):
+class PolygonTool(Tool):
+ name = "polygon"
+ icon = "polygon"
+ toolTip = "Polygon"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Polygon"
@@ -189,7 +208,11 @@ class PolygonTool(Tool):
self.vertices = None
# The magic pen tool
-class MagicPenTool(Tool):
+class MagicPenTool(Tool):
+ name = "magicpen"
+ icon = "magicpen"
+ toolTip = "Magic Pen"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Magic Pen"
@@ -228,7 +251,11 @@ class MagicPenTool(Tool):
self.vertices = None
# The grab tool
-class GrabTool(Tool):
+class GrabTool(Tool):
+ name = "grab"
+ icon = "grab"
+ toolTip = "Grab"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Grab"
@@ -253,7 +280,11 @@ class GrabTool(Tool):
self.game.world.add.remove_mouseJoint()
# The joint tool
-class JointTool(Tool):
+class JointTool(Tool):
+ name = "joint"
+ icon = "joint"
+ toolTip = "Joint"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Joint"
@@ -297,7 +328,11 @@ class JointTool(Tool):
self.jb1 = self.jb2 = self.jb1pos = self.jb2pos = None
# The destroy tool
-class DestroyTool(Tool):
+class DestroyTool(Tool):
+ name = "destroy"
+ icon = "destroy"
+ toolTip = "Destroy"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Destroy"
@@ -326,6 +361,10 @@ class DestroyTool(Tool):
# The joystick tool
class JoystickTool(Tool):
+ name = "joystick"
+ icon = "magicpen" # for now
+ toolTip = "Joystick"
+
def __init__(self,gameInstance):
self.game = gameInstance
self.name = "Joystick"
@@ -352,3 +391,11 @@ class JoystickTool(Tool):
def cancel(self):
self.vertices = None
+
+
+def list_local_classes():
+ this_mod = __import__(__name__)
+ return [val for val in this_mod.__dict__.values()
+ if isinstance(val, type)]
+
+local_classes = list_local_classes() \ No newline at end of file