# Copyright 2022 (c) Anna Schumaker. """Widgets for information about the current track.""" from gi.repository import GObject from gi.repository import GLib from gi.repository import Gtk from . import label class TagInfo(Gtk.ScrolledWindow): """A widget for displaying information about the current track.""" title = GObject.Property(type=str) album = GObject.Property(type=str) artist = GObject.Property(type=str) album_artist = GObject.Property(type=str) prefer_artist = GObject.Property(type=bool, default=True) def __init__(self): """Initialize the TagInfo widget.""" super().__init__(hexpand=True, vexpand=True) self._box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0) self._title = label.Label() self._album = label.Label(prefix="from ") self._artist = label.ArtistLabel(prefix="by ") self._saved_height = 0 self._idle_id = None self.bind_property("title", self._title, "text") self.bind_property("album", self._album, "text") self.bind_property("artist", self._artist, "artist") self.bind_property("album-artist", self._artist, "album-artist") self.bind_property("prefer-artist", self._artist, "prefer-artist", GObject.BindingFlags.BIDIRECTIONAL) self._box.append(self._title) self._box.append(self._album) self._box.append(self._artist) self.set_child(self._box) def __set_label_size(self): self._title.size = self._saved_height / 2.5 for tag in [self._album, self._artist]: tag.size = self._saved_height / 5 self._idle_id = None return GLib.SOURCE_REMOVE def do_size_allocate(self, width, height, baseline) -> None: """Monitor for size changes.""" Gtk.ScrolledWindow.do_size_allocate(self, width, height, baseline) if height != self._saved_height: self._saved_height = height if not self._idle_id: self._idle_id = GLib.idle_add(self.__set_label_size)