From: Oleg Broytman Date: Fri, 27 Jan 2006 16:58:05 +0000 (+0000) Subject: Store the timestamp when the image was used; set a minimum delay between occurences... X-Git-Tag: v4.0.0~65 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=54fa19a157fefa369f13589cdace8b9585bf2379;p=xsetbg.git Store the timestamp when the image was used; set a minimum delay between occurences of the same image. git-svn-id: file:///home/phd/archive/SVN/xsetbg/trunk@3 143022c7-580b-0410-bae3-87f2bf5d3141 --- diff --git a/xsetbg.conf b/xsetbg.conf index 38342e8..cb908d3 100644 --- a/xsetbg.conf +++ b/xsetbg.conf @@ -3,4 +3,5 @@ directory0 = ~/lib/xsetbg/images [xsetbg] min_pause = 60 ; minimum time in seconds between background image changes +min_delay = 86400 ; minimum time in seconds between occurences of the same image borders = darkcyan, steelblue, midnightblue diff --git a/xsetbg.py b/xsetbg.py index 0a4a3f9..cab7b97 100755 --- a/xsetbg.py +++ b/xsetbg.py @@ -6,7 +6,7 @@ Author: Oleg BroytMann Copyright (C) 2000-2006 PhiloSoft Design """ -__version__ = "2.17.0" +__version__ = "3.0.0" __author__ = "Oleg BroytMann " __copyright__ = "Copyright (C) 2000-2006 PhiloSoft Design" __revision__ = "$Id$"[5:-2] @@ -91,6 +91,12 @@ if config.has_option("xsetbg", "borders"): else: borders = ["darkcyan", "steelblue", "midnightblue"] +# minimum time in seconds between occurences of the same image +if config.has_option("xsetbg", "min_delay"): + min_delay = config.getint("xsetbg", "min_delay") +else: + min_delay = 3600*24 # 24 hours + del config @@ -183,8 +189,19 @@ def run(): # Save current time global_db[timestamp_key] = current_time + # Select a random image and check if we've seen it recently; + # loop until we can find a new image (never seen before) or old enough. + for i in xrange(len(images)): # ensure the loop is not infinite + image_name = random.choice(images) + if global_db.has_key(image_name): + image_time = global_db[image_name] + if current_time - image_time > min_delay: + break + else: + break + global_db[image_name] = current_time + border = random.choice(borders) - image_name = random.choice(images) root, ext = os.path.splitext(image_name) # Save filename