[Sugar-devel] [PATCH 2/2] Pippy: add edit toolbar

Anish Mangal anish at sugarlabs.org
Mon Nov 1 07:37:31 EDT 2010


This patch adds the standard edit toolbar to the Pippy layout.
If the activity is not shared, all four toolbar buttons, i.e.
copy, paste, undo, redo will be active. However, if an activity
is shared, the undo and redo buttons are made insensitive. This
is due an issue with undo/redoing that is yet to be debugged
more extensively.

TODO: Open a bug report and mention bug-id here.

Signed-off-by: Anish Mangal <anish at sugarlabs.org>
---
 pippy_app.py |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/pippy_app.py b/pippy_app.py
index ed8ee24..96feb46 100644
--- a/pippy_app.py
+++ b/pippy_app.py
@@ -31,6 +31,7 @@ from signal import SIGTERM
 from gettext import gettext as _
 
 from activity import ViewSourceActivity, TARGET_TYPE_TEXT
+from sugar.activity import activity
 from sugar.activity.activity import ActivityToolbox, \
      get_bundle_path, get_bundle_name
 from sugar.graphics import style
@@ -102,6 +103,14 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
             activity_button = ActivityToolbarButton(self)
             toolbar_box.toolbar.insert(activity_button, 0)
 
+            self._edit_toolbar = activity.EditToolbar()
+            edit_toolbar_button = ToolbarButton()
+            edit_toolbar_button.props.page = self._edit_toolbar
+            edit_toolbar_button.props.icon_name = 'toolbar-edit'
+            edit_toolbar_button.props.label = _('Edit')
+            toolbar_box.toolbar.insert(edit_toolbar_button, -1)
+            self._edit_toolbar.show()
+
             separator = gtk.SeparatorToolItem()
             toolbar_box.toolbar.insert(separator, -1)
 
@@ -180,6 +189,11 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
             # <= 0.84 toolbars
             # Top toolbar with share and close buttons:
             toolbox = ActivityToolbox(self)
+
+            self._edit_toolbar = activity.EditToolbar()
+            toolbox.add_toolbar(_('Edit'), self._edit_toolbar)
+            self._edit_toolbar.show()
+
             # add 'make bundle' entry to 'keep' palette.
             palette = toolbox.get_activity_toolbar().keep.get_palette()
             # XXX: should clear out old palette entries?
@@ -237,6 +251,11 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
             activity_toolbar = toolbox.get_activity_toolbar()
             activity_toolbar.share.props.visible = False
 
+        self._edit_toolbar.undo.connect('clicked', self.undobutton_cb)
+        self._edit_toolbar.redo.connect('clicked', self.redobutton_cb)
+        self._edit_toolbar.copy.connect('clicked', self.copybutton_cb)
+        self._edit_toolbar.paste.connect('clicked', self.pastebutton_cb)
+
         # Main layout.
         self.hpane = gtk.HPaned()
         self.vpane = gtk.VPaned()
@@ -352,6 +371,12 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         return self.hpane
 
     def when_shared(self):
+        # HACK : There are issues with undo/redoing while in shared
+        # mode. So disable the 'undo' and 'redo' buttons when the activity
+        # is shared.
+        self._edit_toolbar.undo.set_sensitive(False)
+        self._edit_toolbar.redo.set_sensitive(False)
+
         self.hpane.remove(self.hpane.get_child1())
         global text_buffer
         self.cloud.sharefield = groupthink.gtk_tools.TextBufferSharePoint(text_buffer)
@@ -414,6 +439,24 @@ class PippyActivity(ViewSourceActivity, groupthink.sugar_tools.GroupActivity):
         self._vte.grab_focus()
         self._vte.feed("\x1B[H\x1B[J\x1B[0;39m")
 
+    def undobutton_cb(self, button):
+        global text_buffer
+        if text_buffer.can_undo():
+            text_buffer.undo()
+
+    def redobutton_cb(self, button):
+        global text_buffer
+        if text_buffer.can_redo():
+            text_buffer.redo()
+
+    def copybutton_cb(self, button):
+        global text_buffer
+        text_buffer.copy_clipboard(gtk.Clipboard())
+
+    def pastebutton_cb(self, button):
+        global text_buffer
+        text_buffer.paste_clipboard(gtk.Clipboard(), None, True)
+
     def gobutton_cb(self, button):
         from shutil import copy2
         self.stopbutton_cb(button) # try stopping old code first.
-- 
1.7.2.3



More information about the Sugar-devel mailing list