Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 3971  / 1 Year ago, mon, january 9, 2023, 11:03:40

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.


More From » indicator

 Answers
0

Simple:


import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

icon_theme = Gtk.IconTheme()
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 Gtk-3.0 docs


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


>>> icon_theme.load_icon("gtk-execute", 48, 0)
<GdkPixbuf.Pixbuf object at 0x7fd1689a5d80 (GdkPixbuf at 0x2ad45e0)>

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/gnome/48x48/actions/gtk-execute.png

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


[#44828] Wednesday, January 11, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mugustered

Total Points: 193
Total Questions: 123
Total Answers: 108

Location: Bermuda
Member since Wed, Mar 22, 2023
1 Year ago
;