]> git.phdru.name Git - xsetbg.git/commitdiff
Feat: Enable/disable images
authorOleg Broytman <phd@phdru.name>
Mon, 12 Aug 2024 16:02:43 +0000 (19:02 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 12 Aug 2024 16:19:53 +0000 (19:19 +0300)
TODO
enable.py [new file with mode: 0755]
rescan_fs.py
xsetbg.py
xsetbg_db.py

diff --git a/TODO b/TODO
index 7dacb2c4e60465e213f238f5a84bb55022fdb77f..71bd2bf36598af403e0c927a817aa79f7fbf571b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -2,7 +2,3 @@ OSD: Image title on screen. Should be in a real window to stay permanent.
 
 
 Min (and max?) image dimensions?
-
-
-Rating (likes and dislikes) to show more interestin pictures
-and skip less interesing?
diff --git a/enable.py b/enable.py
new file mode 100755 (executable)
index 0000000..a1f2d00
--- /dev/null
+++ b/enable.py
@@ -0,0 +1,77 @@
+#! /usr/bin/env python3
+"""Enable/disable images
+
+This file is a part of XSetBg.
+
+"""
+
+import sys
+from getopt import getopt, GetoptError
+
+from xsetbg_db import xsetbg_db
+
+if not xsetbg_db:
+    sys.exit("Error: no database found")
+
+
+def usage(code=0):
+    sys.stderr.write("Usage: %s [-e|--enable] [-d|--disable] [-c|--clear]"
+                     " [-i|--id=<id>] [filename]\n" % sys.argv[0])
+    sys.exit(code)
+
+
+try:
+    options, arguments = getopt(sys.argv[1:], "edci:",
+                                ["enable", "disable", "clear",
+                                 "id="])
+except GetoptError:
+    usage(1)
+
+enable = disable = clear = _id = filename = None
+
+for option, value in options:
+    if option in ("-e", "--enable"):
+        enable = True
+    if option in ("-d", "--disable"):
+        disable = True
+    if option in ("-c", "--clear"):
+        clear = True
+    if option in ("-i", "--id"):
+        _id = value
+
+if arguments:
+    if len(arguments) == 1:
+        try:
+            filename = arguments[0]
+        except ValueError:
+            usage(1)
+    else:
+        usage(1)
+
+if int(bool(enable)) + int(bool(disable)) + int(bool(clear)) != 1:
+    usage(1)
+
+if int(bool(_id)) + int(bool(filename)) != 1:
+    usage(1)
+
+if _id:
+    rows = list(xsetbg_db.selectBy(id=_id))
+    if not rows:
+        sys.exit("No rows by id %s" % _id)
+elif filename:
+    rows = list(xsetbg_db.selectBy(full_name=filename))
+    if not rows:
+        sys.exit("No rows by filename %s" % filename)
+else:
+    usage(1)
+
+row = rows[0]
+
+if enable:
+    row.show = True
+elif disable:
+    row.show = False
+elif clear:
+    row.show = None
+else:
+    usage(1)
index 24302fea4966a2f7259077ac8d24e65813dea435..b8284a93b55c8b263c0f5631adafff80cebf3523 100755 (executable)
@@ -67,9 +67,11 @@ with SQLiteMassInsert() as txn:
                 try:
                     row = xsetbg_db.byFull_name(full_name)
                 except SQLObjectNotFound:
+                    image_and_show = is_image(full_name)
                     values = {'full_name': full_name,
-                              'is_image': is_image(full_name),
+                              'is_image': image_and_show,
                               'flag': True,
+                              'show': image_and_show,
                               }
                     query = txn.sqlrepr(Insert(xsetbg_db.sqlmeta.table,
                                                values=values))
@@ -77,7 +79,8 @@ with SQLiteMassInsert() as txn:
                     count_new += 1
                 else:
                     if row.is_image is None:
-                        row.is_image = is_image(full_name)
+                        row.is_image = image_and_show = is_image(full_name)
+                        row.show = image_and_show
                     row.flag = True
                     count_old += 1
     count_del = xsetbg_db.select('flag IS NULL').count()
index 825b20eb0f9c927614a5285d4c8467524b3c5380..db2f2d00690fab951d656fe82a1d6023f0ed80bf 100644 (file)
--- a/xsetbg.py
+++ b/xsetbg.py
@@ -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()
index ba5ab6c7630cccbdd55cd717000d8ab111f207a4..638ce49fe55cdb157bd7b640895a38fb4977df49 100755 (executable)
@@ -19,10 +19,12 @@ class XSetBg(SQLObject):
     last_shown = IntCol(default=None)  # timestamp
     flag = BoolCol(default=None)
     is_image = BoolCol(default=None)
+    show = BoolCol(default=True)
 
     last_shown_idx = DatabaseIndex('last_shown')
     flag_idx = DatabaseIndex('flag')
     is_image_idx = DatabaseIndex('is_image')
+    show_idx = DatabaseIndex('show')
 
 
 def recreate_db():