#!/usr/bin/env pythonimportosimportreimportstringimportsysfromos.pathimportisdir# ---------------------------------- About ----------------------------------- ## This file inserts a wallpaper pipe menu into Openbox which uses feh ## in order to set the wallpaper from a chosen directory. ## ## Authors: dav1d(main author) and Pwnz3r(hacker and redistributor) ## ## Dav1d's site: http://southwing.homeip.net/~david/ ## Pwnz3r's site: http://pstudios.ath.cx/ ## ## ------------------------------ Setting it up ------------------------------- ## feh automatically inserts the full command string used to set the wallpaper ## into ~/.fehbg. In order to set the wallpaper back at the next start of ## Openbox, just add the following to ~/.xinitrc. ## ## eval `cat ~/.fehbg` ## ---------------------------------------------------------------------------- ## types of files accepted (list, seperated by a |)filetypes="jpg|png|gif"# directory where wallpapers are stored (must be long: no ~ symbol allowed)directory=sys.argv[1]# program to set wallpaper defined in the command stringprogram="feh --bg-scale"defgenmenu(start,directory):# get a directory listdirlist=os.listdir(directory)fordindirlist:# set di to overall directorydi=directory+"/"+d# if we get a dir, generate a menuifisdir(di)and".thumbnails"notindi:print""print" <menu id=\""+di+"\" label=\""+d+"\" >"genmenu(start,di)print" </menu>"# if we get a file, check if it is a valid typeelse:ifre.search(filetypes,string.lower(di))>0:# make fi variable just filename, without extensionfi=string.replace(string.replace(di,directory,""),"/","")fi=fi[:string.rfind(fi,".")]# if so, add it to the pipe menuprint" <item label=\""+fi+"\">"# execute line to set wallpaperprint" <action name=\"Execute\"><execute>"+program+" \""+di+"\"</execute></action>"# if we want to update config file, do soprint" </item>"defmain():# start menuprint"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"print"<openbox_pipe_menu>"# set the original start directorystart=directory# generate menugenmenu(start,directory)# end menuprint"</openbox_pipe_menu>"# run the main() functionif__name__=="__main__":main()