User Tools

Site Tools


change-wallpaper-mfk.py
#!/usr/bin/python
#
# change-wallpaper-mfk.py
#
# A script to change to a random background image
#
# Hacked together by Mithat Konar from code:
# (c) 2004, Davyd Madeley <davyd@madeley.id.au>
# http://oracle.bridgewayconsulting.com.au/~danni/misc/change-background-py.html
# edited 8/2006 by Horst JENS <Horst.Jens@gmx.at>
# edited again 12 / 2006 also by Horst JENS
# (http://videos1.showmedo.com/ShowMeDos/extras/linuxJensMakingDeb/wallpaperslidechanger_py)
#
#   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.
#
 
backgrounds = "./Pictures/Wallpaper"
 
import gconf
import os
import random
import mimetypes
 
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 ()
 
 
dir_items = os.listdir (os.path.join (os.environ["HOME"], backgrounds))
items = []
 
for item in dir_items:
        mimetype = mimetypes.guess_type (item)[0]
        if mimetype and mimetype.split ('/')[0] == "image":
                items.append (item)
 
item = random.randint (0, len (items) - 1)
current_bg = client.get_background ()
 
while (items[item] == current_bg):
        item = random.randint (0, len (items) - 1)
 
client.set_background (os.path.join (os.environ["HOME"], backgrounds, items[item]))
 
option = "stretched"
#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"]
change-wallpaper-mfk.py.txt · Last modified: 2009-10-06 15:39 (external edit)