home · contact · privacy
Browser: Fix by_1st view showing wrong first-row attributes.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 27 Oct 2024 03:39:16 +0000 (04:39 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 27 Oct 2024 03:39:16 +0000 (04:39 +0100)
browser.py

index 57c84c3d8bb4b1677b5705fe1e78b82b6e4c436b..28ed0c64fa8e4af0a69a944346e559088f0ade98 100755 (executable)
@@ -831,6 +831,8 @@ class Gallery:
 
             if self._grid:
                 self._fixed_frame.remove(self._grid)
+            if self._col_headers_grid:
+                self._col_headers_frame.remove(self._col_headers_grid)
             self.slots = []
             self._grid = Gtk.Grid()
             self._fixed_frame.put(self._grid, 0, 0)
@@ -846,6 +848,17 @@ class Gallery:
                     sort_attrs += [(s_name, self.items_attrs[s_name]['incl'])]
                 self._per_row = len(sort_attrs[-1][1])
                 build_rows_by_attrs(sort_attrs, entries_filtered, [])
+                self._col_headers_grid = Gtk.Grid()
+                self._col_headers_frame.put(self._col_headers_grid, 0, 0)
+                self._col_headers_grid.attach(Gtk.Box(), 0, 0, 1, 1)
+                top_attr_name = sort_attrs[-1][0]
+                for i, val in enumerate(sort_attrs[-1][1]):
+                    label = Gtk.Label(label=f'<b>{top_attr_name}</b>: {val}',
+                                      xalign=0,
+                                      ellipsize=Pango.EllipsizeMode.MIDDLE)
+                    label.set_use_markup(True)
+                    self._col_headers_grid.attach(label, i + 1, 0, 1, 1)
+
             else:
                 dir_entries_filtered_sorted = sorted(
                         entries_filtered, key=cmp_to_key(self._sort_cmp))
@@ -930,23 +943,17 @@ class Gallery:
             i_vlabels += 1
         max_slot_width = (vp_width - side_offset) // self._per_row
         slot_size = min(vp_height, max_slot_width)
-        if self._col_headers_grid:
-            self._col_headers_frame.remove(self._col_headers_grid)
-            self._col_headers_grid = None
         if self._by_1st:
-            self._col_headers_grid = Gtk.Grid()
-            spacer_box = Gtk.Box()
-            spacer_box.set_size_request(side_offset, -1)
-            self._col_headers_grid.attach(spacer_box, 0, 0, 1, 1)
-            self._col_headers_frame.put(self._col_headers_grid, 0, 0)
-            attr_name = self._sort_order[0].name
-            attr_values = self.items_attrs[attr_name]['incl']
-            for i, val in enumerate(attr_values):
-                label = Gtk.Label(label=f'<b>{attr_name}</b>: {val}', xalign=0,
-                                  ellipsize=Pango.EllipsizeMode.MIDDLE)
-                label.set_use_markup(True)
-                label.set_size_request(slot_size, -1)
-                self._col_headers_grid.attach(label, i + 1, 0, 1, 1)
+            i_widgets = 0
+            while True:
+                widget = self._col_headers_grid.get_child_at(i_widgets, 0)
+                if 0 == i_widgets:
+                    widget.set_size_request(side_offset, -1)
+                elif isinstance(widget, Gtk.Label):
+                    widget.set_size_request(slot_size, -1)
+                else:
+                    break
+                i_widgets += 1
         slot_size_sans_margin = slot_size - self._slot_margin
         for idx, slot in enumerate(self.slots):
             slot.ensure_slot_size(slot_size_sans_margin, self._slot_margin)