Skip to content

Instantly share code, notes, and snippets.

@PhrozenByte
Created March 30, 2019 14:35
Show Gist options
  • Save PhrozenByte/04c53286b6d78cb6981a868c11cca0fa to your computer and use it in GitHub Desktop.
Save PhrozenByte/04c53286b6d78cb6981a868c11cca0fa to your computer and use it in GitHub Desktop.
Returns the full path to a Gtk icon file by icon name
#!/usr/bin/env python3
import os, sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
if len(sys.argv) < 2:
sys.stderr.write("Usage:\n")
sys.stderr.write(" {} ICON_NAME [ICON_SIZE]\n".format(os.path.basename(__file__)))
sys.exit(1)
icon_name = sys.argv[1]
icon_size = int(sys.argv[2]) if len(sys.argv) >= 3 else 64
icon_theme = Gtk.IconTheme.get_default()
icon_info = icon_theme.lookup_icon(icon_name, icon_size, 0)
if not icon_info:
sys.stderr.write("Unknown icon: {}\n".format(sys.argv[1]))
sys.exit(1)
print(icon_info.get_filename())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment