[Sugar-devel] [PATCH] Add Write to Journal button to standard activity toolbar
Walter Bender
walter at sugarlabs.org
Thu Jan 12 12:27:34 EST 2012
From: Walter Bender <walter.bender at gmail.com>
This patch adds a new button to the standard activity toolbar (between the
activity title and the sharing button). The button involes a palette that
contains a textview widget that lets the user make changes to
metadata['description']. Additional dependencies introduced by this patch
include a new icon, write-journal.svg, and the introduction of a new
string for translation, _('Reflections').
Details regarding this patch can be found at [1]. Note that while this patch
is independent of the Naming Alert, it makes that alert largely obsolete.
[1] http://wiki.sugarlabs.org/go/Features/Write_to_journal_anytime
---
src/sugar/activity/widgets.py | 60 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/src/sugar/activity/widgets.py b/src/sugar/activity/widgets.py
index e5c4063..2a106e9 100644
--- a/src/sugar/activity/widgets.py
+++ b/src/sugar/activity/widgets.py
@@ -1,4 +1,5 @@
# Copyright (C) 2009, Aleksey Lim, Simon Schampijer
+# Copyright (C) 2012, Walter Bender
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -235,6 +236,60 @@ class TitleEntry(gtk.ToolItem):
shared_activity.props.name = title
+class DescriptionEntry(gtk.ToolItem):
+
+ def __init__(self, activity, **kwargs):
+ gtk.ToolItem.__init__(self)
+ self.activity = activity
+
+ write_journal_button = ToolButton('write-journal')
+ write_journal_button.show()
+ # TRANS: Reflections are saved to the description metadata field
+ write_journal_button.set_tooltip(_('Reflections'))
+ self._palette = write_journal_button.get_palette()
+
+ msg_box = gtk.HBox()
+
+ sw = gtk.ScrolledWindow()
+ sw.set_size_request(int(gtk.gdk.screen_width() / 2),
+ 2 * style.GRID_CELL_SIZE)
+ sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self.text_view = gtk.TextView()
+ self.text_view.set_left_margin(style.DEFAULT_PADDING)
+ self.text_view.set_right_margin(style.DEFAULT_PADDING)
+ text_buffer = gtk.TextBuffer()
+ if 'description' in self.activity.metadata:
+ text_buffer.set_text(self.activity.metadata['description'])
+ self.text_view.set_buffer(text_buffer)
+ self.text_view.connect('focus-out-event',
+ self._text_view_focus_out_event_cb)
+ sw.add(self.text_view)
+ sw.show()
+ msg_box.pack_start(sw, expand=False)
+ msg_box.show_all()
+
+ self._palette.set_content(msg_box)
+ write_journal_button.connect('clicked',
+ self._write_journal_button_cb)
+ self.add(write_journal_button)
+
+ def _write_journal_button_cb(self, button):
+ if self._palette:
+ if not self._palette.is_up():
+ self._palette.popup(immediate=True,
+ state=self._palette.SECONDARY)
+ else:
+ self._palette.popdown(immediate=True)
+ return
+
+ def _text_view_focus_out_event_cb(self, widget, event):
+ buffer = self.text_view.get_buffer()
+ start_iter = buffer.get_start_iter()
+ end_iter = buffer.get_end_iter()
+ self.activity.metadata['description'] = \
+ buffer.get_text(start_iter, end_iter)
+
+
class ActivityToolbar(gtk.Toolbar):
"""The Activity toolbar with the Journal entry title, sharing
and Stop buttons
@@ -261,6 +316,11 @@ class ActivityToolbar(gtk.Toolbar):
self.insert(separator, -1)
separator.show()
+ if activity.metadata:
+ description_palette = DescriptionEntry(activity)
+ description_palette.show()
+ self.insert(description_palette, -1)
+
self.share = ShareButton(activity)
self.share.show()
self.insert(self.share, -1)
--
1.7.7.5
More information about the Sugar-devel
mailing list