[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:

http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save

So if you wanted the GdkPixbuf directly you would do:

PagePixbuf = abi.render_page_to_image(1)
PagePixbuf.save(filename,"png")

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

Cheers!

Martin

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

----------------------------------------------------------
#!/usr/bin/python

import sys
import pygtk
pygtk.require('2.0')
import gtk
import abiword

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

box = gtk.VBox()
window.add(box)
box.show()

abi = abiword.Canvas()
box.add(abi)
abi.show()

window.show()

b = gtk.Button('render page')
box.add(b)
b.show()

i = gtk.Image()
box.add(i)
i.show()

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))

gtk.main()
--------------------------------------------

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