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

sumit singh sumit.coder at gmail.com
Mon Jul 20 19:08:34 EDT 2009


Martin and Tomeu,

Martin, thanx a lot for such a detailed answer. I have got what you want to
say. But the problem with me right now is that I think the get_preview
function is available only in the latest release of sugar 0.84 because I am
on 0.82, and my xo gives an error -- " Activity module does not have an
attribute get_preview" . Is it so that the function has been added after
0.82 ? If yes, then is there any way on 0.82 build to take screenshots
programatically.

There is one strange thing which I am encountering right now. Though the log
gives an error that get_preview function is not present but when I ran write
63.xo on the machine ( after replacing sugar.graphics.colorbutton with
gtk.colorButton  in toolbar.py ) , closed it and then again tried to restart
the activity from the journal , I was able to see the following preview
which I am attaching with this mail, that was what was there on my activity
screen before I closed it.

Though I am not very much sure, but this should have happened because of the
save function in activity.Activity class , here is the link-
http://api.sugarlabs.org/sugar.activity.activity-pysrc.html , which calls
the get_preview function of sugar, which is a bit contradictory, if we
consider the result of the logs. Am I wrong in the way I am understanding
this? Kindly give your comments.

Regards,
sumit.






On Mon, Jul 20, 2009 at 6:58 PM, Martin Sevior <msevior at gmail.com> wrote:

> 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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.laptop.org/pipermail/devel/attachments/20090721/79031efb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: preview image.png
Type: image/png
Size: 18552 bytes
Desc: not available
URL: <http://lists.laptop.org/pipermail/devel/attachments/20090721/79031efb/attachment.png>


More information about the Devel mailing list