nowplaying: Create an ArtistLabel
This label has properties for both Artist and Album Artist, and chooses which to display based on the prefer-artist property and which tags have been set. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
c899c15c42
commit
81fdfe66cb
|
@ -34,3 +34,30 @@ class Label(Gtk.Label):
|
|||
attrlist = Pango.AttrList.new()
|
||||
attrlist.insert(Pango.attr_size_new_absolute(self.size * Pango.SCALE))
|
||||
self.set_attributes(attrlist)
|
||||
|
||||
|
||||
class ArtistLabel(Label):
|
||||
"""A label that shows either Artist or Album Artist information."""
|
||||
|
||||
artist = GObject.Property(type=str)
|
||||
album_artist = GObject.Property(type=str)
|
||||
prefer_artist = GObject.Property(type=bool, default=True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Initialize the Artist Label."""
|
||||
super().__init__(**kwargs)
|
||||
self.connect("notify::artist", self.__notify)
|
||||
self.connect("notify::album-artist", self.__notify)
|
||||
self.connect("notify::prefer-artist", self.__notify)
|
||||
|
||||
def __notify(self, label, param) -> None:
|
||||
if self.prefer_artist:
|
||||
if len(self.artist) > 0:
|
||||
self.text = self.artist
|
||||
else:
|
||||
self.text = self.album_artist
|
||||
else:
|
||||
if len(self.album_artist) > 0:
|
||||
self.text = self.album_artist
|
||||
else:
|
||||
self.text = self.artist
|
||||
|
|
|
@ -60,3 +60,55 @@ class TestLabel(unittest.TestCase):
|
|||
self.label.size = size
|
||||
self.assertEqual(self.label.get_attributes().to_string(),
|
||||
f"{expected} {size * Pango.SCALE}")
|
||||
|
||||
|
||||
class TestArtistLabel(unittest.TestCase):
|
||||
"""Test case for our Artist label."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up common variables."""
|
||||
self.label = emmental.nowplaying.label.ArtistLabel(prefix="by ")
|
||||
|
||||
def test_init(self):
|
||||
"""Test that the artist label is set up properly."""
|
||||
self.assertIsInstance(self.label, emmental.nowplaying.label.Label)
|
||||
self.assertEqual(self.label.prefix, "by ")
|
||||
self.assertEqual(self.label.artist, "")
|
||||
self.assertEqual(self.label.album_artist, "")
|
||||
self.assertTrue(self.label.prefer_artist)
|
||||
|
||||
def test_prefer_artist(self):
|
||||
"""Test situations where we want to use the artist property."""
|
||||
self.label.prefer_artist = True
|
||||
|
||||
self.label.artist = "Test Artist"
|
||||
self.assertEqual(self.label.get_text(), "by Test Artist")
|
||||
|
||||
self.label.album_artist = "Test Album Artist"
|
||||
self.assertEqual(self.label.get_text(), "by Test Artist")
|
||||
|
||||
self.label.prefer_artist = False
|
||||
self.assertEqual(self.label.get_text(), "by Test Album Artist")
|
||||
self.label.prefer_artist = True
|
||||
self.assertEqual(self.label.get_text(), "by Test Artist")
|
||||
|
||||
self.label.artist = ""
|
||||
self.assertEqual(self.label.get_text(), "by Test Album Artist")
|
||||
|
||||
def test_prefer_album_artist(self):
|
||||
"""Test situations where we want to use the album artist property."""
|
||||
self.label.prefer_artist = False
|
||||
|
||||
self.label.album_artist = "Test Album Artist"
|
||||
self.assertEqual(self.label.get_text(), "by Test Album Artist")
|
||||
|
||||
self.label.artist = "Test Artist"
|
||||
self.assertEqual(self.label.get_text(), "by Test Album Artist")
|
||||
|
||||
self.label.prefer_artist = True
|
||||
self.assertEqual(self.label.get_text(), "by Test Artist")
|
||||
self.label.prefer_artist = False
|
||||
self.assertEqual(self.label.get_text(), "by Test Album Artist")
|
||||
|
||||
self.label.album_artist = ""
|
||||
self.assertEqual(self.label.get_text(), "by Test Artist")
|
||||
|
|
Loading…
Reference in New Issue