Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2007-11-04 16:00:48 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2007-11-04 16:00:48 (GMT)
commit108147a6b1ee82250db00e7cf0a925773786c9b4 (patch)
treeff1fda819a6df2f4fe9f91e903672997fc9978e2 /lib
parentcd61c52c7ba3649e1d1a4a049dd284ea4b5dd998 (diff)
Hook up the new screenshot code
Diffstat (limited to 'lib')
-rw-r--r--lib/sugar/activity/activity.py34
-rw-r--r--lib/sugar/graphics/window.py13
2 files changed, 19 insertions, 28 deletions
diff --git a/lib/sugar/activity/activity.py b/lib/sugar/activity/activity.py
index 55000f3..d218f08 100644
--- a/lib/sugar/activity/activity.py
+++ b/lib/sugar/activity/activity.py
@@ -67,6 +67,7 @@ from sugar.datastore import datastore
from sugar import wm
from sugar import profile
from sugar import _sugarbaseext
+from sugar import _sugarext
SCOPE_PRIVATE = "private"
SCOPE_INVITE_ONLY = "invite" # shouldn't be shown in UI, it's implicit when you invite somebody
@@ -414,7 +415,7 @@ class Activity(Window, gtk.Container):
self._shared_activity = None
self._share_id = None
self._join_id = None
- self._preview = None
+ self._preview = _sugarext.Preview()
self._updating_jobject = False
self._closing = False
self._deleting = False
@@ -619,18 +620,20 @@ class Activity(Window, gtk.Container):
self._jobject = None
def _get_preview(self):
- preview_pixbuf = self.get_canvas_screenshot()
- if preview_pixbuf is None:
+ pixbuf = self._preview.get_pixbuf()
+ if pixbuf is None:
return None
- preview_pixbuf = preview_pixbuf.scale_simple(style.zoom(300),
- style.zoom(225),
- gtk.gdk.INTERP_BILINEAR)
- # TODO: Find a way of taking a png out of the pixbuf without saving to a temp file.
- # Impementing gtk.gdk.Pixbuf.save_to_buffer in pygtk would solve this.
+ pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
+ gtk.gdk.INTERP_BILINEAR)
+
+ # TODO: Find a way of taking a png out of the pixbuf without saving
+ # to a temp file. Impementing gtk.gdk.Pixbuf.save_to_buffer in pygtk
+ # would solve this.
fd, file_path = tempfile.mkstemp('.png')
del fd
- preview_pixbuf.save(file_path, 'png')
+
+ pixbuf.save(file_path, 'png')
f = open(file_path)
try:
preview_data = f.read()
@@ -638,6 +641,8 @@ class Activity(Window, gtk.Container):
f.close()
os.remove(file_path)
+ self._preview.clear()
+
return preview_data
def _get_buddies(self):
@@ -652,7 +657,8 @@ class Activity(Window, gtk.Container):
return {}
def take_screenshot(self):
- self._preview = self._get_preview()
+ if self.canvas and self.canvas.window:
+ self._preview.take_screenshot(self.canvas.window)
def save(self):
"""Request that the activity is saved to the Journal.
@@ -674,10 +680,9 @@ class Activity(Window, gtk.Container):
self.metadata['buddies_id'] = json.write(buddies_dict.keys())
self.metadata['buddies'] = json.write(self._get_buddies())
- if self._preview is None:
- self.metadata['preview'] = ''
- else:
- self.metadata['preview'] = dbus.ByteArray(self._preview)
+ preview = self._get_preview()
+ if self._preview:
+ self.metadata['preview'] = dbus.ByteArray(preview)
try:
if self._jobject.file_path:
@@ -708,7 +713,6 @@ class Activity(Window, gtk.Container):
copy work that needs to be done in write_file()
"""
logging.debug('Activity.copy: %r' % self._jobject.object_id)
- self._preview = self._get_preview()
self.save()
self._jobject.object_id = None
diff --git a/lib/sugar/graphics/window.py b/lib/sugar/graphics/window.py
index bfaad35..003f870 100644
--- a/lib/sugar/graphics/window.py
+++ b/lib/sugar/graphics/window.py
@@ -114,16 +114,3 @@ class Window(gtk.Window):
self.tray.props.visible = not self.tray.props.visible
return True
return False
-
- 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