Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit aaea3591e27adfafa6a5b47a63a309b15bbbff20

Add DescriptionEntry to the activity sub-toolbar

This is the implementation of the 'Write to Journal anytime'
feature [1].

The patch itself adds a DescriptionItem to the activity
sub-toolbar to make editing a Journal entry description
from within the activity possible. The code has the same
error handling as the TitleEntry.

The patch is an adaptation from the one that landed in
sugar-toolkit-gtk3 and has been ported to the
sugar-toolkit. After talking with teachers and the learning team,
I found out that they are very excited about this feature.
Doing this change not only in sugar-toolkit-gtk3 and limit it
to the activities that have been ported to the new toolkit
we will have a more consistent experience across the activities
in the 0.96 release.

The original patch was done by Simon Schampijer <simon@laptop.org>
and Walter Bender <walter.bender@gmail.com>

Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>

[1] http://wiki.sugarlabs.org/go/Features/Write_to_journal_anytime
  
2828from sugar.graphics.xocolor import XoColor
2929from sugar.graphics.icon import Icon
3030from sugar.bundle.activitybundle import ActivityBundle
31from sugar.graphics import style
3132
3233
3334_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
236236 shared_activity.props.name = title
237237
238238
239class DescriptionItem(gtk.ToolItem):
240
241 def __init__(self, activity, **kwargs):
242 gtk.ToolItem.__init__(self)
243
244 description_button = ToolButton('edit-description')
245 description_button.show()
246 description_button.set_tooltip(_('Description'))
247 self._palette = description_button.get_palette()
248
249 description_box = gtk.HBox()
250 sw = gtk.ScrolledWindow()
251 sw.set_size_request(int(gtk.gdk.screen_width() / 2),
252 2 * style.GRID_CELL_SIZE)
253 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
254 self._text_view = gtk.TextView()
255 self._text_view.set_left_margin(style.DEFAULT_PADDING)
256 self._text_view.set_right_margin(style.DEFAULT_PADDING)
257 text_buffer = gtk.TextBuffer()
258 if 'description' in activity.metadata:
259 text_buffer.set_text(activity.metadata['description'])
260 self._text_view.set_buffer(text_buffer)
261 self._text_view.connect('focus-out-event',
262 self.__description_changed_cb, activity)
263 sw.add(self._text_view)
264 description_box.pack_start(sw, False, True, 0)
265 self._palette.set_content(description_box)
266 description_box.show_all()
267
268 self.add(description_button)
269 description_button.connect('clicked',
270 self.__description_button_clicked_cb)
271
272 activity.metadata.connect('updated', self.__jobject_updated_cb)
273
274 def _get_text_from_buffer(self):
275 buf = self._text_view.get_buffer()
276 start_iter = buf.get_start_iter()
277 end_iter = buf.get_end_iter()
278 return buf.get_text(start_iter, end_iter, False)
279
280 def __jobject_updated_cb(self, jobject):
281 if self._text_view.has_focus():
282 return
283 if 'description' not in jobject:
284 return
285 if self._get_text_from_buffer() == jobject['description']:
286 return
287 buf = self._text_view.get_buffer()
288 buf.set_text(jobject['description'])
289
290 def __description_button_clicked_cb(self, button):
291 self._palette.popup(immediate=True, state=1)
292
293 def __description_changed_cb(self, widget, event, activity):
294 description = self._get_text_from_buffer()
295 if 'description' in activity.metadata and \
296 description == activity.metadata['description']:
297 return
298
299 activity.metadata['description'] = description
300 activity.save()
301 return False
302
303
239304class ActivityToolbar(gtk.Toolbar):
240305 """The Activity toolbar with the Journal entry title, sharing
241306 and Stop buttons
326326 separator.set_expand(True)
327327 self.insert(separator, -1)
328328 separator.show()
329
330 if activity.metadata:
331 description_item = DescriptionItem(activity)
332 description_item.show()
333 self.insert(description_item, -1)
329334
330335 self.share = ShareButton(activity)
331336 self.share.show()