Support for previews in the journal.

master
Tomeu Vizoso 17 years ago
parent 6c0885b490
commit f0e18ba785

@ -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()

@ -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)

@ -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(),

@ -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

Loading…
Cancel
Save