Using Icon Theme Names with Python AppIndicator Module

application-developmenticonsindicatorpythonthemes

How do I get the strings I can insert instead of 'gtk-execute'?

#!/usr/bin/python

import gobject
import gtk
import appindicator

if __name__ == "__main__":
    ind = appindicator.Indicator("example-simple-client", "gtk-execute",
        appindicator.CATEGORY_APPLICATION_STATUS)
    ind.set_status (appindicator.STATUS_ACTIVE)

    menu = gtk.Menu()

    for i in range(3):
        buf = "Test-undermenu - %d" % i
        menu_items = gtk.MenuItem(buf)
        menu.append(menu_items)
        menu_items.connect("activate", gtk.main_quit)
        menu_items.show()

    ind.set_menu(menu)
    gtk.main()

My answer below pretty much does it. Still it would be nice to have some python code that puts out all available icons.

Best Answer

Simple:

import gtk

icon_theme = gtk.icon_theme_get_default()
print icon_theme.list_icons()

The output of which is a tuple of all the icon names:

('input-gaming', 'gnome-aorta', 'stock_bottom', 'config-language', ...) 

See also: gtk.IconTheme.list_icons in the pygtk docs

If you'd like to get your icon as a GtkPixbuf, you can use the load_icon method:

>>> icon_theme.load_icon("gtk-execute", 48, 0)
<gtk.gdk.Pixbuf object at 0xb737443c (GdkPixbuf at 0x907bf38)>

If you want a filename instead, you can use the lookup_icon method:

>>> icon_theme.lookup_icon("gtk-execute", 48, 0).get_filename()
/usr/share/icons/Humanity/actions/48/gtk-execute.svg

Where 48 is the size of the desired icon (see also: get_icon_sizes).

Related Question