home · contact · privacy
Browser: On "by first sorter", show sorted values as header to gallery grid.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 25 Sep 2024 05:29:19 +0000 (07:29 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 25 Sep 2024 05:29:19 +0000 (07:29 +0200)
browser.py

index 56b46f83d2097729762fd30baf23ed1b6c1ca5c7..15d82c26bc7f15d5a7c74b93cf4ace01d8907efc 100755 (executable)
@@ -219,14 +219,19 @@ class Gallery:
         self.items_attrs_filtered = {}
 
         self._fixed_frame = Gtk.Fixed(hexpand=True, vexpand=True)
-        self.scroller = Gtk.ScrolledWindow(propagate_natural_height=True)
-        self.scroller.get_vadjustment().connect(
+        scroller = Gtk.ScrolledWindow(propagate_natural_height=True)
+        self.frame = Gtk.Box(orientation=OR_V)
+        self._col_headers_frame = Gtk.Fixed()
+        self._col_headers_grid = None
+        self.frame.append(self._col_headers_frame)
+        self.frame.append(scroller)
+        scroller.get_vadjustment().connect(
                 'value-changed', lambda _: self._update_view(refocus=False))
         # We want our viewport at always maximum possible size (so we can
         # safely calculate what's in it and what not), even if the gallery
         # would be smaller. Therefore we frame the gallery in an expanding
         # Fixed, to stretch out the viewport even if the gallery is small.
-        self.scroller.set_child(self._fixed_frame)
+        scroller.set_child(self._fixed_frame)
         self._viewport = self._fixed_frame.get_parent()
 
         self._should_update_view = True
@@ -479,6 +484,18 @@ class Gallery:
             slot_bottom = slot_top + slot_size
             in_vp = (slot_bottom >= vp_top and slot_top <= vp_bottom)
             slot.update_widget(slot_size, self._slot_margin, in_vp)
+        if self._col_headers_grid:
+            self._col_headers_frame.remove(self._col_headers_grid)
+            self._col_headers_grid = None
+        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])
+            for i, val in enumerate(attr_values):
+                label = Gtk.Label(label=str(val))
+                label.set_size_request(slot_size, -1)
+                self._col_headers_grid.attach(label, i, 0, 1, 1)
         self._should_update_view = False
         if (not refocus) or (not self.slots):
             return
@@ -677,7 +694,7 @@ class MainWindow(Gtk.Window):
         viewer = Gtk.Box(orientation=OR_V)
         self.navbar = init_navbar()
         viewer.append(self.navbar)
-        viewer.append(self.gallery.scroller)
+        viewer.append(self.gallery.frame)
         self.side_box = Gtk.Box(orientation=OR_V)
         self.sort_box = init_sorter_and_filterer()
         self.side_box.append(self.sort_box)