#!/usr/bin/env python # # GBackground v0.1 # (c) 2008 Adam Shamblin, adam@iratepublik.com # # Inspired by Davyd's script: # http://oracle.bridgewayconsulting.com.au/~davyd/misc/change-background-py.html # # 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 random import time from xml.dom.minidom import parse class GBackground: def __init__ (self): self.backgroundsDB = '.gnome2/backgrounds.xml' self.__initGConfClient() self.__initDOM() self.__files = [] def __initGConfClient (self): self.__gclient = gconf.client_get_default() def __initDOM (self): db = os.path.join( os.environ['HOME'], self.backgroundsDB ) fh = open(db) self.__dom = parse(fh) fh.close() def loadBackgrounds (self): for wallpaper in self.__dom.getElementsByTagName('wallpaper'): if wallpaper.getAttribute('deleted') == 'true': continue filename = wallpaper.getElementsByTagName('filename')[0].firstChild.nodeValue self.__files.append(filename) def setRandomBackground (self): rnd = random.randint(0, len(self.__files) - 1) self.setBackground( self.__files[rnd] ) def getBackground (self): return self.__gclient.get_string('/desktop/gnome/background/picture_filename') def setBackground (self, background): self.__gclient.set_string ("/desktop/gnome/background/picture_filename", background) def main (): gb = GBackground() gb.loadBackgrounds() while (1): gb.setRandomBackground() time.sleep(900) if __name__ == '__main__': main()