[Sugar-devel] help about the get_preview function of activity.Activity class to take screenshots

Martin Sevior msevior at gmail.com
Mon Jul 20 09:28:24 EDT 2009

Hi Sumit,

I just fixed the example code in the pyabiword module of abiword to
give an example
of how this works.

The important line in this example is:

 i.props.pixbuf = abi.render_page_to_image(1)

The converts page number 1 to a GdkPixbuf. Once you have a GdkPixbuf,
in this case in
a Gtk.Image you can convert it to whatever format you wish.

>From the PyGtk reference manual http://www.pygtk.org/docs/pygtk/
 you convert  this to an image with:


So if you wanted the GdkPixbuf directly you would do:

PagePixbuf = abi.render_page_to_image(1)

Where "filename" is the name of the file you wish to store to.



PS. here is test.py which shows the feature in action (thanks for the
patch tomeu!)


import sys
import pygtk
import gtk
import abiword

window = gtk.Window()
window.set_default_size(640, 480)
window.connect('delete-event', gtk.main_quit)

box = gtk.VBox()

abi = abiword.Canvas()


b = gtk.Button('render page')

i = gtk.Image()

def _clicked_cb(widget, abi, i):
    i.props.pixbuf = abi.render_page_to_image(1)

b.connect('clicked', lambda widget: _clicked_cb(widget, abi, i))


On Mon, Jul 20, 2009 at 10:43 PM, sumit singh<sumit.coder at gmail.com> wrote:
> Hi everyone,
> Can anyone please guide me about the proper use of the get_preview function
> of the activity.Activity class of sugar. I had a look at its api, it seems
> to be returning a dictionary sort of thing which is called as the png image.
> What I want to do is to save this image somewhere in the datastore and show
> this image later to the user in my activity. So, what I want to ask is to
> how to load this information in the form of an image later on
> programatically. Can we load it using the gtk.image widget and what is the
> right procedure to save this information.
> Regards,
> sumit
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel

More information about the Devel mailing list