################################################################### # This is a port (if you could call it that) of the php Blackbox # background script to Python. Got to start somewhere don't I? # # At the command line, different aguments can be passed to get some # different behaviour. The list is below... # -m=# For multiple desktops where # is the number of # desktops to display # -o Just choose an image at random and exit. No desktop # slideshow. # -s Scales the image ignoring aspect ratio ################################################################### # Let's import the things we know we will need import dircache, time, commands, sys import getopt, random, re, types # import wx ################################################################### # As the name implies, show usage information for the script def usage(): print 'Command line parameters for bb_bg.' print '-o = image Display the selected image and exit.' print '-s Scales the image ignoring aspect ratio.' print '-v A verbose option. Dumps wmsetbg error messages.' print '-u Print this usage message.' print '-i Interval for slide show.' print ################################################################### ################################################################### # As this is starting to get rather messy, perhaps we should put # command line arg processing section in a function def proc_args(options): print options for o, a in options: print o print 'You\'re an idiot!' sys.exit() ################################################################### # Vars and things big_list = list() directories = list() verbose = str() just_one = str() rand_desk = str() interv = 30.0 # Grab the command line arguments for arg in sys.argv: print arg try: # We aren't using any long options so this is fine opts, args = getopt.getopt(sys.argv[1:], "i:o:su") except getopt.GetoptError: # print help information and exit: usage() sys.exit(2) # proc_args(opts) # sys.exit() # Process command line arguments for o, a in opts: if o == "-i": interv = a interv=float(interv) # The argument comes in as a string so we need to convert to a float if o == "-v": verbose = True if o == "-u": usage() sys.exit() if o in ("-h", "--help"): usage() sys.exit() if o in ("-o", "--output"): item = a if o == "-s": keep_aspect = False if o == "-o": just_one = True # If the user just want's to set the background, if just_one == True: commands.getoutput('wmsetbg -a %s' % (item)) sys.exit() # We want to open the config file for line in file("/home/big/.bb_bg"): print line line = line.strip() fields = line.split("]") # needs 2.2.2 or higher for entry in fields: directories.append(entry) # Well, the first thing I want to do here is just open a directory for dis in directories: images = dircache.listdir(dis) # Loop through the directories and put their contents into a list for item in images: item_tmp = item.lower() if item_tmp.find('.jpeg') == -1 and item_tmp.find('.png') == -1 and item_tmp.find('.gif') == -1 and item_tmp.find('.jpg') == -1: continue num = random.randrange(1, 60) big_list.append(item) # Loop end. Damn! That was easy! # Shuffle the list random.shuffle(big_list) # That done, iterate continously over the lists, with delays of course, # showing the backgrounds while 1: for item in big_list: # print out the name of the image, should we want to see, and # execute wmsetbg here print item out = commands.getoutput('wmsetbg -a %s' % (item)) print out if interv > 0: time.sleep(interv) else: time.sleep(10) # end loop #