home · contact · privacy
browser.py: Minor fixes, and add regex search to string fields.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 23 Sep 2024 05:07:11 +0000 (07:07 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 23 Sep 2024 05:07:11 +0000 (07:07 +0200)
browser.py

index f2183730e83cb77a1967f06e2cf53766cdf31e52..fe09e71588fd6439d27e0a77a8668dead8402cc0 100755 (executable)
@@ -2,6 +2,7 @@
 """Browser for image files."""
 from json import dump as json_dump, load as json_load
 from functools import cmp_to_key
+from re import search as re_search
 from os import listdir
 from os.path import (exists as path_exists, join as path_join, abspath, isdir,
                      splitext, getmtime)
@@ -215,7 +216,7 @@ class Gallery:
 
     def _ensure_updated_view(self):
         """Rather than reload slots every scroll pixel, regularly run this."""
-        if self._should_update_view:
+        if self._should_update_view and self.slots:
             self._update_view(refocus=False, force=True)
         return True
 
@@ -437,6 +438,8 @@ class Gallery:
 
     def _filter_func(self, item):
         """Return if item matches user-set filters."""
+        number_attributes = set(GEN_PARAMS_INT) | set(GEN_PARAMS_FLOAT) | {
+                'BOOKMARKED'}
 
         def number_filter(attr_name, filter_line, to_compare):
             use_float = attr_name.upper() in GEN_PARAMS_FLOAT
@@ -499,12 +502,10 @@ class Gallery:
             if not hasattr(item, filter_attribute):
                 return False
             to_compare = getattr(item, filter_attribute)
-            number_attributes = set(GEN_PARAMS_INT) | set(GEN_PARAMS_FLOAT) | {
-                    'BOOKMARKED'}
             if filter_attribute.upper() in number_attributes:
                 if not number_filter(filter_attribute, value, to_compare):
                     return False
-            elif value not in to_compare:
+            elif not re_search(value, to_compare):
                 return False
         return True
 
@@ -763,7 +764,7 @@ class MainWindow(Gtk.Window):
                     to_set_metadata_on += [item]
                 self.gallery.dir_entries += [item]
             print('')
-            if len(to_set_metadata_on):
+            if to_set_metadata_on:
                 for i, item in enumerate(to_set_metadata_on):
                     msg = f'setting metadata: {i+1}/{len(to_set_metadata_on)}'
                     print(msg, end='\r')