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
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
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."""
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)
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:
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)
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)