Am 22.02.2011 12:37, schrieb Christian Becke:
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.
Sorry, misread your message. The object is actually both: passed as an
argument to the callback, and accessible through the gio.AsyncResult by
calling its get_source_object method, see code below:
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):
print gfile is result.get_source_object () # prints "True"
# 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/