天天看点

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

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('\n')

f.write('\t\n')

f.write('\t\t' + str(currentTime.tm_year) + '\n')

f.write('\t\t' + str(currentTime.tm_mon) + '\n')

f.write('\t\t' + str(currentTime.tm_mday) + '\n')

f.write('\t\t' + str(currentTime.tm_hour) + '\n')

f.write('\t\t' + str(currentTime.tm_min) + '\n')

f.write('\t\t' + str(currentTime.tm_sec) + '\n')

f.write('\t\n')

f.write('\n')

for i in currentImageFiles:

length = length - 1

f.write('\t\n')

f.write('\t\t550.0\n')

f.write('\t\t' + currentImageFiles[length] +'\n')

f.write('\t\n')

f.write('\t\n')

f.write('\t\t25.0\n')

f.write('\t\t' + currentImageFiles[length] + '\n')

if length >= 1:

f.write('\t\t' + currentImageFiles[length-1] + '\n')

if length <1:

f.write('\t\t' + currentImageFiles[len(currentImageFiles)-1] + '\n')

f.write('\t\n')

f.write('\n')

f.close()

取消

评论