From: Christian Heller Date: Tue, 22 Oct 2024 19:09:51 +0000 (+0200) Subject: Browser.py: On "by 1st sorter", add vertical label for secondary sorter. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/process?a=commitdiff_plain;h=5f3cffb1d608df796621ff60ede9c777ce3695bf;p=stable_plom Browser.py: On "by 1st sorter", add vertical label for secondary sorter. --- diff --git a/browser.py b/browser.py index f39e6c4..0b8e9d7 100755 --- a/browser.py +++ b/browser.py @@ -8,7 +8,7 @@ from os.path import (exists as path_exists, join as path_join, abspath, isdir, splitext, getmtime) from datetime import datetime, timezone, timedelta from argparse import ArgumentParser -from math import ceil +from math import ceil, radians from PIL import Image from PIL.PngImagePlugin import PngImageFile import gi # type: ignore @@ -16,8 +16,9 @@ gi.require_version('Gtk', '4.0') gi.require_version('Gdk', '4.0') gi.require_version('Gio', '2.0') # pylint: disable=wrong-import-position -from gi.repository import Gdk, Gtk, Gio, Pango # type: ignore # noqa: E402 -from gi.repository import GObject, GLib # type: ignore # noqa: E402 +from gi.repository import (Gdk, Gio, GLib, # type: ignore # noqa: E402 + GObject, Gtk, Pango, # type: ignore # noqa: E402 + PangoCairo) # type: ignore # noqa: E402 # pylint: disable=no-name-in-module from stable.gen_params import (GenParams, GEN_PARAMS_FLOAT, # noqa: E402 GEN_PARAMS_INT, GEN_PARAMS_STR, # noqa: E402 @@ -469,6 +470,24 @@ class ImgItem(GalleryItem): self.slot.mark('bookmarked', positive) +class VerticalLabel(Gtk.DrawingArea): + """Label of vertical text (rotated -90°).""" + + def __init__(self, text): + super().__init__() + self._text = text + self.set_draw_func(self.on_draw) + + def on_draw(self, _, cairo_ctx, __, height): + """Create Pango Layout from ._text, rotate and re-size.""" + layout = self.create_pango_layout(self._text) + text_width, text_height = layout.get_pixel_size() + cairo_ctx.translate(0, text_width + (height - text_width) / 2) + cairo_ctx.rotate(radians(-90)) + PangoCairo.show_layout(cairo_ctx, layout) + self.set_size_request(text_height, text_width) + + class Gallery: """Representation of GalleryItems below a directory.""" @@ -754,11 +773,14 @@ class Gallery: return f def build_rows_by_attrs(remaining_attrs, - items_of_parent_attr_value): + items_of_parent_attr_value, + parent_attr_value=None): if not items_of_parent_attr_value: return attr_name, attr_values = remaining_attrs[0] if 1 == len(remaining_attrs): + self._grid.attach(VerticalLabel(str(parent_attr_value)), + 0, i_row_ref[0], 1, 1) row = [None] * len(attr_values) for item in items_of_parent_attr_value: val = getattr(item, attr_name) @@ -774,7 +796,7 @@ class Gallery: slot = GallerySlot(GalleryItem('', '')) # dummy self.slots += [slot] i_slot_ref[0] += 1 - self._grid.attach(slot, i_col, i_row_ref[0], 1, 1) + self._grid.attach(slot, i_col+1, i_row_ref[0], 1, 1) i_row_ref[0] += 1 return for attr_value in attr_values: @@ -782,7 +804,8 @@ class Gallery: 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) + items_of_attr_value, + attr_value) if self._grid: self._fixed_frame.remove(self._grid) @@ -1009,7 +1032,8 @@ class MainWindow(Gtk.Window): viewer.append(self.navbar) viewer.append(self.gallery.frame) self.side_box = Gtk.Notebook.new() - self.side_box.append_page(init_metadata_box(), Gtk.Label(label='metadata')) + self.side_box.append_page(init_metadata_box(), + Gtk.Label(label='metadata')) self.side_box.append_page(self.app.conf.box, Gtk.Label(label='config')) box_outer = Gtk.Box(orientation=OR_H) box_outer.append(self.side_box)