From 67a1e8bd00f0d775f4dcb170367290b62929e34f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 09 Jul 2008 22:02:31 +0000 Subject: Menus should now work (really) --- diff --git a/activity.py b/activity.py index d9ff198..1c661da 100644 --- a/activity.py +++ b/activity.py @@ -1,81 +1,98 @@ import olpcgames import pygame from sugar.graphics.toolbutton import ToolButton +from sugar.activity import activity from gettext import gettext as _ +import gtk 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() + # setup the toolbar + def build_toolbar(self): + # make a toolbox + toolbox = activity.ActivityToolbox(self) - toolbar.circle = ToolButton('circle') - toolbar.circle.set_tooltip(_('Circle')) - toolbar.circle.connect('clicked', self._circle_cb) - toolbar.insert(toolbar.circle, 1) - toolbar.circle.show() + # modify the Activity tab + activity_toolbar = toolbox.get_activity_toolbar() + activity_toolbar.share.props.visible = False - toolbar.triangle = ToolButton('triangle') - toolbar.triangle.set_tooltip(_('Triangle')) - toolbar.triangle.connect('clicked', self._triangle_cb) - toolbar.insert(toolbar.triangle, 1) - toolbar.triangle.show() + # make a 'create' toolbar + create_toolbar = gtk.Toolbar() - toolbar.polygon = ToolButton('polygon') - toolbar.polygon.set_tooltip(_('Polygon')) - toolbar.polygon.connect('clicked', self._polygon_cb) - toolbar.insert(toolbar.polygon, 1) - toolbar.polygon.show() + # make + add the creation buttons + box = ToolButton('box') + box.set_tooltip(_("Box")) + box.connect('clicked',self._box_cb) + create_toolbar.insert(box,-1) + box.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() + circle = ToolButton('circle') + circle.set_tooltip(_("Circle")) + circle.connect('clicked',self._circle_cb) + create_toolbar.insert(circle,-1) + circle.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() + triangle = ToolButton('triangle') + triangle.set_tooltip(_("Triangle")) + triangle.connect('clicked',self._triangle_cb) + create_toolbar.insert(triangle,-1) + triangle.show() + + polygon = ToolButton('polygon') + polygon.set_tooltip(_("Polygon")) + polygon.connect('clicked',self._polygon_cb) + create_toolbar.insert(polygon,-1) + polygon.show() + + magicpen = ToolButton('magicpen') + magicpen.set_tooltip(_("Magic Pen")) + magicpen.connect('clicked',self._magicpen_cb) + create_toolbar.insert(magicpen,-1) + magicpen.show() + + grab = ToolButton('grab') + grab.set_tooltip(_("Grab")) + grab.connect('clicked',self._grab_cb) + create_toolbar.insert(grab,-1) + 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() + joint = ToolButton('joint') + joint.set_tooltip(_("Joint")) + joint.connect('clicked',self._joint_cb) + create_toolbar.insert(joint,-1) + 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 + destroy = ToolButton('destroy') + destroy.set_tooltip(_("Destroy")) + destroy.connect('clicked',self._destroy_cb) + create_toolbar.insert(destroy,-1) + destroy.show() + + # add the toolbars to the toolbox + toolbox.add_toolbar("Create",create_toolbar) + create_toolbar.show() + + toolbox.show() + self.set_toolbox(toolbox) + return activity_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')) - 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')) -- cgit v0.9.1