home · contact · privacy
Browser: Minor refactoring.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 25 Sep 2024 05:36:34 +0000 (07:36 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 25 Sep 2024 05:36:34 +0000 (07:36 +0200)
browser.py

index 15d82c26bc7f15d5a7c74b93cf4ace01d8907efc..858fa8d5b3276d53031026eda406ebe77c8ec56e 100755 (executable)
@@ -67,9 +67,8 @@ class Sorter(GObject.GObject):
         self.widget = widget
         title = f'{self.name} ({len(vals_filtered)}/{len(vals_full)}) '
         widget.get_first_child().get_first_child().set_text(title)
-        vals_listed = [f'<b>{val}</b>' if val in vals_filtered
-                       else f'<s>{val}</s>'
-                       for val in sorted(vals_full)]
+        vals_listed = [f'<b>{v}</b>' if v in vals_filtered else f'<s>{v}</s>'
+                       for v in vals_full]
         widget.get_last_child().set_text(', '.join(vals_listed))
         widget.get_last_child().set_use_markup(True)
         filter_entry = widget.get_first_child().get_last_child()
@@ -359,6 +358,9 @@ class Gallery:
                         self.items_attrs_filtered[attr_name].add(val)
             if passes_filters:
                 entries_filtered += [entry]
+        for d in (self.items_attrs, self.items_attrs_filtered):
+            for k, v in d.items():
+                d[k] = sorted(list(v))
         return entries_filtered
 
     def _build_grid(self, entries_filtered):
@@ -405,8 +407,8 @@ class Gallery:
             self.show_dirs = False
             sort_attrs = []
             for sorter in reversed(self._sort_order):
-                values = self.items_attrs_filtered[sorter.name]
-                sort_attrs += [(sorter.name, sorted(list(values)))]
+                sort_attrs += [(sorter.name,
+                                self.items_attrs_filtered[sorter.name])]
             i_row_ref = [0]
             i_slot_ref = [0]
             self.per_row = len(sort_attrs[-1][1])
@@ -490,8 +492,7 @@ class Gallery:
         if self.per_row_by_first_sorter:
             self._col_headers_grid = Gtk.Grid()
             self._col_headers_frame.put(self._col_headers_grid, 0, 0)
-            attr_name = self._sort_order[0].name
-            attr_values = sorted(self.items_attrs_filtered[attr_name])
+            attr_values = self.items_attrs_filtered[self._sort_order[0].name]
             for i, val in enumerate(attr_values):
                 label = Gtk.Label(label=str(val))
                 label.set_size_request(slot_size, -1)