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

Tomeu Vizoso tomeu at sugarlabs.org
Mon Aug 23 03:35:48 EDT 2010


On Sat, Aug 21, 2010 at 19:05, Anish Mangal <anishmangal2002 at gmail.com> wrote:
> 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 visible. However, if an activity
> is shared, the undo and redo buttons are hidden. This is due
> an issue with undo/redoing that is yet to be debugged more
> extensively.

Should we show them as disabled instead?

Regards,

Tomeu

> Also, this patch adds comments to a portion of the code.
>
> TODO: Open a bug report and mention bug-id here.
>
> Signed-off-by: Anish Mangal <anish at sugarlabs.org>
> ---
>  pippy_app.py |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
>  1 files changed, 46 insertions(+), 2 deletions(-)
>
> diff --git a/pippy_app.py b/pippy_app.py
> index 30312c2..d3f87d4 100644
> --- a/pippy_app.py
> +++ b/pippy_app.py
> @@ -33,8 +33,8 @@ from gettext import gettext as _
>  from activity import ViewSourceActivity, TARGET_TYPE_TEXT
>  from sugar.activity.activity import ActivityToolbox, \
>      get_bundle_path, get_bundle_name
> +from sugar.activity import activity
>  from sugar.graphics import style
> -
>  from sugar.graphics.toolbutton import ToolButton
>
>  _ORIGINAL_PIPPY_LAYOUT = False
> @@ -67,7 +67,8 @@ SIZE_Y = gtk.gdk.screen_height()
>
>  groupthink_mimetype = 'pickle/groupthink-pippy'
>
> -# modded ActivityToolbarButton which has its toolbar object public
> +# Create a modded ActivityToolbarButton which has
> +# its toolbar object visible to the outside world.
>  class ActivityToolbarButton(ToolbarButton):
>
>     def __init__(self, activity, **kwargs):
> @@ -108,6 +109,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)
>
> @@ -186,6 +195,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?
> @@ -243,6 +257,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)
> +
>         # The sidebar.
>         self.sidebar = gtk.VBox()
>         self.model = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
> @@ -350,6 +369,13 @@ 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 hide the 'undo' and 'redo' buttons when the activity
> +        # is shared.
> +        self._edit_toolbar.undo.props.visible = False
> +        self._edit_toolbar.redo.props.visible = False
> +        self._edit_toolbar.separator.props.visible = False
> +
>         self.hpane.remove(self.hpane.get_child1())
>         global text_buffer
>         self.cloud.sharefield = groupthink.gtk_tools.TextBufferSharePoint(text_buffer)
> @@ -412,6 +438,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.1
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>


More information about the Sugar-devel mailing list