Skip to content

Instantly share code, notes, and snippets.

@segphault
Created December 29, 2008 03:47
Show Gist options
  • Save segphault/41166 to your computer and use it in GitHub Desktop.
Save segphault/41166 to your computer and use it in GitHub Desktop.
Manually set widget icons in GTK+
# Each individual GTK+ widget has a completely different set of functions for
# manually setting an icon. It also has to be done differently depending on
# whether the icon is being set by stock name or by filename. These
# inconsistencies make GTK+ very frustrating.
def set_icon_named(name, widget, size=gtk.ICON_SIZE_MENU):
if isinstance(widget, gtk.ImageMenuItem):
if name.startswith("/"): widget.get_image().set_from_file(name)
else: widget.get_image().set_from_icon_name(name, size)
elif isinstance(widget, gtk.ToggleToolButton):
if name.startswith("/"): i = gtk.image_new_from_file(name)
else: i = gtk.image_new_from_icon_name(name, size)
widget.set_icon_widget(i); i.show()
elif isinstance(widget, gtk.ToolButton):
if name.startswith("/"): widget.get_icon_widget().set_from_filename(name)
else: widget.set_icon_name(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment