gtk.IconSet
Prev | The gtk Class Reference | Next

## gtk.IconSet

gtk.IconSet — contains a set of variants for an icon

## Synopsis

    class gtk.IconSet(gobject.GBoxed):
        gtk.IconSet(pixbuf=None)
        def copy()
        def render_icon(style, direction, state, size, widget, detail)
        def add_source(source)
        def get_sizes()

## Description

A `gtk.IconSet` contains a set of variants for a single icon. The variants provide icons of different sizes and for different widget states. The variants can be added with the `add_source`() method.

## Constructor

        gtk.IconSet(pixbuf=None)

`pixbuf` : | a `gtk.gdk.Pixbuf`
Returns : | a new `gtk.IconSet`

Creates a new `gtk.IconSet` with `pixbuf` as the default fallback source image. If `pixbuf` is `None` there is no default fallback source image. If you don't add any additional `gtk.IconSource`s to the icon set, all variants of the icon will be created from `pixbuf`, using scaling, pixelation, etc. as required to adjust the icon size or make the icon look insensitive/prelighted.

## Methods

### gtk.IconSet.copy

        def copy()

Returns : | a new `gtk.IconSet` identical to the first.

The `copy`() method returns a copy of the icon set.

### gtk.IconSet.render_icon

        def render_icon(style, direction, state, size, widget, detail)

`style` : | a `gtk.Style` associated with `widget`, or `None`
`direction` : | the text direction; one of: `gtk.TEXT_DIR_NONE`, `gtk.TEXT_DIR_LTR`, `gtk.TEXT_DIR_RTL`
`state` : | the widget state; one of: `gtk.STATE_NORMAL`, `gtk.STATE_ACTIVE`, `gtk.STATE_PRELIGHT`, `gtk.STATE_SELECTED`, `gtk.STATE_INSENSITIVE`
`size` : | the icon size; one of: `gtk.ICON_SIZE_INVALID`, `gtk.ICON_SIZE_MENU`, `gtk.ICON_SIZE_SMALL_TOOLBAR`, `gtk.ICON_SIZE_LARGE_TOOLBAR`, `gtk.ICON_SIZE_BUTTON`, `gtk.ICON_SIZE_DND`, `gtk.ICON_SIZE_DIALOG`
`widget` : | the widget that will display the icon, or `None`
`detail` : | the detail to pass to the theme engine, or `None`
Returns : | a `gtk.gdk.Pixbuf` to be displayed

The `render_icon`() method renders an icon using `gtk.Style.render_icon()`. In most cases, `gtk.Widget.render_icon()` is better, since it automatically provides most of the arguments from the current widget settings. This method never returns `None`; if the icon can't be rendered (perhaps because an image file fails to load), a default "missing image" icon will be returned instead.

### gtk.IconSet.add_source

        def add_source(source)

`source` : | a `gtk.IconSource`

The `add_source`() method adds the `gtk.IconSource` specified by `source` to the icon set. Icon sets have a list of `gtk.IconSource`, which they use as base icons for rendering icons in different states and sizes. Icons are scaled, made to look insensitive, etc. in the `render_icon`() method, but `gtk.IconSet` needs base images to work with. The base images and when to use them are described by a `gtk.IconSource`.

An example of when you'd use this method: a web browser's "Back to Previous Page" icon might point in a different direction in Hebrew and in English; it might look different when insensitive; and it might change size depending on toolbar mode (small or large icons). So a single icon set would contain all those variants of the icon, and you might add a separate source for each one.

You should nearly always add a "default" icon source with all fields wildcarded, which will be used as a fallback if no more specific source matches. `gtk.IconSet` always prefers more specific icon sources to more generic icon sources. The order in which you add the sources to the icon set does not matter.

The `gtk.IconSet`() constructor creates a new icon set with a default icon source based on the given pixbuf.

### gtk.IconSet.get_sizes

        def get_sizes()

Returns : | a tuple containing all the icon sizes supported by the icon set

The `get_sizes`() method returns a tuple containing all the icon sizes this icon set can render.

Prev | Up | Next
gtk.IconInfo | Home | gtk.IconSource