[ruby-gnome2-doc-cvs] [Hiki] create - Gtk::IconTheme

Zurück zum Archiv-Index

ruby-****@sourc***** ruby-****@sourc*****
2005年 3月 7日 (月) 18:39:02 JST


-------------------------
REMOTE_ADDR = 202.96.19.49
REMOTE_HOST = 
REMOTE_USER = ruby-gnome2-hiki        URL = http://ruby-gnome2.sourceforge.jp/cgi-bin/hiki/hiki.cgi?Gtk%3A%3AIconTheme
-------------------------
TITLE       = Gtk::IconTheme
KEYWORD     = 
= class Gtk::IconTheme
Gtk::IconTheme provides a facility for looking up icons by name and size. It acts as a database of information about an icon theme. 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 selecetd by the user. The operation of icon themes on Linux and Unix follows the ((<Icon Theme Specification|URL:http://www.freedesktop.org/wiki/Standards_2ficon_2dtheme_2dspec>)). There is a default icon theme, named hicolor where applications should install their icons, but more additional application themes can be installed as operating system vendors and users choose. 

Named icons are similar to the Themeable Stock Images(Gtk::IconSource, Gtk::IconFactory, Gtk::IconSet) facility, and the distinction between the two may be a bit confusing. A few things to keep in mind: 

* Stock images usually are used in conjunction with Stock Items(Gtk::Stock), such as Gtk::Stock::OK or Gtk:Stock::OPEN. Named icons are easier to set up and therefore are more useful for new icons that an application wants to add, such as application icons or window icons. 

* Stock images can only be loaded at the symbolic sizes defined by the Gtk::IconSize constants(Gtk::IconSize::IconSize), or by custom sizes defined by Gtk::IconSize.register, while named icons are more flexible and any pixel size can be specified. 

* Because stock images are closely tied to stock items, and thus to actions in the user interface, stock images may come in multiple variants for different widget states or writing directions. 

A good rule of thumb is that if there is a stock image for what you want to use, use it, otherwise use a named icon. It turns out that internally stock images are generally defined in terms of one or more named icons. (An example of the more than one case is icons that depend on writing direction; Gtk::Stock::GO_FORWARD uses the two themed icons "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".) 

In many cases, named themes are used indirectly, via Gtk::Image or stock items, rather than directly, but looking up icons directly is also simple. The Gtk::IconTheme object acts as a database of all the icons in the current theme. You can create new Gtk::IconTheme objects, but its much more efficient to use the standard icon theme for the Gdk::Screen so that the icon information is shared with other people looking up icons. In the case where the default screen is being used, looking up an icon can be as simple as: 

  icon_theme = Gtk::IconTheme.default
  begin
    pixbuf = icon_theme.load_icon("gtk-stock-quit", # icon name
                                   48,              # size
                                    0)              # flags
  rescue RuntimeError => e
    puts "Couldn't load icon: #{e.message}"
  end


== Object Hierarchy
* Object
  * GLib::Instantiatable
    * GLib::Object
      * Gtk::IconTheme

== Class Methods
--- Gtk::IconTheme.new
    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 Gtk::IconTheme.default or Gtk::IconTheme.get_for_screen rather than creating a new icon theme object for scratch.
    * Returns: the newly created Gtk::IconTheme object.  

--- Gtk::IconTheme.default
    Gets the icon theme for the default screen. See Gtk::IconThem.get_for_screen.
    * Returns: A unique Gtk::IconTheme associated with the default screen. This icon theme is associated with the screen and can be used as long as the screen is open.  

--- Gtk::IconTheme.get_for_screen(screen)
    Gets the icon theme object associated with screen; if this function has not previously been called for the given screen, a new icon theme object will be created and associated with the screen. Icon theme objects are fairly expensive to create, so using this method is usually a better choice than calling than Gtk::IconTheme.new and setting the screen yourself; by using this method a single icon theme object will be shared between users.
    * screen: a Gdk::Screen  
    * Returns: A unique Gtk::IconTheme associated with the given screen. This icon theme is associated with the screen and can be used as long as the screen is open 

--- Gtk::IconTheme.add_builtin_icon(icon_name, size, pixbuf)
    Registers a built-in icon for icon theme lookups. The idea of built-in icons is to allow an application or library that uses themed icons to function requiring files to be present in the file system. For instance, the default images for all of GTK+'s stock icons are registered as built-icons. 
    In general, if you use Gtk::IconTheme.add_builtin_icon you should also install the icon in the icon theme, so that the icon is generally available. 
    This method will generally be used with pixbufs loaded via Gdk::Pixbuf.new(data, copy_pixels).
    * size: the size at which to register the icon (different images can be registered for the same icon name at different sizes.)  
    * pixbuf: Gdk::Pixbuf that contains the image to use for icon_name.
    * Returns: self

== Instance Methods
--- screen=(screen)
    Sets the screen for an icon theme; the screen is used to track the user's currently configured icon theme, which might be different for different screens.
    * screen: a Gdk::Screen
    * Returns: screen
--- set_screen(screen)
    Same as screen=.
    * screen: a Gdk::Screen
    * Returns: self

--- search_path
    Gets the current search path. See Gtk::IconTheme#search_path=.
    * Returns: an Array of icon theme path directories(String).
--- search_path=(paths)
    Sets the search path for the icon theme object. When looking for an icon theme, GTK+ will search for a subdirectory of one or more of the directories in path with the same name as the icon theme. (Themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user's home directory.) 
    In addition if an icon found isn't found either in the current icon theme or the default icon theme, and an image file with the right name is found directly in one of the elements of path, then that image will be used for the icon name. (This is legacy feature, and new icons should be put into the default icon theme, which is called DEFAULT_THEME_NAME, rather than directly on the icon path.)
    * paths: an Array of directories(String) that are searched for icon themes  
    * Returns: paths
--- set_search_path(paths)
    Same as search_path=.
    * paths: an Array of directories(String) that are searched for icon themes  
    * Returns: self

--- append_search_path(path)
    Appends a directory to the search path. See Gtk::IconTheme#search_path=.
    * path: A directory name(String) to append to the icon path  
    * Returns: self
--- prepend_search_path(path)
    Prepends a directory to the search path. See Gtk::IconTheme#search_path=.
    * path: A directory name(String) to append to the icon path  
    * Returns: self

--- custom_theme=(theme_name)
    Sets the name of the icon theme that the Gtk::IconTheme object uses overriding system configuration. This method cannot be called on the icon theme objects returned from Gtk::IconTheme.default and Gtk::IconTheme.get_for_screen(screen).
    * theme_name: name of icon theme to use instead of configured theme  
    * Returns: theme_name
--- set_custom_theme(theme_name)
    Same as custom_theme=.
    * theme_name: name of icon theme to use instead of configured theme  
    * Returns: self

--- has_icon?(icon_name)
    Checks whether an icon theme includes an icon for a particular name.
    * icon_name: the name of an icon  
    * Returns: true if icon_theme includes an icon for icon_name.  

--- lookup_icon(icon_name, size, flags)
    Looks up a named icon and returns a Gtk::IconInfo. The icon can then be rendered into a pixbuf using Gtk::IconInfo#load_icon. (Gtk::IconTheme#load_icon combines these two steps if all you need is the pixbuf.)
    * icon_name: the name of the icon to lookup  
    * size: desired icon size  
    * flags: flags modifying the behavior of the icon lookup ((<GtkIconLookupFlags|Gtk::IconTheme#GtkIconLookupFlags>))
    * Returns: a Gtk::IconInfo containing information about the icon, or nil if the icon wasn't found. 

--- load_icon(icon_name, flags)
    Looks up an icon in an icon theme, scales it to the given size and renders it into a pixbuf. This is a convenience method; if more details about the icon are needed, use Gtk::IconTheme#lookup_icon followed by Gtk::IconInfo#load_icon. Gtk::IconThemeError is raised if failure.
    * icon_name: the name of the icon to lookup  
    * size: the desired icon size. The resulting icon may not be exactly this size; see Gtk::IconInfo#load_icon.  
    * flags: flags modifying the behavior of the icon lookup ((<GtkIconLookupFlags|Gtk::IconTheme#GtkIconLookupFlags>))
    * Returns: the rendered icon or nil; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. 

--- icons(context = nil)
    Lists the icons in the current icon theme. Only a subset of the icons can be listed by providing a context string. The set of values for the context string is system dependent, but will typically include such values as 'apps' and 'mimetypes'.
    * context: a String identifying a particular type of icon, or nil to list all icons.  
    * Returns: an Array holding the names of all the icons in the theme.  

--- get_icon_sizes(icon_name)
    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.
    * icon_name: the name of an icon  
    * Returns: An Array describing the sizes at which the icon is available. 

--- example_icon_name
    Gets the name of an icon that is representative of the current theme (for instance, to use when presenting a list of themes to the user.)
    * Returns: the name of an example icon or nil

--- rescan_if_needed
    Checks to see if the icon theme has changed; if it has, any currently cached information is discarded and will be reloaded next time icon_theme is accessed.
    * Returns: true if the icon theme has changed and needed to be reloaded.  


== Constants
=== GtkIconLookupFlags 
Used to specify options for Gtk::IconTheme#lookup_icon.
--- LOOKUP_NO_SVG
    Never return SVG icons, even if gdk-pixbuf supports them. Cannot be used together with Gtk::IconTheme::LOOKUP_FORCE_SVG. 
--- LOOKUP_FORCE_SVG
    Return SVG icons, even if gdk-pixbuf doesn't support them. Cannot be used together with Gtk::IconTheme::LOOKUP_NO_SVG. 
--- LOOKUP_USE_BUILTIN
    When passed to Gtk::IconTheme#lookup_icon includes builtin icons as well as files. For a builtin icon, Gtk::IconInfo#filename returns nil and you need to call Gtk::IconInfo#builtin_pixbuf. 

== Signals
--- changed: self
    Emitted when the current icon theme is switched or GTK+ detects that a change has occurred in the contents of the current icon theme.
     * self: Gtk::IconTheme

== ChangeLog
* 2005-03-07 Added. - ((<Masao>))






ruby-gnome2-cvs メーリングリストの案内
Zurück zum Archiv-Index