diff options
-rw-r--r-- | activity.py | 30 | ||||
-rw-r--r-- | icons/clear_all.svg | 115 | ||||
-rw-r--r-- | tools.py | 8 |
3 files changed, 153 insertions, 0 deletions
diff --git a/activity.py b/activity.py index d7a3d76..9994dea 100644 --- a/activity.py +++ b/activity.py @@ -32,6 +32,7 @@ from sugar.activity.widgets import ActivityToolbarButton from sugar.activity.widgets import StopButton from sugar.graphics.radiotoolbutton import RadioToolButton from sugar.graphics.toolbutton import ToolButton +from sugar.graphics.alert import ConfirmationAlert from sugar.graphics.toolbarbox import ToolbarBox from sugar.graphics.toolbarbox import ToolbarButton from sugar.graphics.style import GRID_CELL_SIZE @@ -120,6 +121,12 @@ class PhysicsActivity(activity.Activity): self._insert_stop_play_button(toolbar_box.toolbar) separator = gtk.SeparatorToolItem() + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + self._insert_clear_all_button(toolbar_box.toolbar) + + separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) @@ -149,6 +156,14 @@ class PhysicsActivity(activity.Activity): toolbar.insert(self.stop_play, -1) self.stop_play.show() + def _insert_clear_all_button(self, toolbar): + self.clear_all = ToolButton('clear_all') + self.clear_all.set_tooltip(_("Erase All")) + self.clear_all.set_accelerator(_('<ctrl>a')) + self.clear_all.connect('clicked', self.clear_all_cb) + toolbar.insert(self.clear_all, -1) + self.clear_all.show() + def _insert_create_tools(self, create_toolbar): def _insert_item(toolbar, item, pos=-1): @@ -186,6 +201,21 @@ class PhysicsActivity(activity.Activity): self.stop_play.set_icon('media-playback-start') self.stop_play.set_tooltip(_("Start")) + def clear_all_cb(self, button): + clear_all_alert = ConfirmationAlert() + clear_all_alert.props.title=_('Are You Sure?') + clear_all_alert.props.msg = _('All you work will be discarded. This cannot be undone!') + clear_all_alert.connect('response', self.clear_all_alert_cb) + self.add_alert(clear_all_alert) + + def clear_all_alert_cb(self, alert, response_id): + self.remove_alert(alert) + if response_id is gtk.RESPONSE_OK: + pygame.event.post(pygame.event.Event(pygame.USEREVENT, + action="clear_all")) + else: + pass + def radioClicked(self, button): pygame.event.post(pygame.event.Event(pygame.USEREVENT, action=self.radioList[button])) diff --git a/icons/clear_all.svg b/icons/clear_all.svg new file mode 100644 index 0000000..4316a3a --- /dev/null +++ b/icons/clear_all.svg @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="48px" + height="48px" + id="svg2985" + version="1.1" + inkscape:version="0.48.3.1 r9886" + sodipodi:docname="clear_all.svg"> + <defs + id="defs2987" /> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="7" + inkscape:cx="-1.1428571" + inkscape:cy="24" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:grid-bbox="true" + inkscape:document-units="px" + gridtolerance="10" + inkscape:snap-global="false" + guidetolerance="10" + inkscape:window-width="1360" + inkscape:window-height="744" + inkscape:window-x="0" + inkscape:window-y="24" + inkscape:window-maximized="1" /> + <metadata + id="metadata2990"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + id="layer1" + inkscape:label="Layer 1" + inkscape:groupmode="layer"> + <rect + style="fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:3.899;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3821" + width="30.772253" + height="29.05797" + x="9.1853018" + y="14.328158" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:1.75924551;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3823" + width="38.669331" + height="1.6693259" + x="5.02248" + y="12.593908" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:1.25541639;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3825" + width="1.2017266" + height="14.344584" + x="15.970565" + y="21.399136" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:1.25541639;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3825-4" + width="1.2017266" + height="14.344584" + x="24.11342" + y="21.399137" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:1.25541639;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3825-1" + width="1.2017266" + height="14.344584" + x="31.970564" + y="21.256279" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:3.599;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3908" + width="24.428572" + height="0.14285715" + x="12.571428" + y="6.5714283" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:3.599;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3910" + width="0.14285715" + height="5.1428571" + x="12.571428" + y="6.8571424" /> + <rect + style="fill:none;stroke:#ffffff;stroke-width:3.599;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" + id="rect3910-5" + width="0.14285715" + height="5.1428571" + x="36.785713" + y="6.7142859" /> + </g> +</svg> @@ -49,6 +49,14 @@ class Tool(object): # Stop/start simulation toggle = self.game.world.run_physics self.game.world.run_physics = not toggle + elif event.action == "clear_all": + if len(self.game.world.world.GetBodyList()) > 1: + # Get bodies and destroy them too + for body in self.game.world.world.GetBodyList(): + self.game.world.world.DestroyBody(body) + + # Add ground, because we destroyed it before + self.game.world.add.ground() elif event.action == "focus_in": self.game.in_focus = True elif event.action == "focus_out": |