Page 5 of 5 FirstFirst ... 345
Results 41 to 46 of 46

Thread: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

  1. #41
    Join Date
    Dec 2007
    Location
    The Netherlands
    Beans
    1
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Quote Originally Posted by JasperK View Post
    The newer versions of nautilus as available in Karmic don't store the metadata in xml files anymore. Instead nautilus now uses the new gio abstraction layer to give files a "metadata::custom_icon" attribute. This attribute contains a filename of a picture that should be used as the file icon.

    I changed the python script that was posted before to use gio attributes. I have only tested this on karmic(Nautilus 2.27.4).
    I've tried your script with Nautilus 2.28.0 on Karmic but it didn't work for me . Do you have any suggestions? This is what i get:
    Code:
    Traceback (most recent call last):
      File "custom_icon_gio.py", line 48, in <module>
        main()
      File "custom_icon_gio.py", line 42, in main
        gioFile.set_attribute_string("metadata::custom_icon", sd[1])
    gio.Error: Error setting file metadata: No such file or directory

  2. #42
    Join Date
    Jan 2007
    Beans
    13

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Try mine ...

    Code:
    #!/usr/bin/python
    
    import sys
    from optparse import OptionParser
    import os
    import fnmatch
    from urllib import quote
    
    def main():
        parser = OptionParser(usage="usage: %prog [options] folder [folder2 ...]",
                              version="%prog 0.1")
        parser.add_option("", "--names", dest="names",
                          default="[Ff]older.[Jj][Pp][Gg]",
                          help='specification to match image filenames [default: "%default"]')
        parser.add_option("-R", "--recursive", dest="recursive", action="store_true", default=False,
                          help="set icons for folders recursively")
    
        (options, folders) = parser.parse_args(sys.argv)
        folders = folders[1:]
    
        if not folders:
            parser.error("no folders specified")
    
        noquote = "()'*"
    
        for folder in folders:
            for root, dirs, files in os.walk(folder):
                print root, "..."
                subdirs = []
                for d in dirs:
                    images = fnmatch.filter(os.listdir(os.path.join(root, d)), options.names)
                    if images:
                        path  = os.path.join(root, d)
                        image = os.path.basename(images[0])
                        os.system('gvfs-set-attribute "%s" metadata::custom-icon "%s"' % (path, image))
                    else:
                        print "no image found for %s/%s" % (root, d)
                if not options.recursive:
                    dirs[:] = []
        print "done."
    
    if __name__ == "__main__":
        main()
    Attached Files Attached Files

  3. #43
    Join Date
    Sep 2006
    Beans
    8

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Tanks qos!!!!! this works well for me! hope some day nautilus will do this by default or at least give the optiom...

    C.

  4. #44
    Join Date
    Dec 2009
    Beans
    1

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Quote Originally Posted by qos View Post
    Try mine ...

    Code:
    #!/usr/bin/python
    
    import sys
    from optparse import OptionParser
    import os
    import fnmatch
    from urllib import quote
    
    def main():
        parser = OptionParser(usage="usage: %prog [options] folder [folder2 ...]",
                              version="%prog 0.1")
        parser.add_option("", "--names", dest="names",
                          default="[Ff]older.[Jj][Pp][Gg]",
                          help='specification to match image filenames [default: "%default"]')
        parser.add_option("-R", "--recursive", dest="recursive", action="store_true", default=False,
                          help="set icons for folders recursively")
    
        (options, folders) = parser.parse_args(sys.argv)
        folders = folders[1:]
    
        if not folders:
            parser.error("no folders specified")
    
        noquote = "()'*"
    
        for folder in folders:
            for root, dirs, files in os.walk(folder):
                print root, "..."
                subdirs = []
                for d in dirs:
                    images = fnmatch.filter(os.listdir(os.path.join(root, d)), options.names)
                    if images:
                        path  = os.path.join(root, d)
                        image = os.path.basename(images[0])
                        os.system('gvfs-set-attribute "%s" metadata::custom-icon "%s"' % (path, image))
                    else:
                        print "no image found for %s/%s" % (root, d)
                if not options.recursive:
                    dirs[:] = []
        print "done."
    
    if __name__ == "__main__":
        main()
    Don´t work for me.

    This what i get:

    Usage: albumart [options] folder [folder2 ...]

    albumart: error: no folders specified

  5. #45
    Join Date
    Jan 2007
    Beans
    13

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    I cleaned up the code, and fixed a potential bug.
    So, give it a new try...

    Code:
    #!/usr/bin/python
    
    import sys
    from optparse import OptionParser
    import os
    import fnmatch
    from urllib import quote
    
    
    def setattrib(root, directory, names):
        path   = os.path.join(root, directory)
        images = fnmatch.filter(os.listdir(path), names)
        if images:
            image = os.path.basename(images[0])
            os.system('gvfs-set-attribute "%s" metadata::custom-icon "%s"' % (path, image))
        else:
            print "no image found for %s/%s" % (root, directory)
    
    def main():
        parser = OptionParser(usage="usage: %prog [options] folder [folder2 ...]",
                              version="%prog 0.2")
        parser.add_option("", "--names", dest="names",
                          default="[Ff]older.[Jj][Pp][Gg]",
                          help='specification to match image filenames [default: "%default"]')
        parser.add_option("-R", "--recursive", dest="recursive", action="store_true", default=False,
                          help="set icons for folders recursively")
    
        (options, folders) = parser.parse_args(sys.argv)
        folders = folders[1:]
    
        if not folders:
            parser.error("no folders specified")
    
        noquote = "()'*"
    
        for folder in folders:
            setattrib('', folder, options.names)
            for root, dirs, files in os.walk(folder):
                for d in dirs:
                    setattrib(root, d, options.names)
                if not options.recursive:
                    dirs[:] = []
        print "done."
    
    if __name__ == "__main__":
        main()
    Attached Files Attached Files

  6. #46
    Join Date
    Oct 2009
    Beans
    183
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: HOWTO: Make folder icons use Folder.jpg (Like Windows XP My Music folder does)

    Why don't you just edit an icon theme?

Page 5 of 5 FirstFirst ... 345

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •