Python Gtk3 Window Icon from SVG / scalable icon from stock theme
<p>How to set an high quality icon to Gtk.Window ?
My theme has SVG icons, but I always get an pixel size of 24 px. So what is wrong with my code? Would be very happy for some help. Thanks</p>

<p><a href="http://i.stack.imgur.com/7L9p4.png" rel="nofollow"><img src="http://i.stack.imgur.com/7L9p4.png" alt="enter image description here"></a></p>

<p><strong>Max size is always 24</strong>:</p>

<pre><code>#!/usr/bin/python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)

icon_name = "applications-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)
    found_icons.add(icon.get_filename())
print("\n".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)
window.set_default_icon_list([pixbuf])

window.show_all()
Gtk.main()
</code></pre>

<p><strong>Response</strong>:</p>

<pre><code>/usr/share/icons/Mint-X/categories/22/applications-mail.png
/usr/share/icons/Mint-X/categories/48/applications-mail.png
/usr/share/icons/Mint-X/categories/96/applications-mail.svg
/usr/share/icons/Mint-X/categories/32/applications-mail.png
/usr/share/icons/Mint-X/categories/16/applications-mail.png
/usr/share/icons/Mint-X/categories/24/applications-mail.png
max size = 24 ([22, 16, 24])
</code></pre>

<p>I could be mistaken, here are some ideas:</p>

<ul>
<li>I don't have <em>any</em> icon on my machine called "applications-mail". I did find many "internet-mail" icons though. </li>
</ul>

<blockquote>
  <p>/usr/share/icons/Mint-X/categories/96/applications-mail.svg</p>
</blockquote>

<ul>
<li>Also, I believe svg icons should be in a <code>scalable</code> directory. Possibly the svg you did find wasn't recognized as such. Eg. I have:</li>
</ul>

<p><code>/usr/share/icons/Tango/scalable/apps/internet-mail.svg</code></p>

<ul>
<li>I modified your program slightly:</li>
</ul>

<p>Listing:</p>

<pre><code>#!/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) &gt; 0:
            print("\n".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))
</code></pre>

<p>and I get:</p>

<pre><code>/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])
</code></pre>

<p>where -1 indicates a scalable icon. (so, don't use <code>max()</code> - look for -1.
This from the <a href="https://developer.gnome.org/gtk3/stable/GtkIconTheme.html#gtk-icon-theme-get-icon-sizes" rel="nofollow">developers' site</a>: </p>

<blockquote>
  <p>[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.</p>
</blockquote>

<p><strong>edit</strong>: More ideas:</p>

<ul>
<li><p>Gtk uses gdk-pixbuf.loaders modules to render images such as icons. You might not have the svg driver working correctly. I also seem to recall that the librsvg libraries is necessary.</p></li>
<li><p>Even if another icon is actually working, you might be seeing a copy from the icon cache, and your icon renderer might still be failing.</p></li>
<li><p>There might even be a problem with the icon cache itself. Try <a href="https://developer.gnome.org/gtk3/stable/gtk-update-icon-cache.html" rel="nofollow">rebuilding the cache</a>.</p></li>
</ul>

python icons gtk3