From: Christian Heller Date: Sat, 26 Oct 2024 13:52:35 +0000 (+0200) Subject: Browser: In by_1st view, label attribute name of secondary sorters. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/todos?a=commitdiff_plain;h=9481a1fc2bf8373697b408d35f57cdcfcc7d971e;p=stable_plom Browser: In by_1st view, label attribute name of secondary sorters. --- diff --git a/browser.py b/browser.py index 361bdae..af44e7f 100755 --- a/browser.py +++ b/browser.py @@ -483,7 +483,8 @@ class VerticalLabel(Gtk.DrawingArea): def on_draw(self, _, cairo_ctx, __, height): """Create Pango Layout from ._text, rotate and re-size.""" - layout = self.create_pango_layout(self._text) + layout = self.create_pango_layout() + layout.set_markup(self._text) text_width, text_height = layout.get_pixel_size() cairo_ctx.translate(0, text_width + (height - text_width)) cairo_ctx.rotate(radians(-90)) @@ -790,19 +791,16 @@ class Gallery: self._on_hit_item() return f - def build_rows_by_attrs(remaining_attrs, - items_of_parent_attr_value, - parent_attrs_values): - if not items_of_parent_attr_value: + def build_rows_by_attrs(remaining, items_of_parent, ancestors): + if not items_of_parent: return - attr_name, attr_values = remaining_attrs[0] - if 1 == len(remaining_attrs): - v_offset = len(parent_attrs_values) - for i, val in enumerate(parent_attrs_values): - self._grid.attach(VerticalLabel(str(val)), - i, i_row_ref[0], 1, 1) + attr_name, attr_values = remaining[0] + if 1 == len(remaining): + for i, attr in enumerate(ancestors): + vlabel = VerticalLabel(f'{attr[0]}: {attr[1]}') + self._grid.attach(vlabel, i, i_row_ref[0], 1, 1) row = [None] * len(attr_values) - for item in items_of_parent_attr_value: + for item in items_of_parent: val = getattr(item, attr_name) idx_val_in_attr_values = attr_values.index(val) if row[idx_val_in_attr_values]: @@ -816,17 +814,16 @@ class Gallery: slot = GallerySlot(GalleryItem('', '')) # dummy self.slots += [slot] i_slot_ref[0] += 1 - self._grid.attach(slot, i_col + v_offset, + self._grid.attach(slot, i_col + len(ancestors), i_row_ref[0], 1, 1) i_row_ref[0] += 1 return for attr_value in attr_values: - items_of_attr_value = [ - x for x in items_of_parent_attr_value - if attr_value == getattr(x, attr_name)] - build_rows_by_attrs(remaining_attrs[1:], - items_of_attr_value, - parent_attrs_values + [attr_value]) + items_of_attr_value = [x for x in items_of_parent + if attr_value == getattr(x, + attr_name)] + build_rows_by_attrs(remaining[1:], items_of_attr_value, + ancestors + [(attr_name, attr_value)]) if self._grid: self._fixed_frame.remove(self._grid)