diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-06-15 16:03:17 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-06-15 16:03:17 (GMT) |
commit | f0e18ba785a3d57af54bb6f6a7e9993dee6e72fe (patch) | |
tree | bb5225354f1b67c4714afc168a99b668b8330b90 /sugar/activity/activity.py | |
parent | 6c0885b490b79662245f51628201a83e7ae70067 (diff) |
Support for previews in the journal.
Diffstat (limited to 'sugar/activity/activity.py')
-rw-r--r-- | sugar/activity/activity.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index b72b0b1..2e7641c 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -27,9 +27,11 @@ import time import tempfile import gtk, gobject - +import dbus + from sugar.presence import presenceservice from sugar.activity.activityservice import ActivityService +from sugar.graphics import units from sugar.graphics.window import Window from sugar.graphics.toolbox import Toolbox from sugar.graphics.toolbutton import ToolButton @@ -276,6 +278,25 @@ class Activity(Window, gtk.Container): def save(self): """Request that the activity is saved to the Journal.""" + preview_pixbuf = self.get_canvas_screenshot() + preview_pixbuf = preview_pixbuf.scale_simple(units.grid_to_pixels(4), + units.grid_to_pixels(4), + gtk.gdk.INTERP_BILINEAR) + + # TODO: Find a way of taking a png out of the pixbuf without saving to a temp file. + fd, file_path = tempfile.mkstemp('.png') + del fd + preview_pixbuf.save(file_path, 'png') + f = open(file_path) + try: + preview_data = f.read() + finally: + f.close() + os.remove(file_path) + + # TODO: Take this out when the datastore accepts binary data. + import base64 + self.metadata['preview'] = base64.b64encode(preview_data) try: file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time()) self.write_file(file_path) |