From: Christian Heller Date: Mon, 23 Sep 2024 05:07:11 +0000 (+0200) Subject: browser.py: Minor fixes, and add regex search to string fields. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Bdb.prefix%7D%7D/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=26f9bd5dd4eeb26a1f4107773dd31022a89d07d3;p=stable_plom browser.py: Minor fixes, and add regex search to string fields. --- diff --git a/browser.py b/browser.py index f218373..fe09e71 100755 --- a/browser.py +++ b/browser.py @@ -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')