linux桌面壁纸自动换(类似于windows7壁纸自动换)
来源:互联网 发布:眼药水 知乎 编辑:程序博客网 时间:2024/04/29 21:28
复制以下内容,保存为 py 后缀的文件,拷贝到wallpaper文件夹,进入文件夹,以python运行,选取xml为壁纸
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
# Ubuntu 9.10 dynamic wallpaper maker_Can be used in all the distributions of linux
#
# Auto generate a configuration file which you can use as
# dynamic wallpaper.
#USAGE
#use this dynamic-wall-maker.py by ""[somebody@ubuntu~]$python /path/to/the/dynamic-wall-maker.py /path/to/the/wallpapers_filefolder""
#
#cd
#[wowoto@Archlinux windows7-wallpapers]$ python dynamic-wall-maker.py /path/to/the/wallpapers
#You can set "/path/to/the/wallpapers/dyn-wall.xml" as dynamic wallpaper now,have a good day
#[wowoto@Archlinux windows7-wallpapers]$
# xiaoyang006@gmail.com
# 2009.11
import os
import sys
import optparse
class Printer:
'''Print all kinds of tags.'''
def __init__(self):
self.__indent_format = ' '
def __print_open_tag(self, type, indent=0):
if indent > 0:
for i in range(0, indent):
print self.__indent_format,
print '<%s>' % type
def __print_close_tag(self, type, indent=0):
if indent > 0:
for i in range(0, indent):
print self.__indent_format,
print '</%s>' % type
def __print_tag(self, type, value, indent=0):
if indent > 0:
for i in range(0, indent):
print self.__indent_format,
print '<%s>%s</%s>' % (type, value, type)
def set_indent_format(self, format):
self.__indent_format = format
def start(self):
self.__print_open_tag('background')
def end(self):
self.__print_close_tag('background')
def set_start_time(self, year='2010', mon='02', day='14', hour='00', min='00', sec='00'):
self.__print_open_tag('starttime', 1)
self.__print_tag('year', year, 2)
self.__print_tag('month', mon, 2)
self.__print_tag('day', day, 2)
self.__print_tag('hour', hour, 2)
self.__print_tag('minute', min, 2)
self.__print_tag('second', sec, 2)
self.__print_close_tag('starttime', 1)
def set_static_bg(self, file, time='235'):
self.__print_open_tag('static', 1)
self.__print_tag('duration', time, 2)
self.__print_tag('file', file, 2)
self.__print_close_tag('static', 1)
def set_transition(self, file, new_file, time='235'):
self.__print_open_tag('transition', 1)
self.__print_tag('from', file, 2)
self.__print_tag('to', new_file, 2)
self.__print_close_tag('transition', 1)
class Processor:
'''Generate dynamic wallpaper xml configure file.'''
def __init__(self):
self.walls = []
self.time = '235'
self.__saveout = sys.stdout
self.__conf_fd = None
def add_wall(self, path):
cwd = os.getcwd()
if os.path.isfile(path):
if not path.startwith('/'):
path = cwd + path
self.walls.append(path)
else:
if not path.endswith('/'):
path = path + '/'
#TODO: filter not supported wallpaper file type
command = 'find %s -iname "*.png" -or -iname "*.jpg" -or -iname "*.bmp"' % path
files = os.popen(command).read().split('/n')
del files[-1]
for file in files:
self.walls.append(file)
def del_wall(self, num):
if num >=0 and num < self.walls.count:
del self.walls[num]
else:
print 'Error: No such file!'
def clear_wall(self):
self.walls = []
def show_wall(self):
print '---- list of available wallpapers ----'
for wall in self.walls:
print wall
def count_wall(self):
return self.walls.count
def set_wall_duration(self, time):
self.time = time
def __set_conf_file(self, path):
self.__conf_fd = open(path, 'w')
sys.stdout = self.__conf_fd
def __set_conf_file_finish(self):
sys.stdout = self.__saveout
self.__conf_fd.close()
def output_conf_file(self, path=''):
if len(self.walls) < 2:
print 'Error: Make sure that you have added enough wallpapers? Try to add at least two wallpapers.'
return False
# Rediect stdout to conf file.
if path != '':
self.__set_conf_file(path)
# Generate configure file.
p = Printer()
p.start()
p.set_start_time()
item = self.walls[0]
item_next = None
item_remainder = self.walls[1:]
for item_next in item_remainder:
p.set_static_bg(item)
p.set_transition(item, item_next)
item = item_next
# Roll back to first wallpaper
p.set_static_bg(item_next)
p.set_transition(item_next, self.walls[0])
p.end()
# Restore stdout.
if path != '':
self.__set_conf_file_finish()
return True
if __name__ == '__main__':
cwd = os.getcwd()
default_dirs = [cwd]
default_conf = cwd + "/dyn-wall.xml"
parser = optparse.OptionParser()
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=True,
help="make lots of noise[default]")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=False,
help="be quiet")
parser.add_option("-f", "--filename",
action="append", dest="wallfiles", metavar="FILE", default=list(),
help="wallpaper file")
parser.add_option("-d", "--dir",
action="append", dest="wallpaths", metavar="PATH", default=default_dirs,
help="directory containing wallpapers")
parser.add_option("-o", "--out",
action="store", dest="conf_file", metavar="CONF", default=default_conf,
help="output configration file")
(options, args) = parser.parse_args()
p = Processor()
# Add wall files
for file in options.wallfiles:
p.add_wall(file)
for path in options.wallpaths:
p.add_wall(path)
if options.verbose:
p.show_wall()
# Output conf file
status = p.output_conf_file(options.conf_file)
if status:
if options.verbose:
print 'Generate dynamic wallpaper configure file: %s !' % options.conf_file
print '/nYou can set "%s" as dynamic wallpaper now, have a good day ' % options.conf_file
# end of file
- linux桌面壁纸自动换(类似于windows7壁纸自动换)
- 壁纸自动换
- [Lubuntu] 壁纸自动换
- 如何处理bgswitch,壁纸自动换
- ubuntu 16.04 实现自动换壁纸 幻灯片
- linux shell 换壁纸
- 怎么自动换墙纸?
- win自动换ip脚本
- windows mobile换壁纸
- 批处理自动换IP,给经常换IP的人们
- linux自动更换壁纸脚本
- adsl批处理 自动断开拨号 换IP
- excel表格中隔行自动换颜色?
- div+css 横排自动换列显示
- “自动换列”的CSS设计
- 解决android textview自动换…
- 如何给插件实现自动换肤
- FW300R路由器自动断线换IP
- C#正则表达式编程(三):Match类和Group
- 电源低功耗设计分析
- archlinux 简单安装、配置、使用(部分原创,部分转贴)
- Android开发环境搭建
- 一次失败的淘宝经历
- linux桌面壁纸自动换(类似于windows7壁纸自动换)
- oracle 检查被锁的表及解锁
- Expression Blend实例中文教程(2) - 界面快速入门
- jquery 常用问题
- JS鼠标事件摘录
- POJ 1125 Stockbroker Grapevine(求最短路径—Floyd算法)
- 修正Ehlib5.0.13的一个小问题
- N种内核注入DLL的思路及实现
- android XmlPullParser