]> git.phdru.name Git - xsetbg.git/commitdiff
Store the timestamp when the image was used; set a minimum delay between occurences...
authorOleg Broytman <phd@phdru.name>
Fri, 27 Jan 2006 16:58:05 +0000 (16:58 +0000)
committerOleg Broytman <phd@phdru.name>
Fri, 27 Jan 2006 16:58:05 +0000 (16:58 +0000)
git-svn-id: file:///home/phd/archive/SVN/xsetbg/trunk@3 143022c7-580b-0410-bae3-87f2bf5d3141

xsetbg.conf
xsetbg.py

index 38342e81c003fb5c01b115dce23ad468d99f518c..cb908d314f481990c215cbb79a6e9fe050d804ac 100644 (file)
@@ -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
index 0a4a3f97b6169e3de3bbe12035b2d97b5b5abab6..cab7b9778c04e614b1c525a6627666821db1781c 100755 (executable)
--- a/xsetbg.py
+++ b/xsetbg.py
@@ -6,7 +6,7 @@ Author: Oleg BroytMann <phd@phd.pp.ru>
 Copyright (C) 2000-2006 PhiloSoft Design
 """
 
-__version__ = "2.17.0"
+__version__ = "3.0.0"
 __author__ = "Oleg BroytMann <phd@phd.pp.ru>"
 __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