diff --git a/emmental/__init__.py b/emmental/__init__.py index 8204860..ca1e73c 100644 --- a/emmental/__init__.py +++ b/emmental/__init__.py @@ -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") diff --git a/emmental/nowplaying/__init__.py b/emmental/nowplaying/__init__.py index 910baaa..a34c7ee 100644 --- a/emmental/nowplaying/__init__.py +++ b/emmental/nowplaying/__init__.py @@ -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") diff --git a/tests/nowplaying/test_nowplaying.py b/tests/nowplaying/test_nowplaying.py index 89ed0f4..8d88324 100644 --- a/tests/nowplaying/test_nowplaying.py +++ b/tests/nowplaying/test_nowplaying.py @@ -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) diff --git a/tests/test_emmental.py b/tests/test_emmental.py index c05c154..4fd0c28 100644 --- a/tests/test_emmental.py +++ b/tests/test_emmental.py @@ -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)