GNOME has supported wallpaper cycles for a while now. I know that Ubuntu includes several of them in the default install. (Check them out; there's a Space image cycle, and a cycle for winners of a wallpaper contest.) However, if you want to make your own cycle, then you're SOL, cause there is no official GNOME editor for these wallpaper rotations. So I wrote a simple utility to make them:
#!/usr/bin/env python
import os, sys, datetime, random
# Configuration:
extensions = [ "jpg", "jpeg", "bmp", "gif", "png" ]
period = 5 * 60 # 5 minutes
transition = 5 # 5 seconds
starttime = datetime.datetime.today()
randomize = True
# Verify that we were given a filename:
if len(sys.argv) != 2:
print >>sys.stderr, "Please provide a destination filename."
exit(1)
# Select all images in the current directory:
imgs = filter(lambda x: x.split(".")[-1].lower() in extensions, os.listdir("."))
# Now, get all of their absolute paths:
imgs = map(os.path.abspath, imgs)
# Shuffle if needed:
if randomize: random.shuffle(imgs)
# Functions for writing the XML document:
def write_static(f, path):
global period
f.writelines([
"\t<static>\n",
"\t\t<duration>%d</duration>\n" % period,
"\t\t<file>%s</file>\n" % path,
"\t</static>\n"])
def write_transition(f, start, end):
global transition
f.writelines([
"\t<transition>\n",
"\t\t<duration>%d</duration>\n" % transition,
"\t\t<from>%s</from>\n" % start,
"\t\t<to>%s</to>\n" % end,
"\t</transition>\n"])
def write_header(f):
global starttime
f.writelines([
"<background>\n",
"\t<starttime>\n",
"\t\t<year>%d</year>\n" % starttime.year,
"\t\t<month>%d</month>\n" % starttime.month,
"\t\t<day>%d</day>\n" % starttime.day,
"\t\t<hour>%d</hour>\n" % starttime.hour,
"\t\t<minute>%d</minute>\n" % starttime.minute,
"\t\t<second>%d</second>\n" % starttime.second,
"\t</starttime>\n"])
def write_footer(f):
f.writelines(["</background>\n"])
# Open the file for writing:
f = open(sys.argv[1], "wb")
# Write the XML files:
write_header(f)
for i in xrange(len(imgs)):
write_static(f, imgs[i])
write_transition(f, imgs[i], imgs[i+1 if (i+1)!=len(imgs) else 0])
write_footer(f)
# Done!
f.close()
Usage:
./gen_wallpaper.py output.xml
The script will detect all images in the current directory, shuffle them, and write them into the output xml. You can then open that xml file in the background selection dialog (get the file dialog to show 'All Files') and your background will cycle through all of those pictures.
Have fun! I know this script has been pretty dang useful for me. :)
0 Responses to Wallpaper Cycles in GNOME
Leave a Reply