Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/GetIABooksActivity.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@sugarlabs.org>2011-03-22 14:02:07 (GMT)
committer Gonzalo Odiard <godiard@sugarlabs.org>2011-03-22 14:02:07 (GMT)
commit53705cfc6b38383124f4be1611267977abd5b0d5 (patch)
treeb5877d80638fc9ed086a2431df9f158821342585 /GetIABooksActivity.py
parent6510ad0dd7686235f19dbdf9b159b55dd77e6090 (diff)
Add preview image when save in Journal
Diffstat (limited to 'GetIABooksActivity.py')
-rwxr-xr-xGetIABooksActivity.py57
1 files changed, 39 insertions, 18 deletions
diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py
index 0e4275b..0748a8e 100755
--- a/GetIABooksActivity.py
+++ b/GetIABooksActivity.py
@@ -34,6 +34,7 @@ try:
except ImportError:
OLD_TOOLBAR = True
+from sugar.graphics import style
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.menuitem import MenuItem
from sugar.graphics.toolcombobox import ToolComboBox
@@ -426,23 +427,6 @@ class GetIABooksActivity(activity.Activity):
pixbuf = pixbuf.scale_simple(int(width * scale),
int(height * scale), gtk.gdk.INTERP_BILINEAR)
- """
- pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, \
- pixbuf.get_has_alpha(), \
- pixbuf.get_bits_per_sample(), \
- preview_width, preview_height)
- #pixbuf2.fill(style.COLOR_WHITE.get_int())
-
- margin_x = int((preview_width - (width * scale)) / 2)
- margin_y = int((preview_height - (height * scale)) / 2)
-
- pixbuf.scale(pixbuf2, margin_x, margin_y, \
- preview_width - (margin_x * 2), \
- preview_height - (margin_y * 2), \
- margin_x, margin_y, scale, scale, \
- gtk.gdk.INTERP_BILINEAR)
- """
-
self.image.set_from_pixbuf(pixbuf)
def find_books(self, search_text=''):
@@ -606,12 +590,14 @@ class GetIABooksActivity(activity.Activity):
journal_entry.metadata['mime_type'] = \
self.format_combo.props.value
journal_entry.metadata['buddies'] = ''
- journal_entry.metadata['preview'] = ''
journal_entry.metadata['icon-color'] = profile.get_color().to_string()
textbuffer = self.textview.get_buffer()
journal_entry.metadata['description'] = \
textbuffer.get_text(textbuffer.get_start_iter(),
textbuffer.get_end_iter())
+ if self.exist_cover_image:
+ journal_entry.metadata['preview'] = self._get_preview_image()
+
journal_entry.file_path = tempfile
datastore.write(journal_entry)
os.remove(tempfile)
@@ -619,6 +605,41 @@ class GetIABooksActivity(activity.Activity):
self._alert(_('Success: %s was added to Journal.') %
self.selected_title)
+ def _get_preview_image(self):
+ preview_width, preview_height = style.zoom(300), style.zoom(225)
+
+ pixbuf = self.image.get_pixbuf()
+ width, height = pixbuf.get_width(), pixbuf.get_height()
+
+ scale = 1
+ if (width > preview_width) or (height > preview_height):
+ scale_x = preview_width / float(width)
+ scale_y = preview_height / float(height)
+ scale = min(scale_x, scale_y)
+
+ pixbuf2 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, \
+ pixbuf.get_has_alpha(), \
+ pixbuf.get_bits_per_sample(), \
+ preview_width, preview_height)
+ pixbuf2.fill(style.COLOR_WHITE.get_int())
+
+ margin_x = int((preview_width - (width * scale)) / 2)
+ margin_y = int((preview_height - (height * scale)) / 2)
+
+ pixbuf.scale(pixbuf2, margin_x, margin_y, \
+ preview_width - (margin_x * 2), \
+ preview_height - (margin_y * 2), \
+ margin_x, margin_y, scale, scale, \
+ gtk.gdk.INTERP_BILINEAR)
+ preview_data = []
+
+ def save_func(buf, data):
+ data.append(buf)
+
+ pixbuf2.save_to_callback(save_func, 'png', user_data=preview_data)
+ preview_data = ''.join(preview_data)
+ return dbus.ByteArray(preview_data)
+
def truncate(self, str, length):
if len(str) > length:
return str[0:length - 1] + '...'