nowplaying: Add an Artwork widget to the Now Playing card

Implements: #45 (Create a new NowPlaying widget)
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-07-22 10:44:16 -04:00
parent b3d04805d7
commit f85cdb5b49
4 changed files with 21 additions and 4 deletions

View File

@ -82,8 +82,8 @@ class Application(Adw.Application):
playing = nowplaying.Card()
playing.bind_property("autopause", self, "autopause",
GObject.BindingFlags.BIDIRECTIONAL)
for prop in ["title", "album", "artist", "album-artist",
"playing", "position", "duration", "have-track"]:
for prop in ["title", "album", "artist", "album-artist", "playing",
"position", "duration", "artwork", "have-track"]:
self.player.bind_property(prop, playing, prop)
self.db.settings.bind_setting("now-playing.prefer-artist",
playing, "prefer-artist")

View File

@ -2,6 +2,7 @@
"""A card for displaying information about the currently playing track."""
from gi.repository import GObject
from gi.repository import Gtk
from . import artwork
from . import controls
from . import seeker
from . import tags
@ -10,6 +11,7 @@ from . import tags
class Card(Gtk.Box):
"""The Now Playing information card."""
artwork = GObject.Property(type=GObject.TYPE_PYOBJECT)
title = GObject.Property(type=str)
album = GObject.Property(type=str)
artist = GObject.Property(type=str)
@ -28,11 +30,13 @@ class Card(Gtk.Box):
"""Initialize a Now Playing Card."""
super().__init__()
self._grid = Gtk.Grid()
self._artwork = artwork.Artwork()
self._tags = tags.TagInfo()
self._controls = controls.Controls()
self._bottom_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
self._seeker = seeker.Scale(sensitive=False)
self.bind_property("artwork", self._artwork, "filepath")
for prop in ["title", "album", "artist", "album-artist"]:
self.bind_property(prop, self._tags, prop)
self.bind_property("prefer-artist", self._tags, "prefer-artist",
@ -54,6 +58,7 @@ class Card(Gtk.Box):
self._grid.attach(self._controls, 1, 0, 1, 1)
self._grid.attach(self._bottom_box, 0, 1, 2, 1)
self.append(self._artwork)
self.append(self._grid)
self.add_css_class("card")

View File

@ -3,6 +3,7 @@
import unittest
import unittest.mock
import emmental
import tests.util
from gi.repository import Gtk
@ -23,7 +24,8 @@ class TestNowPlaying(unittest.TestCase):
Gtk.Orientation.HORIZONTAL)
self.assertEqual(self.card._bottom_box.get_spacing(), 0)
self.assertEqual(self.card.get_last_child(), self.card._grid)
self.assertEqual(self.card._artwork.get_next_sibling(),
self.card._grid)
self.assertEqual(self.card._grid.get_child_at(0, 1),
self.card._bottom_box)
self.assertEqual(self.card._grid.get_child_at(1, 1),
@ -31,6 +33,15 @@ class TestNowPlaying(unittest.TestCase):
self.assertTrue(self.card.has_css_class("card"))
def test_artwork(self):
"""Test that an Artwork instance has been added."""
self.assertIsInstance(self.card._artwork,
emmental.nowplaying.artwork.Artwork)
self.assertEqual(self.card.get_first_child(), self.card._artwork)
self.card.artwork = tests.util.COVER_JPG
self.assertEqual(self.card._artwork.filepath, tests.util.COVER_JPG)
def test_prefer_artist(self):
"""Test the 'prefer-artist' property."""
self.assertTrue(self.card.prefer_artist)

View File

@ -115,7 +115,8 @@ class TestEmmental(unittest.TestCase):
win = self.application.build_window()
for (property, value) in [("have-track", True), ("playing", True),
("duration", 10), ("position", 5)]:
("duration", 10), ("position", 5),
("artwork", "/a/b/c.jpg")]:
with self.subTest(property=property, value=value):
self.application.player.set_property(property, value)
self.assertEqual(win.now_playing.get_property(property), value)