]> git.phdru.name Git - xsetbg.git/blobdiff - xsetbg.py
Build: For Python 3.13 SQLObject requires unreleased FormEncode
[xsetbg.git] / xsetbg.py
index 1f318c7265edf8fc13e7cebf76eaeae94b357abb..db2f2d00690fab951d656fe82a1d6023f0ed80bf 100644 (file)
--- a/xsetbg.py
+++ b/xsetbg.py
@@ -50,11 +50,11 @@ if xsetbg_conf.has_option("xsetbg", "min_delay"):
     min_delay = xsetbg_conf.get("xsetbg", "min_delay")
 
     # Borrowed from http://stackoverflow.com/a/2765366
-    td_re = re.compile('(?:(?P<years>\d+)y)?'
-                       '(?:(?P<months>\d+)m)?'
-                       '(?:(?P<days>\d+)d)?'
-                       '(?:T(?:(?P<hours>\d+)h)?'
-                       '(?:(?P<minutes>\d+)m)?(?:(?P<seconds>\d+)s)?)?')
+    td_re = re.compile('(?:(?P<years>\\d+)y)?'
+                       '(?:(?P<months>\\d+)m)?'
+                       '(?:(?P<days>\\d+)d)?'
+                       '(?:T(?:(?P<hours>\\d+)h)?'
+                       '(?:(?P<minutes>\\d+)m)?(?:(?P<seconds>\\d+)s)?)?')
     td_dict = td_re.match(min_delay).groupdict(0)
     delta = timedelta(days=int(td_dict['days']) +
                       (int(td_dict['months']) * 30) +
@@ -73,7 +73,7 @@ else:
 
 
 if xsetbg_db.select(
-        '(is_image = 1) AND (last_shown IS NULL OR last_shown < %d)' %
+        '(is_image = 1) AND show AND (last_shown IS NULL OR last_shown < %d)' %
         (time() - min_delay)).count() == 0:
     error("No unshown images found. Run rescan_fs.py "
           "or decrease min_delay. Abort.")
@@ -94,7 +94,7 @@ def change(force=False):
 
     try:
         timestamp = xsetbg_db.select(
-            '(is_image = 1) AND (last_shown IS NOT NULL)',
+            '(is_image = 1) AND show AND (last_shown IS NOT NULL)',
             orderBy='-last_shown')[0].last_shown
         current_time = time()
 
@@ -105,13 +105,13 @@ def change(force=False):
 
         # Select a random image that has never been shown
         not_shown_select = xsetbg_db.select(
-            '(is_image = 1) AND (last_shown IS NULL)')
+            '(is_image = 1) AND show AND (last_shown IS NULL)')
         not_shown_count = not_shown_select.count()
         if not_shown_count:
             row = not_shown_select[random.randint(0, not_shown_count - 1)]
         else:
             old_shown_select = xsetbg_db.select(
-                '(is_image = 1) AND '
+                '(is_image = 1) AND show AND '
                 '(last_shown IS NOT NULL AND last_shown < %d)' %
                 current_time - min_delay)
             old_shown_count = old_shown_select.count()
@@ -129,6 +129,12 @@ def change(force=False):
         if ext in ('tif', 'tiff'):
             program_options[0] = 'xsetbg'
 
+        if ext == 'webp':
+            program_options = ['display', '-backdrop',
+                               '-background', random.choice(borders),
+                               '-window', 'root',
+                               row.full_name.encode(fs_encoding)]
+
         rc = subprocess.call(program_options)
         if rc:
             error("cannot execute xli!")