# Copyright 2022 (c) Anna Schumaker. """A card for displaying information about the currently playing track.""" from gi.repository import GObject from gi.repository import Gtk from . import controls from . import tags class Card(Gtk.Box): """The Now Playing information card.""" 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) playing = GObject.Property(type=bool, default=False) autopause = GObject.Property(type=int, default=-1, minimum=-1, maximum=99) have_next = GObject.Property(type=bool, default=False) have_previous = GObject.Property(type=bool, default=False) have_track = GObject.Property(type=bool, default=False) def __init__(self): """Initialize a Now Playing Card.""" super().__init__() self._grid = Gtk.Grid() self._tags = tags.TagInfo() self._controls = controls.Controls() for prop in ["title", "album", "artist", "album-artist"]: self.bind_property(prop, self._tags, prop) self.bind_property("prefer-artist", self._tags, "prefer-artist", GObject.BindingFlags.BIDIRECTIONAL) for prop in ["playing", "have-next", "have-previous", "have-track"]: self.bind_property(prop, self._controls, prop) self.bind_property("autopause", self._controls, "autopause", GObject.BindingFlags.BIDIRECTIONAL) for sig in ["play", "pause", "previous", "next"]: self._controls.connect(sig, self.__on_control, sig) self._grid.attach(self._tags, 0, 0, 1, 1) self._grid.attach(self._controls, 1, 0, 1, 1) self.append(self._grid) self.add_css_class("card") def __on_control(self, controls: controls.Controls, signal: str) -> None: self.emit(signal) @GObject.Signal def play(self) -> None: """Signal that the Play button has been clicked.""" @GObject.Signal def pause(self) -> None: """Signal that the Pause button has been clicked.""" @GObject.Signal def previous(self) -> None: """Signal that the Previous button has been clicked.""" @GObject.Signal def next(self) -> None: """Signal that the Nause button has been clicked."""