Class: Gtk::IconTheme

Inherits:
Object
  • Object
show all
Extended by:
GLib::Deprecatable
Defined in:
lib/gtk3/deprecated.rb,
lib/gtk3/icon-theme.rb

Overview

GtkIconTheme provides a facility for loading themed icons.

The main reason for using a name rather than simply providing a filename
is to allow different icons to be used depending on what “icon theme” is
selected by the user. The operation of icon themes on Linux and Unix
follows the Icon Theme Specification
There is a fallback icon theme, named hicolor, where applications
should install their icons, but additional icon themes can be installed
as operating system vendors and users choose.

In many cases, named themes are used indirectly, via [classGtk.Image]
rather than directly, but looking up icons directly is also simple. The
GtkIconTheme object acts as a database of all the icons in the current
theme. You can create new GtkIconTheme objects, but it’s much more
efficient to use the standard icon theme of the GtkWidget so that the
icon information is shared with other people looking up icons.

GtkIconTheme *icon_theme;
GtkIconPaintable *icon;
GdkPaintable *paintable;

icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (my_widget));
icon = gtk_icon_theme_lookup_icon (icon_theme,
                                   "my-icon-name", // icon name
                                   48, // icon size
                                   1,  // scale
                                   0,  // flags);
paintable = GDK_PAINTABLE (icon);
// Use the paintable
g_object_unref (icon);

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGtk::IconTheme

Creates a new icon theme object.

Icon theme objects are used to lookup up an icon by name
in a particular icon theme. Usually, you’ll want to use
[funcGtk.IconTheme.get_for_display] rather than creating
a new icon theme object for scratch.

Class Method Details

.get_for_display(display) ⇒ Gtk::IconTheme

Gets the icon theme object associated with display.

If this function has not previously been called for the given
display, a new icon theme object will be created and associated
with the display. Icon theme objects are fairly expensive to create,
so using this function is usually a better choice than calling
[ctorGtk.IconTheme.new] and setting the display yourself; by using
this function a single icon theme object will be shared between users.

Parameters:

Returns:

  • (Gtk::IconTheme)

    A unique GtkIconTheme associated with
    the given display. This icon theme is associated with the display
    and can be used as long as the display is open. Do not ref or unref it.

Instance Method Details

#add_resource_path(path) ⇒ nil

Adds a resource path that will be looked at when looking
for icons, similar to search paths.

See [methodGtk.IconTheme.set_resource_path].

This function should be used to make application-specific icons
available as part of the icon theme.

Parameters:

  • path (String)

    a resource path

Returns:

  • (nil)

#add_search_path(path) ⇒ nil

Appends a directory to the search path.

See [methodGtk.IconTheme.set_search_path].

Parameters:

  • path (Gtk::filename)

    directory name to append to the icon path

Returns:

  • (nil)

#choose_icon(icon_names, size, flags = nil) ⇒ Object



20
21
22
23
24
# File 'lib/gtk3/icon-theme.rb', line 20

def choose_icon(icon_names, size, flags=nil)
  icon_names = [icon_names] unless icon_names.is_a?(Array)
  flags ||= 0
  choose_icon_raw(icon_names, size, flags)
end

#choose_icon_rawObject



19
# File 'lib/gtk3/icon-theme.rb', line 19

alias_method :choose_icon_raw, :choose_icon

#displayGdk::Display

The display that this icon theme object is attached to.

Returns:

#display=(display) ⇒ Gdk::Display

The display that this icon theme object is attached to.

Parameters:

Returns:

#get_icon_sizes(icon_name) ⇒ Array<Integer>

Returns an array of integers describing the sizes at which
the icon is available without scaling.

A size of -1 means that the icon is available in a scalable
format. The array is zero-terminated.

Parameters:

  • icon_name (String)

    the name of an icon

Returns:

  • (Array<Integer>)

    A newly
    allocated array describing the sizes at which the icon is
    available. The array should be freed with g_free() when it is no
    longer needed.

#has_gicon(gicon) ⇒ Boolean

Checks whether an icon theme includes an icon
for a particular GIcon.

Parameters:

  • gicon (Gio::Icon)

    a GIcon

Returns:

  • (Boolean)

    true if self includes an icon for gicon

#has_icon(icon_name) ⇒ Boolean

Checks whether an icon theme includes an icon
for a particular name.

Parameters:

  • icon_name (String)

    the name of an icon

Returns:

  • (Boolean)

    true if self includes an
    icon for icon_name.

#icon_namesGtk::

The icon names that are supported by the icon theme.

Returns:

#icon_names=(icon_names) ⇒ Gtk::

The icon names that are supported by the icon theme.

Parameters:

Returns:

#lookup_by_gicon(icon, size, scale, direction, flags) ⇒ Gtk::IconPaintable

Looks up a icon for a desired size and window scale.

The icon can then be rendered by using it as a GdkPaintable,
or you can get information such as the filename and size.

Parameters:

  • icon (Gio::Icon)

    the GIcon to look up

  • size (Integer)

    desired icon size

  • scale (Integer)

    the desired scale

  • direction (Gtk::TextDirection)

    text direction the icon will be displayed in

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:

  • (Gtk::IconPaintable)

    a GtkIconPaintable containing
    information about the icon. Unref with g_object_unref()

#lookup_icon(icon, size, flags = nil) ⇒ Gtk::IconPaintable

Looks up a named icon for a desired size and window scale,
returning a GtkIconPaintable.

The icon can then be rendered by using it as a GdkPaintable,
or you can get information such as the filename and size.

If the available icon_name is not available and fallbacks are
provided, they will be tried in order.

If no matching icon is found, then a paintable that renders the
"missing icon" icon is returned. If you need to do something else
for missing icons you need to use [methodGtk.IconTheme.has_icon].

Note that you probably want to listen for icon theme changes and
update the icon. This is usually done by overriding the
GtkWidgetClass.css-changed() function.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • fallbacks (Array<String>)
  • size (Integer)

    desired icon size.

  • scale (Integer)

    the window scale this will be displayed on

  • direction (Gtk::TextDirection)

    text direction the icon will be displayed in

  • flags (Gtk::IconLookupFlags) (defaults to: nil)

    flags modifying the behavior of the icon lookup

Returns:



27
28
29
30
31
32
33
34
35
36
# File 'lib/gtk3/icon-theme.rb', line 27

def lookup_icon(icon, size, flags=nil)
  case icon
  when String, Symbol
    flags ||= :generic_fallback
    lookup_icon_raw(icon.to_s, size, flags)
  else
    flags ||= 0
    lookup_by_gicon(icon, size, flags)
  end
end

#lookup_icon_rawGtk::IconPaintable

Looks up a named icon for a desired size and window scale,
returning a GtkIconPaintable.

The icon can then be rendered by using it as a GdkPaintable,
or you can get information such as the filename and size.

If the available icon_name is not available and fallbacks are
provided, they will be tried in order.

If no matching icon is found, then a paintable that renders the
"missing icon" icon is returned. If you need to do something else
for missing icons you need to use [methodGtk.IconTheme.has_icon].

Note that you probably want to listen for icon theme changes and
update the icon. This is usually done by overriding the
GtkWidgetClass.css-changed() function.

Parameters:

  • icon_name (String)

    the name of the icon to lookup

  • fallbacks (Array<String>)
  • size (Integer)

    desired icon size.

  • scale (Integer)

    the window scale this will be displayed on

  • direction (Gtk::TextDirection)

    text direction the icon will be displayed in

  • flags (Gtk::IconLookupFlags)

    flags modifying the behavior of the icon lookup

Returns:



# File 'lib/gtk3/icon-theme.rb', line 26

#resource_pathGtk::

Resource paths that will be looked at when looking for icons,
similar to search paths.

The resources are considered as part of the hicolor icon theme
and must be located in subdirectories that are defined in the
hicolor icon theme, such as <b>path</b>/16x16/actions/run.png.
Icons that are directly placed in the resource path instead
of a subdirectory are also considered as ultimate fallback.

Returns:

  • (Gtk::)

    resource-path

#resource_path=(resource_path) ⇒ Gtk::

Resource paths that will be looked at when looking for icons,
similar to search paths.

The resources are considered as part of the hicolor icon theme
and must be located in subdirectories that are defined in the
hicolor icon theme, such as <b>path</b>/16x16/actions/run.png.
Icons that are directly placed in the resource path instead
of a subdirectory are also considered as ultimate fallback.

Parameters:

Returns:

  • (Gtk::)

    resource-path

  • (Gtk::)

    resource-path

#search_pathGtk::

The search path for this icon theme.

When looking for icons, GTK will search for a subdirectory of
one or more of the directories in the search path with the same
name as the icon theme containing an index.theme file. (Themes
from multiple of the path elements are combined to allow themes
to be extended by adding icons in the user’s home directory.)

Returns:

  • (Gtk::)

    search-path

#search_path=(search_path) ⇒ Gtk::

The search path for this icon theme.

When looking for icons, GTK will search for a subdirectory of
one or more of the directories in the search path with the same
name as the icon theme containing an index.theme file. (Themes
from multiple of the path elements are combined to allow themes
to be extended by adding icons in the user’s home directory.)

Parameters:

Returns:

#theme_nameString

The name of the icon theme that is being used.

Unless set to a different value, this will be the value of
the GtkSettings:gtk-icon-theme-name property of the GtkSettings
object associated to the display of the icontheme object.

Returns:

  • (String)

    theme-name

#theme_name=(theme_name) ⇒ String

The name of the icon theme that is being used.

Unless set to a different value, this will be the value of
the GtkSettings:gtk-icon-theme-name property of the GtkSettings
object associated to the display of the icontheme object.

Parameters:

  • theme_name (String)

Returns:

  • (String)

    theme-name

  • (String)

    theme-name