#!/usr/bin/python import gconf, sys, os, string, random, mimetypes activePath = os.getcwd() + '/.backgrounds' dataFilePath = activePath + "/.dataFile" 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_Images (self, images) : dataFile = file (dataFilePath, "w") for image in images: dataFile.write (image + "\n") dataFile.close () def get_Filenames(self): directoryList = [] if os.path.exists(dataFilePath) : for line in file(dataFilePath) : directoryList.append(line[:-1]) if len(directoryList) < 1 : directoryListing = os.listdir (activePath) for image in directoryListing: mimetype = mimetypes.guess_type (image)[0] if mimetype and mimetype.split ('/')[0] == "image": directoryList.append (image) return directoryList def get_Images(self): images = self.get_Filenames() return images client = GConfClient () current_bg = client.get_background () current_images = client.get_Images() randIndex = random.randint(0, len(current_images)-1) client.set_background (activePath + "/" + current_images[randIndex]) current_images.remove(current_images[randIndex]) client.set_Images(current_images)