def get_icon(image, size):
"""
Generate a GdkPixbuf image
:param image: icon name or image path
:return: GdkPixbux Image
"""
directory = path.join(env.get("DATA_DIR"), "applications", "images") + "/"
theme = Gtk.IconTheme.get_default()
if theme.has_icon(path.splitext(image)[0]):
icon = theme.load_icon(path.splitext(image)[0], size, 0)
elif path.exists(directory + image):
icon = GdkPixbuf.Pixbuf.new_from_file(directory + image)
elif path.exists(image):
icon = GdkPixbuf.Pixbuf.new_from_file(image)
else:
icon = theme.load_icon("image-missing", size, 0)
if icon.get_width() != size or icon.get_height() != size:
icon = icon.scale_simple(size, size, GdkPixbuf.InterpType.BILINEAR)
return icon
评论列表
文章目录