Das besondere an dem Skript: Im Gegensatz zu anderen Hintergrund-wechsel-Programmen wird hier nicht verlangt daß alle erwünschten Hintergrundbilder in einem bestimmten Verzeichnis liegen. Stattdessen wird ein neues Verzeichnis namens ".wallpaperchanger" erstellt und dort eine Datei namens "wallpaperchangerconfig.py" erzeugt. Diese Datei ist per Texteditor veränderbar und enthält:
- Liste von Bilder-Verzeichnissen, welche rekursiv durchsucht werden (inkl. Unterverzeichnisse)
Liste von Schlüsselwörtern, bei deren Vorkommen ein Bild NICHT verwendet werden soll (zB "Thumbnail"
Liste von Schlüsselwörtern, bei deren Vorkommen ein Bild gekachelt (gestreckt, gezoomt, skaliert) werden soll.
Python Skript und fertiges .deb-Paket für Ubuntu stehen hier zum download bereit: http://members.chello.at/horst.jens/files.htm
Python-Skript Quellcode:
Code: Alles auswählen
#!/usr/bin/python
#
# wallpaperchanger.py
#
# A script to change your gnome wallpaper to a random background image
#
# (c) 2004, Davyd Madeley <davyd@madeley.id.au>
# edited 8/2006 by Horst JENS <Horst.Jens@gmx.at>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import gconf
import os
import sys
import random
import mimetypes
if os.name != 'posix':
raise SystemExit, "no-linux Operations System detected. Yuk !"
sys.path.append(os.environ["HOME"])
sys.path.append(os.path.join(os.environ["HOME"], '.wallpaperchanger'))
configdir = os.path.join(os.environ["HOME"], '.wallpaperchanger')
try:
from wallpaperchangerconfig import * # try to import config file
#print "config file imported."
except:
print 'could not import configfile, so fresh configfile will be created in ~/.wallpaperchanger'
os.chdir(os.environ["HOME"])
try:
os.mkdir('.wallpaperchanger')
except:
pass # if you can not create a directory, it may already exist...
os.chdir('.wallpaperchanger')
try:
c = file('wallpaperchangerconfig.py','w')
c.write('#config file for wallpaperchanger \n')
c.write('#must be located in ~/.wallpaperchanger \n')
c.write('#and must be named wallpaperchangerconfig.py \n')
c.write('#all text behind a # is a comment \n')
c.write('#you can edit this file as you like \n')
c.write('#all directorys listed here will be searched recursive (INCLUDING their sub-directorys). Example: \n')
c.write('# picturedirs = ["/home", "/media/win_c/pictures", "/media/win_d/personal/mycat/"] \n')
c.write('picturedirs = ["/home"] \n')
c.write('#all keywords listed here will make the wallpaper tiled if keyword is found in pathname or filename. \n')
c.write('keywords_tiled = ["tiled", "pattern"] \n')
c.write('#all keywords listed here will make the wallpaper centered if keyword is found in pathname or filename. \n')
c.write('keywords_centered = ["centered"] \n')
c.write('#all keywords listed here will make the wallpaper zoomed if keyword is found in pathname or filename. \n')
c.write('keywords_zoomed = ["zoomed"] \n')
c.write('#all keywords listed here will make the wallpaper streched if keyword is found in pathname or filename. \n')
c.write('keywords_stretched = ["stretched"] \n')
c.write('# per default, all wallpapers will be "scaled" if no other keyword is found. \n')
c.write('#if any of the keywords listed here is found in filename or pathname, file will NOT be used as wallpaper.. \n')
c.write('keywords_exclude = ["privat", "secret", "bad", "ugly", "temp", "thumb"] \n')
c.close()
except:
raise SystemExit, "could not write configfile to ~/.wallpaperchanger . Please check write permissions."
from wallpaperchangerconfig import * # try to import config file
#print "config file written to ~/.wallpaperchanger and imported."
class GConfClient:
def __init__(self):
self.__client__ = gconf.client_get_default ()
def get_background(self):
return self.__client__.get_string("/desktop/gnome/background/picture_filename")
def set_background(self, background):
self.__client__.set_string("/desktop/gnome/background/picture_filename", background)
def set_option (self, option):
self.__client__.set_string("/desktop/gnome/background/picture_options", option)
client = GConfClient()
imageitems = []
for picturedir in picturedirs:
for rootdir, dirlist, filelist in os.walk(picturedir): # recursive scan for filenames
for file in filelist:
mimetype = mimetypes.guess_type(file)[0]
if mimetype and mimetype.split('/')[0] == "image":
clean = True
for keyword in keywords_exclude:
if keyword in rootdir or keyword in file:
clean = False
if clean == True:
imageitems.append(os.path.join(rootdir,file))
if len(imageitems) < 1:
raise SystemExit, "no pictures found"
item = random.randint(0, len (imageitems) - 1)
current_bg = client.get_background()
while (imageitems[item] == current_bg):
item = random.randint(0, len(imageitems) - 1)
client.set_background(imageitems[item])
option = "scaled" # default
for keyword in keywords_tiled:
if keyword in imageitems[item]:
option = "wallpaper"
for keyword in keywords_centered:
if keyword in imageitems[item]:
option = "centered"
for keyword in keywords_zoomed:
if keyword in imageitems[item]:
option = "zoom"
for keyword in keywords_stretched:
if keyword in imageitems[item]:
option = "stretched"
client.set_option(option)
#print "setting wallpaper" , imageitems[item], "with the option", option
#options = ["scaled","wallpaper", "zoom", "centered", "streched"]
Kommentare ?
