def set_icon_for_button_and_menuitem(icon_name, button=None, menuitem=None): icon_source = gtk.IconSource() icon_source.set_icon_name(icon_name) icon_set = gtk.IconSet() icon_set.add_source(icon_source) if button: image_widget = gtk.image_new_from_icon_set(icon_set, gtk.ICON_SIZE_SMALL_TOOLBAR) button.set_icon_widget(image_widget) if menuitem: image_widget = gtk.image_new_from_icon_set(icon_set, gtk.ICON_SIZE_MENU) menuitem.set_image(image_widget)
def clone_image(self, image): storage = image.get_storage_type() if storage == gtk.IMAGE_PIXMAP: img, mask = image.get_pixmap() return gtk.image_new_from_pixmap(img, mask) if storage == gtk.IMAGE_IMAGE: img, mask = image.get_image() return gtk.image_new_from_image(img, mask) if storage == gtk.IMAGE_PIXBUF: return gtk.image_new_from_pixbuf(image.get_pixbuf()) if storage == gtk.IMAGE_STOCK: img, size = image.get_stock() return gtk.image_new_from_stock(img, size) if storage == gtk.IMAGE_ICON_SET: img, size = image.get_icon_set() return gtk.image_new_from_icon_set(img, size) if storage == gtk.IMAGE_ANIMATION: return gtk.image_new_from_animation(image.get_animation()) if storage == gtk.IMAGE_ICON_NAME: img, size = image.get_icon_name() return gtk.image_new_from_icon_name(img, size) # if storage == gtk.IMAGE_EMPTY: img = gtk.Image() img.set_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU) return img
def gtk_ico_image_load(path, icosize=None): '''try to return a gtk image from path, if fails, return a broken image''' if file_readable(path): pixbuf = gtk_pixbuf_load(path) iconset = gtk.IconSet(pixbuf) return gtk.image_new_from_icon_set(iconset,icosize) else: return gtk.image_new_from_stock(gtk.STOCK_MISSING_IMAGE, gtk.ICON_SIZE_DIALOG)
def readPixmap(fn): pixbuf = gtk.gdk.pixbuf_new_from_file(fn) source = gtk.IconSource() source.set_pixbuf(pixbuf) source.set_size(gtk.ICON_SIZE_DIALOG) source.set_size_wildcarded(gtk.FALSE) iconset = gtk.IconSet() iconset.add_source(source) p = gtk.image_new_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG) return p
def readPixmap(fn): pixbuf = gtk.gdk.pixbuf_new_from_file(fn) source = gtk.IconSource() source.set_pixbuf(pixbuf) source.set_size(gtk.ICON_SIZE_DIALOG) source.set_size_wildcarded(False) iconset = gtk.IconSet() iconset.add_source(source) p = gtk.image_new_from_icon_set(iconset, gtk.ICON_SIZE_DIALOG) return p
def small_image(widget, *args): """Return a large-size gtk.Image for the object.""" iset = iconset(widget, *args) return gtk.image_new_from_icon_set(iset, gtk.ICON_SIZE_SMALL_TOOLBAR)
def set_from_icon_set(self, icon_set, size): """Load image from icon set.""" image = gtk.image_new_from_icon_set(icon_set, size) self.set_from_pixbuf(image.get_pixbuf())