ubuntu 下用python写了个生成动态壁纸的脚本,如果通过代码实现使用这个xml,而不是通过桌面->背景->添加

是如何通过代码实现调用这个xml,打字打成“如果”去来

第1个回答  2012-03-22
sudo mkdir /usr/share/backgrounds/mybackground-imgs
sudo cd /usr/share/backgrounds/mybackground-imgs
sudo cp /home/你的背景图片所在目录/* .
sudo ./backgroud.py

其中backgroud.py:
#!/usr/bin/env python
#coding=utf-8
import glob, os
import shutil
import time
import Image

filelist=[]
def filelie(path):
if os.path.isfile(path):
wenjian=os.path.splitext(path)[1][1:]
if wenjian=="jpg" or wenjian=="png" or wenjian=="gif":
try:
kuan,gao = Image.open(path).size
if kuan>=1024 and gao>=768:
filelist.append(path)
except IOError:
pass
elif os.path.isdir(path):
for item in os.listdir(path):
itemsrc = os.path.join(path, item)
filelie(itemsrc)

curdir = os.getcwd()
filelie(curdir)
currentImageFiles = filelist
#print filelist
if os.path.isfile('backgroundslide.xml'):
os.remove('backgroundslide.xml')

currentTime = time.localtime()
length = len(currentImageFiles)

f = file('backgroundslide.xml', 'w')

f.write('<background>\n')
f.write('\t<starttime>\n')
f.write('\t\t<year>' + str(currentTime.tm_year) + '</year>\n')
f.write('\t\t<month>' + str(currentTime.tm_mon) + '</month>\n')
f.write('\t\t<day>' + str(currentTime.tm_mday) + '</day>\n')
f.write('\t\t<hour>' + str(currentTime.tm_hour) + '</hour>\n')
f.write('\t\t<minute>' + str(currentTime.tm_min) + '</minute>\n')
f.write('\t\t<second>' + str(currentTime.tm_sec) + '</second>\n')
f.write('\t</starttime>\n')
f.write('<!--This animation will start at the time it created-->\n')

for i in currentImageFiles:
length = length - 1
f.write('\t<static>\n')
f.write('\t\t<duration>550.0</duration>\n')
f.write('\t\t<file>' + currentImageFiles[length] +'</file>\n')
f.write('\t</static>\n')
f.write('\t<transition>\n')
f.write('\t\t<duration>25.0</duration>\n')
f.write('\t\t<from>' + currentImageFiles[length] + '</from>\n')
if length >= 1:
f.write('\t\t<to>' + currentImageFiles[length-1] + '</to>\n')
if length <1:
f.write('\t\t<to>' + currentImageFiles[len(currentImageFiles)-1] + '</to>\n')
f.write('\t</transition>\n')

f.write('</background>\n')
f.close()追问

你这个只是生成xml而已,还不是要通过右键-》视图-》添加 选中xml

第2个回答  2012-03-24
好像是需要配置gconf,看看有没有可以配置gconf的python库吧.
gconf就像是gnome下的注册表.
第3个回答  2012-03-16
将xml文件拷贝到 /usr/share/backgrounds/cosmos/追问

显然不行撒,xml这个文件肯定是被某个配置文件引用了,关键是我现在找不到这个配置文件,find命令貌似没成功

追答

去ubuntu论坛看看

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网