gtk.gdk.PixbufLoaderan object providing application-driven progressive image
loadingSynopsisgtk.gdk.PixbufLoadergobject.GObjectgtk.gdk.PixbufLoaderimage_typeNonewritebufcount-1get_pixbufget_animationcloseset_sizewidthheightget_formatFunctionsgtk.gdk.pixbuf_loader_new_with_mime_typemime_typeAncestry+-- gobject.GObject
+-- gtk.gdk.PixbufLoader
Signal Prototypes"area-prepared"callbackpixbufloaderuser_param1..."area-updated"callbackpixbufloaderxywidthheightuser_param1..."closed"callbackpixbufloaderuser_param1..."size-prepared"callbackpixbufloaderwidthheightuser_param1...DescriptionA gtk.gdk.PixbufLoader
provides a way for applications to drive the process of loading an image, by
letting them send the image data directly to the loader instead of having
the loader read the data from a file. Applications can use this instead of
the gtk.gdk.pixbuf_new_from_file function
or the gtk.gdk.PixbufAnimation
constructor when they need to parse image data in small chunks. For example,
it should be used when reading an image from a (potentially) slow network
connection, or when loading an extremely large file.To use gtk.gdk.PixbufLoader
to load an image, just create a new one, and call the write()
method to send the data to it. When done, the close()
method should be called to end the stream and finalize everything. The
loader will emit two important signals throughout the process. The first,
"area-prepared", will be called as soon as the image has enough information
to determine the size of the image to be used. The application can call the
get_pixbuf()
method to retrieve the pixbuf. No actual image data will be in the pixbuf,
so it can be safely filled with any temporary graphics (or an initial color)
as needed.The "area-updated" signal is emitted every time a region is
updated. This way you can update a partially completed image. Note that you
do not know anything about the completeness of an image from the area
updated. For example, in an interlaced image, you need to make several
passes before the image is done loading.Loading an AnimationLoading an animation is almost as easy as loading an image. Once
the first "area-prepared" signal has been emitted, you can call the get_animation()
method to get the gtk.gdk.PixbufAnimation
object and the gtk.gdk.PixbufAnimation.get_iter()
method to get an gtk.gdk.PixbufAnimationIter
for displaying it.Constructorgtk.gdk.PixbufLoaderimage_typeNoneimage_type :the name of the image format or
NoneReturns :A new gtk.gdk.PixbufLoader
object.Creates a new gtk.gdk.PixbufLoader
object. If image_type is not specified or is
None the image type will be automatically deduced from
the image data. If image_type is specified the gtk.gdk.PixbufLoader
attempts to parse the image data as if it were an image of the specified
type. Identifying the image type is useful if you want an error if the image
isn't the expected type, for loading image formats that can't be reliably
identified by looking at the data, or if the user manually forces a specific
type.This constructor raises the GError exception if an error occurs
trying to load the module for image_type.Methodsgtk.gdk.PixbufLoader.writewritebufcount-1buf :a string containing some portion of the image
data.count :the length of buf in
bytes.Returns :True if the write was
successful.The write() method causes the pixbuf
loader to parse the bytes of an image contained in the string specified by
buf. If count is specified and
is in the range (0, len(buf)) only count bytes of
buf are used. This method returns
True if the image data was loaded successfully. If an
error occurred this method raises the GError exception and will not accept
further writes. The loader may or may not be closed depending on the
error.gtk.gdk.PixbufLoader.get_pixbufget_pixbufReturns :the gtk.gdk.Pixbuf that
the loader is creating, or None if not enough data has
been read to determine how to create the image buffer.The get_pixbuf() method returns the
gtk.gdk.Pixbuf
that a pixbuf loader is currently creating. In general it only makes sense
to call this method after the "area-prepared" signal has been emitted by
the loader which means that enough data has been read to know the size of
the image that will be allocated. If the loader has not received enough data
via the write()
method, this method returns None. The same pixbuf will be
returned in all future calls to this method. Also, if the loader is an
animation, it will return the "static image" of the animation (see the gtk.gdk.PixbufAnimation.get_static_image()
method).gtk.gdk.PixbufLoader.get_animationget_animationReturns :the gtk.gdk.PixbufAnimation
that the loader is loading, or None if not enough data
has been read to determine the information.The get_animation() method returns the
gtk.gdk.PixbufAnimation
that the pixbuf loader is currently creating. In general it only makes sense
to call this method after the "area-prepared" signal has been emitted by the
loader. If the loader doesn't have enough bytes yet (hasn't emitted the
"area-prepared" signal) this method will return
None.gtk.gdk.PixbufLoader.closecloseReturns :True if all image data
written so far was successfully passed out via the "area_update"
signalThe close() method informs the pixbuf
loader that no further writes using the write()
will occur, so that it can free its internal loading structures. Also, the
pixbuf loader tries to parse any data that hasn't yet been parsed and if the
remaining data is partial or corrupt, the GError exception will be
raised.gtk.gdk.PixbufLoader.set_sizeset_sizewidthheightwidth :The desired width for the image being
loaded.height :The desired height for the image being
loaded.This method is available in PyGTK 2.4 and above.The set_size() method causes the image
to be scaled to the size specified by width and
height while it is being loaded. The desired image
size can be determined relative to the original size of the image by calling
the set_size()
from a signal handler for the "size-prepared"
signal.Attempts to set the desired image size are ignored after the
emission of the "size-prepared".gtk.gdk.PixbufLoader.get_formatget_formatReturns :a Python dict containing the image format
information or NoneThis method is available in PyGTK 2.4 and above.The get_format() method returns the
available information about the format of the currently loading image
file. This method returns None if their is no information available
e.g. before the image has started loading.Functionsgtk.gdk.pixbuf_loader_new_with_mime_typegtk.gdk.pixbuf_loader_new_with_mime_typemime_typemime_type : the mime type to be loadedReturns :a new gtk.gdk.PixbufLoader
object.This function is available in PyGTK 2.4 and above.The
gtk.gdk.pixbuf_loader_new_with_mime_type() function
creates a new pixbuf loader object that always attempts to parse image data
as if it were an image of the mime type specified by
mime_type, instead of identifying the type
automatically. Useful if you want an error if the image isn't the expected
mime type, for loading image formats that can't be reliably identified by
looking at the data, or if the user manually forces a specific mime
type.This function raises the GError exception if an error occurs
during the loading of the mime type image module.SignalsThe "area-prepared" gtk.gdk.PixbufLoader Signalcallbackpixbufloaderuser_param1...pixbufloader :the pixbufloader that received the
signaluser_param1 :the first user parameter (if any) specified
with the connect()
method... :additional user parameters (if
any)The "area-prepared" signal is emitted when sufficient image data
has been received and parsed to determine the size of the image.The "area-updated" gtk.gdk.PixbufLoader Signalcallbackpixbufloaderxywidthheightuser_param1...pixbufloader :the pixbufloader that received the
signalx :the X coordinate of the
regiony :the Y coordinate of the
regionwidth :the width of the regionheight :the height of the regionuser_param1 :the first user parameter (if any) specified
with the connect()
method... :additional user parameters (if
any)The "area-updated" signal is emitted when sufficient image data
has been received and parsed to allow the region specified by
x, y,
width and height to be
displayed.The "closed" gtk.gdk.PixbufLoader Signalcallbackpixbufloaderuser_param1...pixbufloader :the pixbufloader that received the
signaluser_param1 :the first user parameter (if any) specified
with the connect()
method... :additional user parameters (if
any)The "closed" signal is emitted when the
pixbufloader is closed by calling the close()
method.The "size-prepared" gtk.gdk.PixbufLoader Signalcallbackpixbufloaderwidthheightuser_param1...pixbufloader :the pixbufloader that received the
signalwidth :the original width of the
imageheight :he original height of the
imageuser_param1 :the first user parameter (if any) specified
with the connect()
method... :additional user parameters (if
any)This signal is available in GTK+ 2.2 and above.The "size-prepared" signal is emitted when the pixbuf loader has
been fed the initial amount of data that is required to figure out the size
of the image that it will create. Applications can call the set_size()
method in response to this signal to set the desired size of the
image.