Icons & Images¶
Provides methods for convenient icons and image handling
Icon management¶
- xlgui.icons.MANAGER¶
Singleton instance of the IconManager
- class xlgui.icons.IconManager¶
Provides convenience functions for managing icons and images in general
- add_icon_name_from_directory(icon_name, directory)¶
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
- add_icon_name_from_file(icon_name, filename, size=None)¶
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)¶
Registers an icon name from a pixbuf
Parameters: - icon_name (string) – the name for the icon
- pixbuf (gtk.gdk.Pixbuf) – the pixbuf of an image
- size (int) – the size the icon shall be registered for
- add_stock_from_directory(stock_id, directory)¶
Registers a stock icon from files found in a directory
Parameters: - stock_id (string) – the stock id for the icon
- directory (string) – the location to search for icons
- add_stock_from_file(stock_id, filename)¶
Registers a stock icon from a filename
Parameters: - stock_id (string) – the stock id for the icon
- filename (string) – the filename of an image
- add_stock_from_files(stock_id, filenames)¶
Registers a stock icon from filenames
Parameters: - stock_id (string) – the stock id for the icon
- filenames (list of string) – the filenames of images
- add_stock_from_pixbuf(stock_id, pixbuf)¶
Registers a stock icon from a pixbuf
Parameters: - stock_id (string) – the stock id for the icon
- pixbuf (gtk.gdk.Pixbuf) – the pixbuf of an image
- add_stock_from_pixbufs(stock_id, pixbufs)¶
Registers a stock icon from pixbufs
Parameters: - stock_id (string) – the stock id for the icon
- pixbuf (list of gtk.gdk.Pixbuf) – the pixbufs of images
- pixbuf_from_data(data, size=None, keep_ratio=True, upscale=False)¶
Generates a pixbuf from arbitrary image data
Parameters: - data (byte) – The raw image data
- size (tuple of int) – Size to scale to; if not specified, the image will render to its native size
- keep_ratio (bool) – Whether to keep the original image ratio on resizing operations
- upscale (bool) – Whether to upscale if the requested size exceeds the native size
Returns: the generated pixbuf
Return type: gtk.gdk.Pixbuf or None
- pixbuf_from_icon_name(icon_name, size=<class 'mocks.ICON_SIZE_BUTTON'>)¶
Generates a pixbuf from an icon name
Parameters: - stock_id (string) – an icon name
- size (int or GtkIconSize) – the size of the icon, will be tried to converted to a GTK icon size
Returns: the generated pixbuf
Return type: gtk.gdk.Pixbuf or None
- pixbuf_from_rating(*args, **kwargs)¶
Returns a pixbuf representing a rating
Parameters: rating (int) – the rating Returns: the rating pixbuf Return type: gtk.gdk.Pixbuf
- pixbuf_from_stock(stock_id, size=<class 'mocks.ICON_SIZE_BUTTON'>)¶
Generates a pixbuf from a stock id
Parameters: - stock_id (string) – a stock id
- size (GtkIconSize) – the size of the icon
Returns: the generated pixbuf
Return type: gtk.gdk.Pixbuf or None
- pixbuf_from_text(text, size, background_color='#456eac', border_color='#000', text_color='#fff')¶
Generates a pixbuf based on a text, width and height
Parameters: - size (tuple of int) – A tuple describing width and height
- background_color (string) – The color of the background as hexadecimal value
- border_color (string) – The color of the border as hexadecimal value
- text_color (string) – The color of the text as hexadecimal value
Utilities¶
- class xlgui.icons.ExtendedPixbuf(pixbuf)¶
A gtk.gdk.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)¶
Horizontally appends a pixbuf to the current
Parameters: - other (gtk.gdk.Pixbuf) – the pixbuf to append
- spacing (int) – amount of pixels between the pixbufs
Returns: a new pixbuf
Return type:
- add_vertical(other, spacing=0)¶
Vertically appends a pixbuf to the current
Parameters: - other (gtk.gdk.Pixbuf) – the pixbuf to append
- spacing (int) – amount of pixels between the pixbufs
Returns: a new pixbuf
Return type:
- composite_simple(other)¶
Composites a pixbuf on the current pixbuf at the location (0, 0)
Parameters: other (gtk.gdk.Pixbuf) – the pixbuf to composite Returns: a new pixbuf Return type: ExtendedPixbuf
- move(offset_x, offset_y, resize=False)¶
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:
- multiply_horizontal(multiplier, spacing=0)¶
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:
- multiply_vertical(multiplier, spacing=0)¶
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:
- xlgui.icons.extended_pixbuf_new_from_file(filename)¶
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