我可能弄错了,这里有一些想法:
>我的机器上没有任何名为“applications-mail”的图标.我确实发现了许多“互联网邮件”图标.
/usr/share/icons/Mint-X/categories/96/applications-mail.svg
>另外,我相信svg图标应该在一个可伸缩的目录中.可能你发现的svg并没有被认出来.例如.我有:
/usr/share/icons/Tango/scalable/apps/internet-mail.svg
>我稍微修改了你的程序:
清单:
#!/usr/bin/env python3
from gi.repository import Gtk
class MainWindow(Gtk.Window):
def __init__(self):
super(MainWindow, self).__init__()
self.connect("delete-event", Gtk.main_quit)
#icon_name = "applications-mail"
icon_name = "internet-mail"
icon_theme = Gtk.IconTheme.get_default()
found_icons = set()
for res in range(0, 512, 2):
icon = icon_theme.lookup_icon(icon_name, res, 0)
#print(icon)
if icon != None:
found_icons.add(icon.get_filename())
if len(found_icons) > 0:
print("
".join(found_icons))
sizes = Gtk.IconTheme.get_default().get_icon_sizes(icon_name)
max_size = max(sizes)
print("max size = {} ({})".format(max_size, sizes))
pixbuf = icon_theme.load_icon(icon_name, max_size, 0)
self.set_default_icon_list([pixbuf])
self.show_all()
def run(self):
Gtk.main()
def main(args):
mainwdw = MainWindow()
mainwdw.run()
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
我得到:
/usr/share/icons/Tango/24x24/apps/internet-mail.png
/usr/share/icons/Tango/scalable/apps/internet-mail.svg
/usr/share/icons/Tango/16x16/apps/internet-mail.png
/usr/share/icons/Tango/32x32/apps/internet-mail.png
/usr/share/icons/Tango/22x22/apps/internet-mail.png
max size = 32 ([22, 16, 24, 32, -1, 0])
其中-1表示可缩放图标. (所以,不要使用max() – 查找-1.
这来自developers’ site:
[gtk_icon_theme_get_icon_sizes] Returns an array of integers describing the sizes at which the icon is
available without scaling. A size of -1 means that the icon is
available in a scalable format.
编辑:更多想法:
> Gtk使用gdk-pixbuf.loaders模块来渲染图标等图像.您可能没有svg驱动程序正常工作.我似乎也记得librsvg库是必要的.
>即使另一个图标实际工作,您可能会看到图标缓存中的副本,并且您的图标渲染器可能仍然失败.
>图标缓存本身甚至可能存在问题.试试rebuilding the cache.