From: Christian Heller Date: Wed, 25 Sep 2024 05:29:19 +0000 (+0200) Subject: Browser: On "by first sorter", show sorted values as header to gallery grid. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/calendar?a=commitdiff_plain;h=9bba6e3a8e1f02ba51c91cc799cc04f5c3bfd4d5;p=stable_plom Browser: On "by first sorter", show sorted values as header to gallery grid. --- diff --git a/browser.py b/browser.py index 56b46f8..15d82c2 100755 --- a/browser.py +++ b/browser.py @@ -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)