Gtk.IconFactory

g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.Object GObject.Object Gtk.IconFactory Gtk.IconFactory GObject.Object->Gtk.IconFactory Gtk.Buildable->Gtk.IconFactory

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gtk.Buildable (10)

Structs:

GObject.ObjectClass (5)

class

lookup_default (stock_id)

class

new ()

add (stock_id, icon_set)

add_default ()

lookup (stock_id)

remove_default ()

Virtual Methods

Inherited:

GObject.Object (7), Gtk.Buildable (10)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Gtk.IconFactory(**kwargs)
Bases:

GObject.Object, Gtk.Buildable

Abstract:

No

Structure:

Gtk.IconFactoryClass

An icon factory manages a collection of Gtk.IconSet; a Gtk.IconSet manages a set of variants of a particular icon (i.e. a Gtk.IconSet contains variants for different sizes and widget states). Icons in an icon factory are named by a stock ID, which is a simple string identifying the icon. Each Gtk.Style has a list of Gtk.IconFactory derived from the current theme; those icon factories are consulted first when searching for an icon. If the theme doesn’t set a particular icon, GTK+ looks for the icon in a list of default icon factories, maintained by Gtk.IconFactory.add_default() and Gtk.IconFactory.remove_default(). Applications with icons should add a default icon factory with their icons, which will allow themes to override the icons for the application.

To display an icon, always use Gtk.Style.lookup_icon_set() on the widget that will display the icon, or the convenience function Gtk.Widget.render_icon(). These functions take the theme into account when looking up the icon to use for a given stock ID.

Gtk.IconFactory as Gtk.Buildable

Gtk.IconFactory supports a custom <sources> element, which can contain multiple <source> elements. The following attributes are allowed:

  • stock-id

    The stock id of the source, a string. This attribute is mandatory

  • filename

    The filename of the source, a string. This attribute is optional

  • icon-name

    The icon name for the source, a string. This attribute is optional.

  • size

    Size of the icon, a Gtk.IconSize enum value. This attribute is optional.

  • direction

    Direction of the source, a Gtk.TextDirection enum value. This attribute is optional.

  • state

    State of the source, a Gtk.StateType enum value. This attribute is optional.

A Gtk.IconFactory UI definition fragment.
<object class="GtkIconFactory" id="iconfactory1">
  <sources>
    <source stock-id="apple-red" filename="apple-red.png"/>
  </sources>
</object>
<object class="GtkWindow" id="window1">
  <child>
    <object class="GtkButton" id="apple_button">
      <property name="label">apple-red</property>
      <property name="use-stock">True</property>
    </object>
  </child>
</object>
classmethod lookup_default(stock_id)[source]
Parameters:

stock_id (str) – an icon name

Returns:

a Gtk.IconSet, or None

Return type:

Gtk.IconSet

Looks for an icon in the list of default icon factories. For display to the user, you should use Gtk.Style.lookup_icon_set() on the Gtk.Style for the widget that will display the icon, instead of using this function directly, so that themes are taken into account.

Deprecated since version 3.10: Use Gtk.IconTheme instead.

classmethod new()[source]
Returns:

a new Gtk.IconFactory

Return type:

Gtk.IconFactory

Creates a new Gtk.IconFactory. An icon factory manages a collection of Gtk.IconSets; a Gtk.IconSet manages a set of variants of a particular icon (i.e. a Gtk.IconSet contains variants for different sizes and widget states). Icons in an icon factory are named by a stock ID, which is a simple string identifying the icon. Each Gtk.Style has a list of Gtk.IconFactorys derived from the current theme; those icon factories are consulted first when searching for an icon. If the theme doesn’t set a particular icon, GTK+ looks for the icon in a list of default icon factories, maintained by Gtk.IconFactory.add_default() and Gtk.IconFactory.remove_default(). Applications with icons should add a default icon factory with their icons, which will allow themes to override the icons for the application.

Deprecated since version 3.10: Use Gtk.IconTheme instead.

add(stock_id, icon_set)[source]
Parameters:

Adds the given icon_set to the icon factory, under the name stock_id. stock_id should be namespaced for your application, e.g. “myapp-whatever-icon”. Normally applications create a Gtk.IconFactory, then add it to the list of default factories with Gtk.IconFactory.add_default(). Then they pass the stock_id to widgets such as Gtk.Image to display the icon. Themes can provide an icon with the same name (such as “myapp-whatever-icon”) to override your application’s default icons. If an icon already existed in self for stock_id, it is unreferenced and replaced with the new icon_set.

Deprecated since version 3.10: Use Gtk.IconTheme instead.

add_default()[source]

Adds an icon factory to the list of icon factories searched by Gtk.Style.lookup_icon_set(). This means that, for example, Gtk.Image.new_from_stock() will be able to find icons in self. There will normally be an icon factory added for each library or application that comes with icons. The default icon factories can be overridden by themes.

Deprecated since version 3.10: Use Gtk.IconTheme instead.

lookup(stock_id)[source]
Parameters:

stock_id (str) – an icon name

Returns:

icon set of stock_id.

Return type:

Gtk.IconSet

Looks up stock_id in the icon factory, returning an icon set if found, otherwise None. For display to the user, you should use Gtk.Style.lookup_icon_set() on the Gtk.Style for the widget that will display the icon, instead of using this function directly, so that themes are taken into account.

Deprecated since version 3.10: Use Gtk.IconTheme instead.

remove_default()[source]

Removes an icon factory from the list of default icon factories. Not normally used; you might use it for a library that can be unloaded or shut down.

Deprecated since version 3.10: Use Gtk.IconTheme instead.