Am 22.02.2011 05:29, schrieb Jason Heeris:
I'm confused about some of the GIO async functions. In my case, I want
to use gio.File.replace_contents_async(). But what's the signature of
the callback it takes? I would assume that the callback receives the
original File object, but looking at the docs for gio.AsyncResult, it
might also need to take other arguments:

"This callback will be triggered when the operation has completed, and
will be passed a GAsyncResult instance filled with the details of the
operation's success or failure, the object the asynchronous function
was started for and any error codes returned."

This sentence is a bit grammatically imprecise :P I'm not sure whether
the "object the asynchronous function was started for" is part of (a)
what is passed to the callback, or (b) the contents of the
GAsyncResult.

It's neither nor. It's the object on which you called the replace_contents_async method (usually a gio.File):

import glib
import gio

mainloop = None

def callback (gfile, result):
        # gfile will be the same object as below
        try:
                gfile.replace_contents_finish (result)
                print "success"
        except gio.Error, error:
                print error
        finally:
                mainloop.quit ()

gfile = gio.File (uri="file:///tmp/test.txt")
gfile.replace_contents_async ("Hello!\n", callback)

mainloop = glib.MainLoop ()
mainloop.run ()

In either case, how do I use it? Presumably the return value from
replace_contents_finish() is the same as from replace_contents() (an
etag). But do I need to pass the GAsyncResult to
replace_contents_finish(), so that it's populated with any error
codes? Or are the error codes passed into the callback?

See above for how to deal with errors.


Any clarifying comments welcome :)

— Jason
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/


--
--
Christian Becke

Sprengelstr. 8
13353 Berlin

Phone: +49 (0)30 45 02 90 23
Mobile: +49 (0)160 7 43 88 88
Email: [email protected]
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to