diff options
author | Manuel Quiñones <manuq@laptop.org> | 2012-01-05 16:45:10 (GMT) |
---|---|---|
committer | Manuel Quiñones <manuq@laptop.org> | 2012-01-05 16:45:10 (GMT) |
commit | 7f2baed6e4aa388feb033a2b6c9f9ea9f6aa01c2 (patch) | |
tree | 22b6f7765813262fea76d61ee4f657adc996a3a8 | |
parent | b92532a3e477406c92b1f76c1e47a323ca5e37e6 (diff) |
Restore starred links
The thumbnails are now made with Cairo.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
-rw-r--r-- | linkbutton.py | 48 | ||||
-rw-r--r-- | webactivity.py | 40 |
2 files changed, 45 insertions, 43 deletions
diff --git a/linkbutton.py b/linkbutton.py index 151f74c..a6248bf 100644 --- a/linkbutton.py +++ b/linkbutton.py @@ -20,6 +20,9 @@ from gi.repository import GdkPixbuf import os from gi.repository import GObject +from gi.repository import Gdk +import StringIO +import cairo from gettext import gettext as _ import rsvg import re @@ -47,32 +50,27 @@ class LinkButton(TrayButton, GObject.GObject): def set_image(self, buf, fill='#0000ff', stroke='#4d4c4f'): img = Gtk.Image() - loader = GdkPixbuf.PixbufLoader() - loader.write(buf) - loader.close() - pixbuf = loader.get_pixbuf() - del loader + str_buf = StringIO.StringIO(buf) + thumb_surface = cairo.ImageSurface.create_from_png(str_buf) xo_buddy = os.path.join(os.path.dirname(__file__), "icons/link.svg") - pixbuf_bg = self._read_link_background(xo_buddy, fill, stroke) - pixbuf_bg = pixbuf_bg.scale_simple(style.zoom(120), - style.zoom(110), - GdkPixbuf.InterpType.BILINEAR) + + bg_surface = self._read_link_background(xo_buddy, fill, stroke) + + cairo_context = cairo.Context(bg_surface) dest_x = style.zoom(10) dest_y = style.zoom(20) - w = pixbuf.get_width() - h = pixbuf.get_height() - scale_x = 1 - scale_y = 1 - - pixbuf.composite(pixbuf_bg, dest_x, dest_y, w, h, dest_x, dest_y, - scale_x, scale_y, GdkPixbuf.InterpType.BILINEAR, 255) + cairo_context.set_source_surface(thumb_surface, dest_x, dest_y) + thumb_width, thumb_height = style.zoom(100), style.zoom(80) + cairo_context.rectangle(dest_x, dest_y, thumb_width, thumb_height) + cairo_context.fill() + + bg_width, bg_height = style.zoom(120), style.zoom(110) + pixbuf_bg = Gdk.pixbuf_get_from_surface(bg_surface, 0, 0, + bg_width, bg_height) img.set_from_pixbuf(pixbuf_bg) self.set_icon_widget(img) img.show() - del pixbuf - del pixbuf_bg - gc.collect() def _read_link_background(self, filename, fill_color, stroke_color): icon_file = open(filename, 'r') @@ -87,8 +85,16 @@ class LinkButton(TrayButton, GObject.GObject): entity = '<!ENTITY stroke_color "%s">' % stroke_color data = re.sub('<!ENTITY stroke_color .*>', entity, data) - data_size = len(data) - return rsvg.Handle(data=data).get_pixbuf() + link_width, link_height = style.zoom(120), style.zoom(110) + link_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, + link_width, link_height) + link_context = cairo.Context(link_surface) + link_scale_w = link_width * 1.0 / 120 + link_scale_h = link_height * 1.0 / 110 + link_context.scale(link_scale_w, link_scale_h) + handler = rsvg.Handle(data=data) + handler.render_cairo(link_context) + return link_surface def setup_rollover_options(self, info): palette = Palette(info, text_maxlen=50) diff --git a/webactivity.py b/webactivity.py index 4730588..3d741d9 100644 --- a/webactivity.py +++ b/webactivity.py @@ -35,6 +35,7 @@ import cjson from gi.repository import GConf import locale import cairo +import StringIO from hashlib import sha1 from sugar3.activity import activity @@ -504,7 +505,7 @@ class WebActivity(activity.Activity): ''' take screenshot and add link info to the model ''' browser = self._tabbed_view.props.current_browser - ui_uri = browser.get_url_from_nsiuri(browser.progress.location) + ui_uri = browser.get_uri() for link in self.model.data['shared_links']: if link['hash'] == sha1(ui_uri).hexdigest(): @@ -553,31 +554,26 @@ class WebActivity(activity.Activity): ''' an item of the link tray has been clicked ''' self._tabbed_view.props.current_browser.load_uri(url) - def _pixbuf_save_cb(self, buf, data): - data[0] += buf - return True - - def get_buffer(self, pixbuf): - data = [""] - pixbuf.save_to_callback(self._pixbuf_save_cb, "png", {}, data) - return str(data[0]) - def _get_screenshot(self): - window = self._tabbed_view.props.current_browser.window - width, height = window.get_size() + browser = self._tabbed_view.props.current_browser + window = browser.get_window() + width, height = window.get_width(), window.get_height() + + thumb_width, thumb_height = style.zoom(100), style.zoom(80) - screenshot = GdkPixbuf.Pixbuf(GdkPixbuf.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) + thumb_surface = Gdk.Window.create_similar_surface(window, + cairo.CONTENT_COLOR, thumb_width, thumb_height) - screenshot = screenshot.scale_simple(style.zoom(100), - style.zoom(80), - GdkPixbuf.InterpType.BILINEAR) + cairo_context = cairo.Context(thumb_surface) + thumb_scale_w = thumb_width * 1.0 / width + thumb_scale_h = thumb_height * 1.0 / height + cairo_context.scale(thumb_scale_w, thumb_scale_h) + Gdk.cairo_set_source_window(cairo_context, window, 0, 0) + cairo_context.paint() - buf = self.get_buffer(screenshot) - return buf + thumb_str = StringIO.StringIO() + thumb_surface.write_to_png(thumb_str) + return thumb_str.getvalue() def can_close(self): if self._force_close: |