From 92e9cc8bbd8900413c1349139e21ef12a411f684 Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Tue, 19 Nov 2013 14:27:56 +0000 Subject: Add a Clear/Erase All tool Problem: It is problematic to remove all bodies in the canvas, one by one, to get a clear screen. A clear all tool is certainly needed. Solution: Implement a Clear All tool, which also asks for confirmation before destroying everything. Fixes #1615 --- (limited to 'activity.py') 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(_('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])) -- cgit v0.9.1