Icons & Images

Provides methods for convenient icons and image handling

Icon management

xlgui.icons.MANAGER

Singleton instance of the IconManager

class xlgui.icons.IconManager[source]

Provides convenience functions for managing icons and images in general

add_icon_name_from_directory(icon_name, directory)[source]

Registers an icon name from files found in a directory

Parameters:
  • icon_name (string) – the name for the icon
  • directory (string) – the location to search for icons
Returns:

filesystem location of the highest-quality icon of this name, or None if not found

Return type:

Optional[str]

add_icon_name_from_file(icon_name, filename, size=None)[source]

Registers an icon name from a filename

Parameters:
  • icon_name (string) – the name for the icon
  • filename (string) – the filename of an image
  • size (int) – the size the icon shall be registered for
add_icon_name_from_pixbuf(icon_name, pixbuf, size=None)[source]

Registers an icon name from a pixbuf

Parameters:
  • icon_name (string) – the name for the icon
  • pixbuf (GdkPixbuf.Pixbuf) – the pixbuf of an image
  • size (int) – the size the icon shall be registered for
pixbuf_from_icon_name()[source]

Generates a pixbuf from an icon name

Parameters:
  • icon_name – an icon name
  • size – the size of the icon, will be tried to converted to a GTK icon size
Returns:

the generated pixbuf

pixbuf_from_rating(rating, size_ratio=1)[source]

Returns a pixbuf representing a rating

Parameters:rating (int) – the rating
Returns:the rating pixbuf
Return type:GdkPixbuf.Pixbuf

Utilities

class xlgui.icons.ExtendedPixbuf(pixbuf)[source]

A GdkPixbuf.Pixbuf wrapper class allowing for interaction using standard operators

Thus you can do the following:

  • pixbuf1 + pixbuf2 (horizontally appends pixbuf2 to pixbuf1)
  • pixbuf * 5 (multiplies the content of pixbuf)
  • pixbuf1 & pixbuf2 (simple composition of pixbuf2 on pixbuf1, the desired alpha value has to be included in the pixbufs themselves)
  • pixbuf1 < pixbuf2, pixbuf1 > pixbuf2 (compares the pixbuf dimensions)
  • pixbuf1 == pixbuf2 (compares the pixel data, use the is operator to check for identity)

Even more is possible with the provided verbose methods

add_horizontal(other, spacing=0)[source]

Horizontally appends a pixbuf to the current

Parameters:
  • other (GdkPixbuf.Pixbuf) – the pixbuf to append
  • spacing (int) – amount of pixels between the pixbufs
Returns:

a new pixbuf

Return type:

ExtendedPixbuf

add_vertical(other, spacing=0)[source]

Vertically appends a pixbuf to the current

Parameters:
  • other (GdkPixbuf.Pixbuf) – the pixbuf to append
  • spacing (int) – amount of pixels between the pixbufs
Returns:

a new pixbuf

Return type:

ExtendedPixbuf

composite_simple(other)[source]

Composites a pixbuf on the current pixbuf at the location (0, 0)

Parameters:other (GdkPixbuf.Pixbuf) – the pixbuf to composite
Returns:a new pixbuf
Return type:ExtendedPixbuf
move(offset_x, offset_y, resize=False)[source]

Moves the content of the current pixbuf within its boundaries (clips overlapping data) and optionally resizes the pixbuf to contain the movement

Parameters:
  • offset_x (int) – the amount of pixels to move in horizontal direction
  • offset_y (int) – the amount of pixels to move in vertical direction
  • resize (bool) – whether to resize the pixbuf on movement
Returns:

a new pixbuf

Return type:

ExtendedPixbuf

multiply_horizontal(multiplier, spacing=0)[source]

Horizontally multiplies the current pixbuf content

Parameters:
  • multiplier (int) – How often the pixbuf shall be multiplied
  • spacing (int) – amount of pixels between the pixbufs
Returns:

a new pixbuf

Return type:

ExtendedPixbuf

multiply_vertical(multiplier, spacing=0)[source]

Vertically multiplies the current pixbuf content

Parameters:
  • multiplier (int) – How often the pixbuf shall be multiplied
  • spacing (int) – amount of pixels between the pixbufs
Returns:

a new pixbuf

Return type:

ExtendedPixbuf

xlgui.icons.extended_pixbuf_new_from_file(filename)[source]

Returns a new ExtendedPixbuf containing an image loaded from the specified file

Parameters:filename (string) – the name of the file containing the image to load
Returns:a new pixbuf
Return type:ExtendedPixbuf