####################################################################### ''' Simple script maden by Bortoli German this is usefull to create background with sliders for Gnome Desktop Enviroments It autogenerate the XML that contains the instructions Usage: Run the script inside a folder that contain the images that you want to make a slider. ''' ####################################################################### ############# CONFIG ################################################## ########## Time in minuts that you want to slide minutos = 20; ########### END CONFIG ################################################ minutos = minutos * 60 minutos = str(minutos) ##Converted to seconds and string ## START OF PROGRAM ################################################## import os, sys,mimetypes, string cur_path = os.getcwd() #get the current filepath cont_args = sys.argv.__len__() # Get the pathname with the first argument if the folder doesnt exist # it will generate the slider from current location if (cont_args == 2): if os.path.exists(sys.argv[1]): print "Generating images from: "+sys.argv[1] cur_path = sys.argv[1] else: print "The input file is not valid, generating slider from current directory ..." files = os.listdir( cur_path ) #get the files inside the path ## EndIf # The 3 argument is the output name of the XML file if (cont_args == 3): xml_name = sys.argv[2] else: xml_name = "background.xml" images = [] for f in files: pos = mimetypes.guess_type(f) pos = pos[0].find('image') #get the images mymtypes if (pos >= 0): images.append( f ) #save all images inside image array #-- EndFor files = None #unset the variable cont = images.__len__() #count array elements # Create the XML body xml_start = "20090804000000" xml_end = "" xml_content = '' if cont != 0: # Start to generate the XML content i = 0 while i < cont: if i < cont-1: xml_content += " \t\n"+minutos+"\n"+cur_path+"/"+images[i]+"\n\n\n5.0\n"+cur_path+"/"+images[i]+"\n"+cur_path+"/"+images[i+1]+"\n\n" else: xml_content += " \t\n"+minutos+"\n"+cur_path+"/"+images[i]+"\n\n\n5.0\n"+cur_path+"/"+images[i]+"\n"+cur_path+"/"+images[0]+"\n\n" i += 1 #EndWhile print images xml_file = open(xml_name , "w") xml_file.writelines(xml_start+xml_content+xml_end) xml_file.close() #EndIf else: print "There are no images - try to find another sexy (like me) folder"