audio: Add a custom TrackArtist label

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-08-30 17:18:46 -04:00
parent 4ab66ef7ab
commit ae7c2010e9
2 changed files with 26 additions and 0 deletions

View File

@ -14,6 +14,18 @@ class TrackTitle(Gtk.Label):
self.set_markup(f"<big>{GLib.markup_escape_text(text)}</big>")
class TrackArtist(Gtk.Label):
def __init__(self, player):
Gtk.Label.__init__(self)
player.connect("track-changed", self.on_track_changed)
self.on_track_changed(player, None, player.track)
self.add_css_class("subtitle")
def on_track_changed(self, player, old, new):
text = f"by {new.artist}" if new else "The Cheesy Music Player"
self.set_markup(f"<big>{GLib.markup_escape_text(text)}</big>")
class NowPlaying(Gtk.ScrolledWindow):
def __init__(self):
Gtk.ScrolledWindow.__init__(self)

View File

@ -8,6 +8,7 @@ class FakeTrack(GObject.GObject):
def __init__(self):
GObject.GObject.__init__(self)
self.title = "Test Title"
self.artist = "Test Artist"
class FakePlayer(GObject.GObject):
def __init__(self):
@ -31,6 +32,19 @@ class TestAudioTrackTitle(unittest.TestCase):
self.assertEqual(title.get_text(), "Test Title")
class TestAudioTrackArtist(unittest.TestCase):
def test_track_artist(self):
fake = FakePlayer()
artist = nowplaying.TrackArtist(fake)
self.assertIsInstance(artist, Gtk.Label)
self.assertTrue(artist.has_css_class("subtitle"))
self.assertEqual(artist.get_text(), "The Cheesy Music Player")
fake.emit("track-changed", None, FakeTrack())
self.assertEqual(artist.get_text(), "by Test Artist")
class TestNowPlaying(unittest.TestCase):
def test_now_playing_init(self):
now = nowplaying.NowPlaying()