Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-15 16:03:17 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-15 16:03:17 (GMT)
commitf0e18ba785a3d57af54bb6f6a7e9993dee6e72fe (patch)
treebb5225354f1b67c4714afc168a99b668b8330b90
parent6c0885b490b79662245f51628201a83e7ae70067 (diff)
Support for previews in the journal.
-rw-r--r--shell/view/Shell.py6
-rw-r--r--sugar/activity/activity.py23
-rw-r--r--sugar/datastore/datastore.py2
-rw-r--r--sugar/graphics/window.py13
4 files changed, 39 insertions, 5 deletions
diff --git a/shell/view/Shell.py b/shell/view/Shell.py
index 626f8a2..ab13269 100644
--- a/shell/view/Shell.py
+++ b/shell/view/Shell.py
@@ -214,13 +214,13 @@ class Shell(gobject.GObject):
file_path = os.path.join(tempfile.gettempdir(), '%i' % time.time())
window = gtk.gdk.get_default_root_window()
- width, height = window.get_size();
- x_orig, y_orig = window.get_origin();
+ width, height = window.get_size()
+ x_orig, y_orig = window.get_origin()
screenshot = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=False,
bits_per_sample=8, width=width, height=height)
screenshot.get_from_drawable(window, window.get_colormap(), x_orig, y_orig, 0, 0,
- width, height);
+ width, height)
screenshot.save(file_path, "png")
jobject = datastore.create()
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)
diff --git a/sugar/datastore/datastore.py b/sugar/datastore/datastore.py
index 4cac40b..4b8b903 100644
--- a/sugar/datastore/datastore.py
+++ b/sugar/datastore/datastore.py
@@ -96,7 +96,7 @@ def create():
return DSObject(object_id=None, metadata=DSMetadata(), file_path=None)
def write(ds_object, reply_handler=None, error_handler=None):
- logging.debug('datastore.write: %r' % ds_object.metadata.get_dictionary())
+ logging.debug('datastore.write')
if ds_object.object_id:
dbus_helpers.update(ds_object.object_id,
ds_object.metadata.get_dictionary(),
diff --git a/sugar/graphics/window.py b/sugar/graphics/window.py
index d2afaf8..28fdb35 100644
--- a/sugar/graphics/window.py
+++ b/sugar/graphics/window.py
@@ -53,3 +53,16 @@ class Window(gtk.Window):
group = gtk.Window()
group.realize()
window.window.set_group(group.window)
+
+ def get_canvas_screenshot(self):
+ if not self.canvas:
+ return None
+
+ window = self.canvas.window
+ width, height = window.get_size()
+
+ screenshot = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, has_alpha=False,
+ bits_per_sample=8, width=width, height=height)
+ screenshot.get_from_drawable(window, window.get_colormap(), 0, 0, 0, 0,
+ width, height)
+ return screenshot