[Sugar-devel] [PATCH sugar-toolkit-gtk3] Do the preview in the activity using cairo intead of GdkPixbuf

Gonzalo Odiard godiard at sugarlabs.org
Fri Feb 10 11:10:04 EST 2012


Ok. I will work to try to remove the toolbar.

Next we can see how to scale without streching.
(I had code to do it in the old Browse downloadmanager)

Gonzalo

2012/2/10 Manuel Quiñones <manuq at laptop.org>

> Hi Gonzalo,
>
> Tested.  I see the same issue as the current Browse favourite pages
> thumbnails (which I wrote and was a reference for this): unlike the
> previous version in GTK2+, the toolbar is added to the screenshot.
>
> As a side note, we should fix the stretching, which was also in the
> previous version.  Look how stretched this moon looks:
>
> http://dev.laptop.org/~manuq/stretched_thumb.png
>

Hmm, I don't know what is better, a preview with or without toolbar.
A Design Team decision



>
>
> El día 9 de febrero de 2012 17:08,  <godiard at sugarlabs.org> escribió:
> > From: Gonzalo Odiard <godiard at gmail.com>
> >
> > Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
> > ---
> >  src/sugar3/activity/activity.py |   33 ++++++++++++++++++---------------
> >  1 files changed, 18 insertions(+), 15 deletions(-)
> >
> > diff --git a/src/sugar3/activity/activity.py
> b/src/sugar3/activity/activity.py
> > index 19c1974..e943d44 100644
> > --- a/src/sugar3/activity/activity.py
> > +++ b/src/sugar3/activity/activity.py
> > @@ -54,11 +54,12 @@ import os
> >  import time
> >  from hashlib import sha1
> >  from functools import partial
> > +import StringIO
> >
> >  from gi.repository import GConf
> >  from gi.repository import Gtk
> >  from gi.repository import Gdk
> > -from gi.repository import GdkPixbuf
> > +import cairo
> >  from gi.repository import GObject
> >  import dbus
> >  import dbus.service
> > @@ -642,26 +643,28 @@ class Activity(Window, Gtk.Container):
> >         binary content of a png image with a width of 300 and a height
> of 225
> >         pixels.
> >         """
> > -        if self.canvas is None or not hasattr(self.canvas,
> 'get_snapshot'):
> > +        if self.canvas is None or not hasattr(self.canvas,
> 'get_window'):
> >             return None
> > -        pixmap = self.canvas.get_snapshot((-1, -1, 0, 0))
> >
> > -        width, height = pixmap.get_size()
> > -        pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, 0, 8,
> width, height)
> > -        pixbuf = pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
> > -                                          0, 0, 0, 0, width, height)
> > -        pixbuf = pixbuf.scale_simple(style.zoom(300), style.zoom(225),
> > -                                     GdkPixbuf.InterpType.BILINEAR)
> > +        window = self.canvas.get_window()
> >
> > -        preview_data = []
> > +        width, height = window.get_width(), window.get_height()
> >
> > -        def save_func(buf, data):
> > -            data.append(buf)
> > +        preview_width, preview_height = style.zoom(300), style.zoom(225)
> >
> > -        pixbuf.save_to_callback(save_func, 'png',
> user_data=preview_data)
> > -        preview_data = ''.join(preview_data)
> > +        preview_surface = Gdk.Window.create_similar_surface(window,
> > +            cairo.CONTENT_COLOR, preview_width, preview_height)
> >
> > -        return preview_data
> > +        cairo_context = cairo.Context(preview_surface)
> > +        preview_scale_w = preview_width * 1.0 / width
> > +        preview_scale_h = preview_height * 1.0 / height
> > +        cairo_context.scale(preview_scale_w, preview_scale_h)
> > +        Gdk.cairo_set_source_window(cairo_context, window, 0, 0)
> > +        cairo_context.paint()
> > +
> > +        preview_str = StringIO.StringIO()
> > +        preview_surface.write_to_png(preview_str)
> > +        return preview_str.getvalue()
> >
> >     def _get_buddies(self):
> >         if self.shared_activity is not None:
> > --
> > 1.7.7.6
> >
> > _______________________________________________
> > Sugar-devel mailing list
> > Sugar-devel at lists.sugarlabs.org
> > http://lists.sugarlabs.org/listinfo/sugar-devel
>
>
>
> --
> .. manuq ..
>



-- 
Gonzalo Odiard
SugarLabs Argentina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20120210/1ac1fed2/attachment.html>


More information about the Sugar-devel mailing list