From: Christian Heller Date: Thu, 24 Oct 2024 16:47:55 +0000 (+0200) Subject: Browser.py: In filtered attribute values count, differentiate what's suppressed by... X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/unset_cookie?a=commitdiff_plain;h=be9fd3d481e9fb956550464fbbac2586fc09b947;p=stable_plom Browser.py: In filtered attribute values count, differentiate what's suppressed by own filter and by other filters. --- diff --git a/browser.py b/browser.py index 223f118..b775516 100755 --- a/browser.py +++ b/browser.py @@ -124,11 +124,14 @@ class SorterAndFilterer(GObject.GObject): self.widget = widget # label len_incl = len(vals['incl']) - title = f'{self.name} ({len_incl}/{len_incl + len(vals["excl"])}) ' + len_semi_total = len_incl + len(vals['semi']) + len_total = len_semi_total + len(vals['excl']) + title = f'{self.name} ({len_incl}/{len_semi_total}/{len_total}) ' self.widget.label.set_text(title) # values listing vals_listed = [f'{v}' for v in vals['incl']] - vals_listed += [f'{v}' for v in vals['excl']] + vals_listed += [f'{v}' for v in vals['semi']] + vals_listed += [f'{v}' for v in vals['excl']] self.widget.values.set_text(', '.join(vals_listed)) self.widget.values.set_use_markup(True) # filter input @@ -729,24 +732,39 @@ class Gallery: def build_items_attrs(): self.items_attrs.clear() - self.items_attrs |= {s.name: {'incl': [], 'excl': []} - for s in self._sort_order} + + def collect_and_split_attr_vals(entries): + items_attrs_tmp = {} + for attr_name in (s.name for s in self._sort_order): + items_attrs_tmp[attr_name] = {'incl': [], 'excl': []} + vals = set() + for entry in [e for e in entries + if isinstance(e, ImgItem)]: + val = (getattr(entry, attr_name) + if hasattr(entry, attr_name) else None) + if val is not None: + vals.add(val) + for v in vals: + k = ('incl' if self._passes_filter(attr_name, v) + else 'excl') + items_attrs_tmp[attr_name][k] += [v] + return items_attrs_tmp + + items_attrs_tmp_1 = collect_and_split_attr_vals(self.dir_entries) + filtered_entries = filter_entries(items_attrs_tmp_1) + items_attrs_tmp_2 = collect_and_split_attr_vals(filtered_entries) for attr_name in (s.name for s in self._sort_order): - vals = set() - for entry in [e for e in self.dir_entries - if isinstance(e, ImgItem)]: - val = (getattr(entry, attr_name) - if hasattr(entry, attr_name) else None) - if val is not None: - vals.add(val) - for v in vals: - k = 'incl' if self._passes_filter(attr_name, v) else 'excl' - self.items_attrs[attr_name][k] += [v] - for attr_vals in self.items_attrs.values(): - attr_vals['incl'].sort() - attr_vals['excl'].sort() - - def filter_entries(): + final_values = {'incl': [], 'semi': []} + final_values['excl'] = items_attrs_tmp_1[attr_name]['excl'] + for v in items_attrs_tmp_1[attr_name]['incl']: + k = ('incl' if v in items_attrs_tmp_2[attr_name]['incl'] + else 'semi') + final_values[k] += [v] + for category in ('incl', 'semi', 'excl'): + final_values[category].sort() + self.items_attrs[attr_name] = final_values + + def filter_entries(items_attrs): entries_filtered = [] for entry in self.dir_entries: if (not self._show_dirs) and isinstance(entry, DirItem): @@ -756,7 +774,7 @@ class Gallery: if isinstance(entry, ImgItem): val = (getattr(entry, attr_name) if hasattr(entry, attr_name) else None) - if val in self.items_attrs[attr_name]['excl']: + if val not in items_attrs[attr_name]['incl']: passes_filters = False break if passes_filters: @@ -838,7 +856,7 @@ class Gallery: self._shall_build = False old_selected_item = self.selected_item build_items_attrs() - entries_filtered = filter_entries() + entries_filtered = filter_entries(self.items_attrs) build_grid(entries_filtered) new_idx = 0 if old_selected_item is not None: