I just installed ubuntu12.04 recently. I miss my previous desktop background in Windows (photos of my friends going out with me ~), From http://forum.ubuntu.org.cn/viewtopic.php? T = 391446 & P = 2873883 learn about modification/usr/share/backgrounds/contest/precise. xml
File, but there are a lot of photos. If you don't want to manually modify them, you can use python to complete this task. Below are my achievements.
"""
This is the "diy_dynamic_wallpapers.py" which is used to set your favorite pictures as wallpapers.
First step:
Put your wallpapers in one folder (such as/usr/home/Ubuntu/mywallpapers)
Second step:
Exec this Moudle and generate the "precise. xml"
For example: diy_dynamic_wallpapers ("/usr/home/Ubuntu/mywallpapers", "/usr/home/Ubuntu/precise. xml ")
Third step:
Move the "precise. xml" to/usr/share/backgrounds/contest/precise. xml
$: Sudo mV/usr/home/Ubuntu/precise. xml/usr/share/backgrounds/contest/precise. xml
Fourth step:
Open the dialog which is used for changing the wallpaper, then select the image with a clock mark
@ Environment:
Ubuntu12.04
Python2.7
@ Refurls:
Http://forum.ubuntu.org.cn/viewtopic.php? T = 391446 & P = 2873883
Http://www.linuxidc.com/Linux/2012-05/59776.htm
Http://www.51testing.com /? Uid-138711-action-viewspace-itemid-173347
@ Author: aslily
"""
Def diy_dynamic_wallpapers (rootdir, outputpath ):
# @ Rootdir: the directory which stores the background images
# @ Outputpath: the path for the newly precise. xml
Import OS
Import OS. Path
From XML. Dom. minidom import document
# Store full path names of the background images into picturename
Picturename = []
For parent, dirnames, filenames in OS. Walk (rootdir ):
For filename in filenames:
Picturename. insert (0, OS. Path. Join (parent, filename ))
"""
# Test for picturename
Print 'first = '+ picturename [0]
For picture in picturename:
Print 'pn = '+ picture
Print 'last = '+ picturename [-1]
"""
# Set the default time for changing picture
Sduration = "45.0" # One stays 45 seconds and then change to next
Tduration = "5.0" # change one to next in 5 seconds
# Create XML Doc
Doc = Document ()
# Background Node
Background = Doc. createelement ("background ")
Doc. appendchild (background)
# Starttime Node
Starttime = Doc. createelement ("starttime ")
Background. appendchild (starttime)
# Tags in starttime
Tagsinstart = [["year", "2009"], ["month", "08"], ["day", "04"],
["Hour", "00"], ["Minute", "00"], ["second", "00"]
For tag in tagsinstart:
Node = Doc. createelement (TAG [0])
Nodevalue = Doc. createtextnode (TAG [1])
Node. appendchild (nodevalue)
Starttime. appendchild (node)
# Create static nodes and transition nodes
Picturenum = Len (picturename)
For index in range (LEN (picturename )):
# Create static Node
Snode = Doc. createelement ("static ")
Dnode = Doc. createelement ("duration ")
Dvalue = Doc. createtextnode (sduration)
Fnode = Doc. createelement ("file ")
Fvalue = Doc. createtextnode (picturename [Index])
Background. appendchild (snode)
Snode. appendchild (dnode)
Snode. appendchild (fnode)
Dnode. appendchild (dvalue)
Fnode. appendchild (fvalue)
# Create transition Node
Tnode = Doc. createelement ("transition ")
Tdnode = Doc. createelement ("duration ")
Tdvalue = Doc. createtextnode (tduration)
Fromnode = Doc. createelement ("from ")
Tonode = Doc. createelement ("")
# Set fromvalue and tovalue
If (index <picturenum-1 ):
FV = picturename [Index]
TV = picturename [index + 1]
Else:
FV = picturename [-1]
TV = picturename [0]
Fromvalue = Doc. createtextnode (Fv)
Tovalue = Doc. createtextnode (TV)
Background. appendchild (tnode)
Tnode. appendchild (tdnode)
Tnode. appendchild (fromnode)
Tnode. appendchild (tonode)
Tdnode. appendchild (tdvalue)
Fromnode. appendchild (fromvalue)
Tonode. appendchild (tovalue)
# End
# Test for XML
# Print Doc. toprettyxml (indent = "")
# Output XML file to outputpath
With open (outputpath, "W") as F:
F. Write (Doc. toprettyxml (indent = ""))
# Print that's OK
Print "that's OK"