2022-05-31 10:18:53 -04:00
|
|
|
# Copyright 2022 (c) Anna Schumaker.
|
|
|
|
"""A card for displaying information about the currently playing track."""
|
2022-06-24 17:30:57 -04:00
|
|
|
from gi.repository import GObject
|
2022-05-31 10:18:53 -04:00
|
|
|
from gi.repository import Gtk
|
2022-07-01 10:30:02 -04:00
|
|
|
from . import controls
|
2022-07-15 09:59:04 -04:00
|
|
|
from . import seeker
|
2022-06-24 17:30:57 -04:00
|
|
|
from . import tags
|
2022-05-31 10:18:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Card(Gtk.Box):
|
|
|
|
"""The Now Playing information card."""
|
|
|
|
|
2022-06-24 17:30:57 -04:00
|
|
|
title = GObject.Property(type=str)
|
|
|
|
album = GObject.Property(type=str)
|
|
|
|
artist = GObject.Property(type=str)
|
|
|
|
album_artist = GObject.Property(type=str)
|
2022-07-15 09:59:04 -04:00
|
|
|
duration = GObject.Property(type=float, default=1)
|
|
|
|
position = GObject.Property(type=float, default=0)
|
2022-06-24 17:30:57 -04:00
|
|
|
prefer_artist = GObject.Property(type=bool, default=True)
|
2022-07-01 10:30:02 -04:00
|
|
|
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)
|
2022-06-24 17:30:57 -04:00
|
|
|
|
2022-05-31 10:18:53 -04:00
|
|
|
def __init__(self):
|
|
|
|
"""Initialize a Now Playing Card."""
|
|
|
|
super().__init__()
|
|
|
|
self._grid = Gtk.Grid()
|
2022-06-24 17:30:57 -04:00
|
|
|
self._tags = tags.TagInfo()
|
2022-07-01 10:30:02 -04:00
|
|
|
self._controls = controls.Controls()
|
2022-07-15 09:59:04 -04:00
|
|
|
self._bottom_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
|
|
|
self._seeker = seeker.Scale(sensitive=False)
|
2022-06-24 17:30:57 -04:00
|
|
|
|
|
|
|
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)
|
2022-07-01 10:30:02 -04:00
|
|
|
for prop in ["playing", "have-next", "have-previous", "have-track"]:
|
|
|
|
self.bind_property(prop, self._controls, prop)
|
2022-07-15 09:59:04 -04:00
|
|
|
self.bind_property("have-track", self._seeker, "sensitive")
|
2022-07-01 10:30:02 -04:00
|
|
|
self.bind_property("autopause", self._controls, "autopause",
|
|
|
|
GObject.BindingFlags.BIDIRECTIONAL)
|
2022-07-15 09:59:04 -04:00
|
|
|
self.bind_property("duration", self._seeker, "duration")
|
|
|
|
self.bind_property("position", self._seeker, "position")
|
2022-07-01 10:30:02 -04:00
|
|
|
|
|
|
|
for sig in ["play", "pause", "previous", "next"]:
|
|
|
|
self._controls.connect(sig, self.__on_control, sig)
|
2022-07-15 09:59:04 -04:00
|
|
|
self._seeker.connect("change-value", self.__on_seek)
|
2022-06-24 17:30:57 -04:00
|
|
|
|
2022-07-15 09:59:04 -04:00
|
|
|
self._bottom_box.append(self._seeker)
|
2022-06-24 17:30:57 -04:00
|
|
|
self._grid.attach(self._tags, 0, 0, 1, 1)
|
2022-07-01 10:30:02 -04:00
|
|
|
self._grid.attach(self._controls, 1, 0, 1, 1)
|
2022-07-15 09:59:04 -04:00
|
|
|
self._grid.attach(self._bottom_box, 0, 1, 2, 1)
|
2022-05-31 10:18:53 -04:00
|
|
|
|
|
|
|
self.append(self._grid)
|
|
|
|
self.add_css_class("card")
|
2022-07-01 10:30:02 -04:00
|
|
|
|
|
|
|
def __on_control(self, controls: controls.Controls, signal: str) -> None:
|
|
|
|
self.emit(signal)
|
|
|
|
|
2022-07-15 09:59:04 -04:00
|
|
|
def __on_seek(self, seek: seeker.Scale, scroll: Gtk.ScrollType,
|
|
|
|
value: float) -> None:
|
|
|
|
self.emit("seek", value)
|
|
|
|
|
2022-07-01 10:30:02 -04:00
|
|
|
@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."""
|
2022-07-15 09:59:04 -04:00
|
|
|
|
|
|
|
@GObject.Signal(arg_types=(float,))
|
|
|
|
def seek(self, newpos: float) -> None:
|
|
|
|
"""Signal that the user wants us to seek."""
|