emmental/emmental/sidebar/title.py

34 lines
1.3 KiB
Python

# Copyright 2022 (c) Anna Schumaker.
"""Helper widgets for sidebar rows titles."""
from gi.repository import GObject
from gi.repository import Pango
from gi.repository import Gtk
class Title(Gtk.Box):
"""Row Title and Subtitle."""
title = GObject.Property(type=str)
subtitle = GObject.Property(type=str)
def __init__(self, title: str = "", subtitle: str = "", **kwargs):
"""Initialize a row Title widget."""
super().__init__(orientation=Gtk.Orientation.VERTICAL,
title=title, subtitle=subtitle, tooltip_text=title,
hexpand=True, valign=Gtk.Align.CENTER,
margin_top=6, margin_bottom=6, **kwargs)
self._title = Gtk.Label(label=self.title, xalign=0,
ellipsize=Pango.EllipsizeMode.END)
self._subtitle = Gtk.Label(label=self.subtitle, xalign=0,
ellipsize=Pango.EllipsizeMode.END)
self._title.add_css_class("header")
self._subtitle.add_css_class("caption")
self.bind_property("title", self, "tooltip-text")
self.bind_property("title", self._title, "label")
self.bind_property("subtitle", self._subtitle, "label")
self.append(self._title)
self.append(self._subtitle)