Martin and Tomeu,<br><br>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. <br>
<br>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.<br>
<br>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- <a href="http://api.sugarlabs.org/sugar.activity.activity-pysrc.html">http://api.sugarlabs.org/sugar.activity.activity-pysrc.html</a> , 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. <br>
<br>Regards,<br>sumit.<br><br><br><br><br><br><br><div class="gmail_quote">On Mon, Jul 20, 2009 at 6:58 PM, Martin Sevior <span dir="ltr"><<a href="mailto:msevior@gmail.com">msevior@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Sumit,<br>
<br>
I just fixed the example code in the pyabiword module of abiword to<br>
give an example<br>
of how this works.<br>
<br>
The important line in this example is:<br>
<br>
i.props.pixbuf = abi.render_page_to_image(1)<br>
<br>
The converts page number 1 to a GdkPixbuf. Once you have a GdkPixbuf,<br>
in this case in<br>
a Gtk.Image you can convert it to whatever format you wish.<br>
<br>
>From the PyGtk reference manual <a href="http://www.pygtk.org/docs/pygtk/" target="_blank">http://www.pygtk.org/docs/pygtk/</a><br>
you convert this to an image with:<br>
<br>
<a href="http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save" target="_blank">http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save</a><br>
<br>
So if you wanted the GdkPixbuf directly you would do:<br>
<br>
PagePixbuf = abi.render_page_to_image(1)<br>
PagePixbuf.save(filename,"png")<br>
<br>
Where "filename" is the name of the file you wish to store to.<br>
<br>
Cheers!<br>
<br>
Martin<br>
<br>
PS. here is test.py which shows the feature in action (thanks for the<br>
patch tomeu!)<br>
<br>
----------------------------------------------------------<br>
#!/usr/bin/python<br>
<br>
import sys<br>
import pygtk<br>
pygtk.require('2.0')<br>
import gtk<br>
import abiword<br>
<br>
window = gtk.Window()<br>
window.set_default_size(640, 480)<br>
window.connect('delete-event', gtk.main_quit)<br>
<br>
box = gtk.VBox()<br>
window.add(box)<br>
box.show()<br>
<br>
abi = abiword.Canvas()<br>
box.add(abi)<br>
abi.show()<br>
<br>
window.show()<br>
<br>
b = gtk.Button('render page')<br>
box.add(b)<br>
b.show()<br>
<br>
i = gtk.Image()<br>
box.add(i)<br>
i.show()<br>
<br>
def _clicked_cb(widget, abi, i):<br>
i.props.pixbuf = abi.render_page_to_image(1)<br>
<br>
b.connect('clicked', lambda widget: _clicked_cb(widget, abi, i))<br>
<br>
gtk.main()<br>
--------------------------------------------<br>
<div><div></div><div class="h5"><br>
On Mon, Jul 20, 2009 at 10:43 PM, sumit singh<<a href="mailto:sumit.coder@gmail.com">sumit.coder@gmail.com</a>> wrote:<br>
> Hi everyone,<br>
><br>
> Can anyone please guide me about the proper use of the get_preview function<br>
> of the activity.Activity class of sugar. I had a look at its api, it seems<br>
> to be returning a dictionary sort of thing which is called as the png image.<br>
> What I want to do is to save this image somewhere in the datastore and show<br>
> this image later to the user in my activity. So, what I want to ask is to<br>
> how to load this information in the form of an image later on<br>
> programatically. Can we load it using the gtk.image widget and what is the<br>
> right procedure to save this information.<br>
><br>
> Regards,<br>
> sumit<br>
><br>
</div></div>> _______________________________________________<br>
> Sugar-devel mailing list<br>
> <a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
> <a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
><br>
><br>
</blockquote></div><br>