Possible Duplicate:
How can I change the folder icon?

I'm using python. I want change a file icon with Gio from a python app. I found a lot of deprecated documentation and I'm not sure how I can do it.

I tried this, but nothing happen:

from gi.repository import Gio
f = Gio.File.parse_name('/home/my_user/Desktop/test.txt')
f.set_attribute_string("metadata::custom_icon", '/usr/share/icons/Humanity/animations/48/brasero-disc-100.svg', Gio.FileQueryInfoFlags.NONE, None)

Which class and method have I use? Any idea, please? Thanks in advance!

  • I think is not a duplicate, because I don't want use 'gvfs-set-attribute', because it's not refresh nautilus contents. By this reason I want use Gio :) – Costales Sep 13 '12 at 15:35
  • 1
    gvfs-set-attribute is merely a command line tool which does basically the exact same thing you are doing in your code. You can use it as a quick way to test, rather than editing the code. – dobey Sep 13 '12 at 17:04

This is mostly a duplicate of a previous question I answered, but you have 2 problems with your current code:

  • It is custom-icon and not custom_icon
  • You really do not want to set the icon of a file to be a file from the animations context of a theme. Or in general, a file at all. It's better to set the custom-icon-name attribute if you really must, and then have that icon be a part of the theme, so that it works correctly if the user changes themes.
  • Thanks dobey! but I tried 'custom-icon' and 'custom-icon-name', and Nautilus is not changing the icon :( Any idea? Thanks in advance! :) paste.ubuntu.com/1202847 – Costales Sep 13 '12 at 15:29
  • You need to set custom-icon-name to just the icon name, such as "text-x-generic" for it to work. You may also need to refresh the view in nautilus, if you have the window already open and expect it to change immediately. – dobey Sep 13 '12 at 16:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.