Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
It would help if you gave a quick python example that we can run to test. (current code does nothing for me) –  Ward Muylaert Jun 5 '11 at 18:37
    
Found one here for those wondering. –  Ward Muylaert Jun 5 '11 at 18:40
    
Example-Code added. It's basically the code in your link with a small twist –  con-f-use Jun 5 '11 at 18:55
add comment

3 Answers

up vote 10 down vote accepted
+50

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).

share|improve this answer
add comment

It follows regular icon naming, which will, as far as I know, start at your theme and then keep falling back till it matches something with the name.

Taking for example the Faenza icon theme I currently use.

In /usr/share/icons/Faenza/index.theme it says (clipped)

[Icon Theme]
Name=Faenza
Inherits=gnome,hicolor
Comment=Icon theme project with tilish style, by Tiheum
Directories=actions/16,animations/16,apps/16,categories/16,devices/16,emblems/16,mimetypes/16,places/16,status/16,stock/16,actions/22,animations/22,apps/22,categories/22,devices/22,emblems/22,mimetypes/22,places/22,status/22,stock/22,actions/24,animations/24,apps/24,categories/24,devices/24,emblems/24,mimetypes/24,places/24,status/24,stock/24,actions/32,animations/32,apps/32,categories/32,devices/32,emblems/32,mimetypes/32,places/32,status/32,stock/32,actions/48,animations/48,apps/48,categories/48,devices/48,emblems/48,mimetypes/48,places/48,status/48,stock/48,actions/scalable,apps/scalable,categories/scalable,devices/scalable,emblems/scalable,mimetypes/scalable,places/scalable,status/scalable,stock/scalable

Notice the Inherits=... line? Those are Faenza's "fallbacks" in case it doesn't have the icon itself.

This is relevant to your question, because you can enter a name for an icon and then the icon will first be searched for in /usr/share/icons/YOURICONTHEME/. In the odd case that it doesn't find it, it will check the fallbacks (in this case /usr/share/icons/gnome/ and /usr/share/icons/hicolor/). You'll find that most (Ubuntu) icon themes inherit from gnome and/or hicolor so if you use the name of an icon in these folders, you can most likely rest assured that every theme will show an icon.

share|improve this answer
add comment

Shameless selfanswer: http://gtk2-perl.sourceforge.net/doc/pod/Gtk2/Stock.html

Edit: No not really. Wrong incomplete answer. For instance "indicator-messages" is not included in that list.

Update: In the folder /usr/share/icons/MYTHEME where MYTHEME denotes the name of the theme in use should be the icons. Will test that now.

Update2: Yes all icons in the aforementioned folder work! And the themes have fallbacks for items not found. The ones in gtk-stock mentioned in the link earlier are from the fallbacks. Would be nice to have some python code that puts out all available icons. One fare good using standard-items of the gtk-stock and the default-theme only, as the others' presence depends on the theme the user employs on runtime.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.