Wallpaper management pt.1

I really like wallpapers (especially those with babes ^_^), and I always try to get as many as I can. I also wrote a script to download the wallpapers from skins.be. To avoid lots of traffic to this website I won't publish the script here - but it is awesome!

$ find wallpapers_skins.be -type f | wc -l
35640

This is the result after running it to fetch all images with a resolution of 1920×1200 and 1280×1024 and I also downloaded other websites… Okay, let's just say I've got a lot of wallpapers. The problem you'll face is, which wallpaper you should use. My window manager is Xfce4 and it supports image-lists to pick a random background image on login. To pick a random wallpaper during your session you can force Xfce4 to switch to a none-wallpaper and immediately back to you image-list. I wrote a little tool, placing it self in your system tray, to do it. An old description of the project can be found here, but I recently rewrote the whole application but I haven't had time to write the project page for it. The behavior is pretty much the same but the code is much more organized. To download the project you can go to http://git.goatpr0n.de/Xfwpc/ and download it from there.

Xfwpc has some features which you might find interesting:

  • image-lists based on wireless networks
  • multi-desktop support
  • on-the-fly update timer changing
  • on-demand wallpaper changing

After advertising my Xfwpc project a little bit, I'll come to the main reason why I started writing this blog entry - I always start without plan. Just typing and typing and typing, blah blah blah, errr back to the text.

In order to manage the flood of wallpapers I've collected, I wrote scripts to automaticly add the images to the correct image-list of a monitor based on its resolution ratio. Today I've wrote a script to use from within feh. feh is a very cool image viewer with some nice features. What I did, was to define two actions to add a wallpaper to monitor 1 or 2.

So let's have a look at the script first.

#!/usr/bin/env python
 
import sys, os
import gtk, pynotify
import Image
import subprocess
 
screen = gtk.gdk.Screen()
 
def add_to_list(image, monitor):
    cmd = 'xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor%s/last-image-list' % monitor
    pipe = subprocess.Popen(cmd, shell=True, bufsize=128,
                            stdout=subprocess.PIPE).stdout
    listpath = pipe.readline().rstrip('\n')
    print listpath
    fd_list = open(listpath, 'a')
    if fd_list:
        fd_list.write(os.path.expanduser(image) + '\n')
        fd_list.close()
        n = pynotify.Notification('Wallpaper added.',
                                  'Successfully added %s.' % image,
                                  'dialog-ok')
        n.set_urgency(pynotify.URGENCY_NORMAL)
        n.set_timeout(3000)
        n.show()
 
def get_ImageRatio(image):
    try:
        img = Image.open(image)
    except:
        n = pynotify.Notification('Image error',
                                  'Failed to load %s' % image,
                                  'dialog-no')
        n.set_urgency(pynotify.URGENCY_CRITICAL)
        n.set_timeout(3000)
        n.show()
        raise Exception('Image error')
    w, h = img.size
    del img
    return 1.0 * w / h
 
def get_MonitorRatio(monitor):
    geometry = screen.get_monitor_geometry(int(monitor))
    ratio = 1.0 * geometry.width / geometry.height
    return ratio
 
def main(argv):
    pynotify.init('Wallpaper adder')
    if len(argv) < 3:
        print 'Not enough parameter. Need monitor name and at least one image.'
        sys.exit(1)
 
    monitor = argv[1]
    images = argv[2:]
 
    for image in images:
        iRatio = get_ImageRatio(image)
        mRatio = get_MonitorRatio(monitor)
        if iRatio == mRatio:
            add_to_list(image, monitor)
        else:
            n = pynotify.Notification('Wallpaper resolution error',
                                      'Skipping %s. Wrong ratio: %4.3f:%4.3f' % (image, iRatio, mRatio),
                                      'dialog-no')
            n.set_urgency(pynotify.URGENCY_CRITICAL)
            n.set_timeout(3000)
            n.show()
 
if __name__ == '__main__':
    main(sys.argv)

The script checks if the image fits the screen ratio of the current resolution and then adds it to the image-list of the given screen. The path to the list is determained by invoking xfconf-query.

To use the script with feh, I have added the following alias to my shell configuration

alias feh="feh --action1 '${HOME}/bin/wallpaper_add2Monitor 0 \"%f\"' --action2 '${HOME}/bin/wallpaper_add2Monitor 1 \"%f\"'"

If I run feh and press 1 or 2. We will run the script to add it to the image-list.

I haven't re-read this entry (tl;dr), but I hope you've got what I was trying to say and give some feedback, but not on the crappy writing style ;-) Thank you!

Comments




If you can't read the letters on the image, download this .wav file to get them read to you.
Posted 2010/03/22 22:36 · Julian Knauer
 
blog/2010/03/22.wallpaper.management.pt.1.txt · Last modified: 2010/03/22 22:36 by jpk
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki