GdkPixbuf.PixbufLoader

g GObject.Object GObject.Object GdkPixbuf.PixbufLoader GdkPixbuf.PixbufLoader GObject.Object->GdkPixbuf.PixbufLoader

Subclasses:None

Methods

Inherited:GObject.Object (37)
Structs:GObject.ObjectClass (5)
class new ()
class new_with_mime_type (mime_type)
class new_with_type (image_type)
  close ()
  get_animation ()
  get_format ()
  get_pixbuf ()
  set_size (width, height)
  write (buf)
  write_bytes (buffer)

Virtual Methods

Inherited:GObject.Object (7)
  do_area_prepared ()
  do_area_updated (x, y, width, height)
  do_closed ()
  do_size_prepared (width, height)

Properties

None

Signals

Inherited:GObject.Object (1)
Name Short Description
area-prepared This signal is emitted when the pixbuf loader has allocated the pixbuf in the desired size.
area-updated This signal is emitted when a significant area of the image being loaded has been updated.
closed This signal is emitted when GdkPixbuf.PixbufLoader.close() is called.
size-prepared This 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.

Fields

Inherited:GObject.Object (1)
Name Type Access Description
parent_instance GObject.Object r  
priv object r  

Class Details

class GdkPixbuf.PixbufLoader(**kwargs)
Bases:GObject.Object
Abstract:No
Structure:GdkPixbuf.PixbufLoaderClass

The GdkPixbuf.PixbufLoader struct contains only private fields.

classmethod new()[source]
Returns:A newly-created pixbuf loader.
Return type:GdkPixbuf.PixbufLoader

Creates a new pixbuf loader object.

classmethod new_with_mime_type(mime_type)[source]
Parameters:mime_type (str) – the mime type to be loaded
Raises:GLib.Error
Returns:A newly-created pixbuf loader.
Return type:GdkPixbuf.PixbufLoader

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of mime type 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.

The list of supported mime types depends on what image loaders are installed, but typically “image/png”, “image/jpeg”, “image/gif”, “image/tiff” and “image/x-xpixmap” are among the supported mime types. To obtain the full list of supported mime types, call GdkPixbuf.PixbufFormat.get_mime_types() on each of the GdkPixbuf.PixbufFormat structs returned by GdkPixbuf.Pixbuf.get_formats().

New in version 2.4.

classmethod new_with_type(image_type)[source]
Parameters:image_type (str) – name of the image format to be loaded with the image
Raises:GLib.Error
Returns:A newly-created pixbuf loader.
Return type:GdkPixbuf.PixbufLoader

Creates a new pixbuf loader object that always attempts to parse image data as if it were an image of type image_type, instead of identifying the type automatically. 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.

The list of supported image formats depends on what image loaders are installed, but typically “png”, “jpeg”, “gif”, “tiff” and “xpm” are among the supported formats. To obtain the full list of supported image formats, call GdkPixbuf.PixbufFormat.get_name() on each of the GdkPixbuf.PixbufFormat structs returned by GdkPixbuf.Pixbuf.get_formats().

close()[source]
Raises:GLib.Error
Returns:True if all image data written so far was successfully passed out via the update_area signal
Return type:bool

Informs a pixbuf loader that no further writes with GdkPixbuf.PixbufLoader.write() will occur, so that it can free its internal loading structures. Also, tries to parse any data that hasn’t yet been parsed; if the remaining data is partial or corrupt, an error will be returned. If False is returned, error will be set to an error from the #GDK_PIXBUF_ERROR or #G_FILE_ERROR domains. If you’re just cancelling a load rather than expecting it to be finished, passing None for error to ignore it is reasonable.

Remember that this does not unref the loader, so if you plan not to use it anymore, please GObject.Object.unref() it.

get_animation()[source]
Returns:The GdkPixbuf.PixbufAnimation that the loader is loading, or None if not enough data has been read to determine the information.
Return type:GdkPixbuf.PixbufAnimation

Queries the GdkPixbuf.PixbufAnimation that a pixbuf loader is currently creating. In general it only makes sense to call this function 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 function will return None.

get_format()[source]
Returns:A GdkPixbuf.PixbufFormat or None. The return value is owned by GdkPixbuf.Pixbuf and should not be freed.
Return type:GdkPixbuf.PixbufFormat or None

Obtains the available information about the format of the currently loading image file.

New in version 2.2.

get_pixbuf()[source]
Returns:The GdkPixbuf.Pixbuf that the loader is creating, or None if not enough data has been read to determine how to create the image buffer.
Return type:GdkPixbuf.Pixbuf

Queries the GdkPixbuf.Pixbuf that a pixbuf loader is currently creating. In general it only makes sense to call this function after the “area-prepared” signal has been emitted by the loader; this 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 GdkPixbuf.PixbufLoader.write(), then this function returns None. The returned pixbuf will be the same in all future calls to the loader, so simply calling GObject.Object.ref() should be sufficient to continue using it. Additionally, if the loader is an animation, it will return the “static image” of the animation (see GdkPixbuf.PixbufAnimation.get_static_image()).

set_size(width, height)[source]
Parameters:
  • width (int) – The desired width of the image being loaded.
  • height (int) – The desired height of the image being loaded.

Causes the image to be scaled while it is loaded. The desired image size can be determined relative to the original size of the image by calling GdkPixbuf.PixbufLoader.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 signal.

New in version 2.2.

write(buf)[source]
Parameters:buf (bytes) – Pointer to image data.
Raises:GLib.Error
Returns:True if the write was successful, or False if the loader cannot parse the buffer.
Return type:bool

This will cause a pixbuf loader to parse the next count bytes of an image. It will return True if the data was loaded successfully, and False if an error occurred. In the latter case, the loader will be closed, and will not accept further writes. If False is returned, error will be set to an error from the #GDK_PIXBUF_ERROR or #G_FILE_ERROR domains.

write_bytes(buffer)[source]
Parameters:buffer (GLib.Bytes) – The image data as a GLib.Bytes
Raises:GLib.Error
Returns:True if the write was successful, or False if the loader cannot parse the buffer.
Return type:bool

This will cause a pixbuf loader to parse a buffer inside a GLib.Bytes for an image. It will return True if the data was loaded successfully, and False if an error occurred. In the latter case, the loader will be closed, and will not accept further writes. If False is returned, error will be set to an error from the #GDK_PIXBUF_ERROR or #G_FILE_ERROR domains.

See also: GdkPixbuf.PixbufLoader.write()

New in version 2.30.

do_area_prepared() virtual
do_area_updated(x, y, width, height) virtual
Parameters:
do_closed() virtual
do_size_prepared(width, height) virtual
Parameters:
  • width (int) –
  • height (int) –

Signal Details

GdkPixbuf.PixbufLoader.signals.area_prepared(pixbuf_loader)
Signal Name:area-prepared
Flags:RUN_LAST
Parameters:pixbuf_loader (GdkPixbuf.PixbufLoader) – The object which received the signal

This signal is emitted when the pixbuf loader has allocated the pixbuf in the desired size. After this signal is emitted, applications can call GdkPixbuf.PixbufLoader.get_pixbuf() to fetch the partially-loaded pixbuf.

GdkPixbuf.PixbufLoader.signals.area_updated(pixbuf_loader, x, y, width, height)
Signal Name:

area-updated

Flags:

RUN_LAST

Parameters:
  • pixbuf_loader (GdkPixbuf.PixbufLoader) – The object which received the signal
  • x (int) – X offset of upper-left corner of the updated area.
  • y (int) – Y offset of upper-left corner of the updated area.
  • width (int) – Width of updated area.
  • height (int) – Height of updated area.

This signal is emitted when a significant area of the image being loaded has been updated. Normally it means that a complete scanline has been read in, but it could be a different area as well. Applications can use this signal to know when to repaint areas of an image that is being loaded.

GdkPixbuf.PixbufLoader.signals.closed(pixbuf_loader)
Signal Name:closed
Flags:RUN_LAST
Parameters:pixbuf_loader (GdkPixbuf.PixbufLoader) – The object which received the signal

This signal is emitted when GdkPixbuf.PixbufLoader.close() is called. It can be used by different parts of an application to receive notification when an image loader is closed by the code that drives it.

GdkPixbuf.PixbufLoader.signals.size_prepared(pixbuf_loader, width, height)
Signal Name:

size-prepared

Flags:

RUN_LAST

Parameters:
  • pixbuf_loader (GdkPixbuf.PixbufLoader) – The object which received the signal
  • width (int) – the original width of the image
  • height (int) – the original height of the image

This 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 GdkPixbuf.PixbufLoader.set_size() in response to this signal to set the desired size to which the image should be scaled.