12

How can I get the full file path from an icon name in GNOME?

david4dev
  • 4,854
  • 2
  • 28
  • 35
  • Is there something specific to icons in gnome? Use `os.path` services. – khachik May 22 '11 at 19:39
  • 1
    @khachik, there is indeed, gnome looks up an icon name in the current icon theme, which may be installed system-wide or per-user, so it is not predictable where the file may be. – ptomato May 23 '11 at 00:03

2 Answers2

15
import gtk
icon_theme = gtk.icon_theme_get_default()
icon_info = icon_theme.lookup_icon("my-icon-name", 48, 0)
print icon_info.get_filename()
Flimm
  • 136,138
  • 45
  • 251
  • 267
10

Translation for Python 3:

from gi.repository import Gtk
icon_theme = Gtk.IconTheme.get_default()
icon_info = icon_theme.lookup_icon("my-icon-name", 48, 0)
print(icon_info.get_filename())
zbyszek
  • 5,105
  • 1
  • 27
  • 22
  • 1
    The second line should be `icon_theme = Gtk.IconTheme.get_default()` to be equivalent to the accepted answer (otherwise, the user's icon theme preference isn't taken into account). – rkjnsn Aug 14 '14 at 18:32