Loader#

Added in version 2.0.

class Loader(**properties: Any)#

Superclasses: Object

Loader prepares loading an image.

The following example shows how to obtain a Gdk.Texture. It uses GlyGtk4 for this.

#include <glycin-gtk4.h>

file = g_file_new_for_path ("test.png");
loader = gly_loader_new (file);
image = gly_loader_load (loader, NULL);
if (image)
  {
    frame = gly_image_next_frame (image, NULL);
    if (frame)
      {
        texture = gly_gtk_frame_get_texture (frame);
        g_print ("Image height: %d\n", gdk_texture_get_height (texture));
        image_widget = gtk_image_new_from_paintable (GDK_PAINTABLE (texture));
      }
  }

Constructors#

class Loader
classmethod new(file: File) Loader#

Creates a new loader for a file.

Added in version 2.0.

Parameters:

file – A file from which to load the image data

classmethod new_for_bytes(bytes: Bytes) Loader#

Creates a new loader for bytes.

Added in version 2.0.

Parameters:

bytes – Data from which to load the image

classmethod new_for_stream(stream: InputStream) Loader#

Creates a new loader for a stream.

Added in version 2.0.

Parameters:

stream – A stream from which to load the image data

Methods#

class Loader
classmethod get_mime_types() list[str]#

Returns a list of MIME types currently supported for loading images.

This list is generated from the config on first use of a loader or call of this function and cached afterwards. Hence, the first call can be blocking.

Added in version 2.0.

classmethod get_mime_types_async(callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Async variant of get_mime_types

Added in version 2.0.

Parameters:
  • callback

  • user_data – user data to pass to callback

classmethod get_mime_types_finish() list[str]#

Finishes the get_mime_types_async call.

Added in version 2.0.

load() Image#

Synchronously loads an image and returns an Image when successful.

Added in version 2.0.

async load_async(self) Image#

This is the awaitable version of load_async().

Added in version 2.0.

load_async(cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronous version of load.

Added in version 2.0.

Parameters:
  • cancellable – A Cancellable to cancel the operation

  • callback – A callback to call when the operation is complete

  • user_data – Data to pass to callback

load_finish(result: AsyncResult) Image#

Finishes the load_async call.

Added in version 2.0.

Parameters:

result – A GAsyncResult

set_accepted_memory_formats(memory_format_selection: MemoryFormatSelection) None#

Sets which memory formats can be returned by the loader

If the memory format doesn’t match one of the selected formats, the format will be transformed into the best suitable format selected.

Added in version 2.0.

Parameters:

memory_format_selection – Accepted memory formats

set_apply_transformations(apply_transformations: bool) None#

Set whether to apply transformations to texture

When enabled, transformations like image orientation are applied to the texture data.

This option is enabled by default.

Added in version 2.0.

Parameters:

apply_transformations

set_sandbox_selector(sandbox_selector: SandboxSelector) None#

Selects which sandbox mechanism should be used. The default without calling this function is SandboxSelector``.AUTO``.

Added in version 2.0.

Parameters:

sandbox_selector – Method by which the sandbox mechanism is selected

Properties#

class Loader
props.apply_transformation: bool#

The type of the None singleton.

props.bytes: Bytes#

The type of the None singleton.

props.cancellable: Cancellable#

The type of the None singleton.

props.file: File#

The type of the None singleton.

props.memory_format_selection: MemoryFormatSelection#

The type of the None singleton.

props.sandbox_selector: SandboxSelector#

The type of the None singleton.

props.stream: InputStream#

The type of the None singleton.