Sunday, August 15, 2010

Wallpaper slideshow on Ubuntu

The only way to have multiple wallpapers on a GNOME desktop is by making a xml file and setting that as your wallpaper. What you get is a slideshow with each wallpaper as a slide and a transition between slides that lets you decide how long to use each wallpaper. Read more.

There are also projects to do this for you using a GUI. You might want to give them a try if you're more comfortable with using GUI applications. Alternatively, you could whip up a script using the shell or Python to do the hard work of writing the xml for you. The crucial pieces are functions to generate the start time, slide and transition tags with all accompanying attributes. I'll reproduce those functions from my own script here.

def set_starttime(self):
        starttime = etree.SubElement(self.xml, 'starttime')
        year = etree.SubElement(starttime, 'year')
        year.text = str(self.year)
        month = etree.SubElement(starttime, 'month')
        month.text = str(self.month)
        day = etree.SubElement(starttime, 'day')
        day.text = str(
        hour = etree.SubElement(starttime, 'hour')
        hour.text = str(self.hour)
        minute = etree.SubElement(starttime, 'minute')
        minute.text = str(self.minute)
        second = etree.SubElement(starttime, 'second')
        second.text = str(self.second)

The above generates the start time tag along with child tags for date and time. It's not the most compact code but it works. Next, comes the functions for generating the slide and transition tags.

def make_transition(self, previous, current):
        transition = etree.SubElement(self.xml, 'transition')
        duration = etree.SubElement(transition, 'duration')
        duration.text = str(self.transit_duration)
        fr = etree.SubElement(transition, 'from')
        fr.text = previous
        to = etree.SubElement(transition, 'to')
        to.text = current

def make_slide(self, current):
        static = etree.SubElement(self.xml, 'static')
        duration = etree.SubElement(static, 'duration')
        duration.text = str(self.slide_duration)
        wallpaper = etree.SubElement(static, 'file')
        wallpaper.text = current

Along with these three functions, you simply write code (a simple loop will do) that generates a list of file paths to the desired wallpapers, ties them all together and outputs the xml onto a file.

Thanks to Quickly you can be up and running in short order. Most of the framework will be generated for you so you just need to insert code specific to your needs. You don't even need to be a programming guru to make stuff like this.

Related posts:

Multiple wallpapers on Ubuntu