nowplaying: Add the PreferArtistMenu to the ArtistLabel
This menu is used to select between showing the artist or album artist tag. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
997b1de012
commit
c434f6672e
|
@ -1,6 +1,7 @@
|
|||
# Copyright 2022 (c) Anna Schumaker.
|
||||
"""A Gtk.Label set up for displaying nowplaying tags."""
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Pango
|
||||
|
||||
|
@ -70,9 +71,37 @@ class ArtistLabel(Label):
|
|||
def __init__(self, **kwargs):
|
||||
"""Initialize the Artist Label."""
|
||||
super().__init__(**kwargs)
|
||||
self._menu = PreferArtistMenu()
|
||||
self._popover = Gtk.Popover(child=self._menu)
|
||||
self._clicked = Gtk.GestureClick()
|
||||
|
||||
self.bind_property("prefer-artist", self._menu, "prefer-artist",
|
||||
GObject.BindingFlags.BIDIRECTIONAL)
|
||||
|
||||
self.add_controller(self._clicked)
|
||||
self._clicked.connect("released", self.__clicked)
|
||||
|
||||
self.connect("notify::artist", self.__notify)
|
||||
self.connect("notify::album-artist", self.__notify)
|
||||
self.connect("notify::prefer-artist", self.__notify)
|
||||
self.connect("notify::size", self.__notify_size)
|
||||
|
||||
rect = Gdk.Rectangle()
|
||||
rect.x, rect.y = (8, 8)
|
||||
self._popover.set_pointing_to(rect)
|
||||
self._popover.set_parent(self)
|
||||
|
||||
def __del__(self) -> None:
|
||||
"""Clean up the Artist Label."""
|
||||
self._popover.unparent()
|
||||
|
||||
def __clicked(self, gesture, n_press, x, y) -> None:
|
||||
self._popover.popup()
|
||||
|
||||
def __notify_size(self, label, param) -> None:
|
||||
rect = Gdk.Rectangle()
|
||||
(rect.x, rect.y) = (self.size, self.size)
|
||||
self._popover.set_pointing_to(rect)
|
||||
|
||||
def __notify(self, label, param) -> None:
|
||||
if self.prefer_artist:
|
||||
|
|
|
@ -115,11 +115,39 @@ class TestArtistLabel(unittest.TestCase):
|
|||
def test_init(self):
|
||||
"""Test that the artist label is set up properly."""
|
||||
self.assertIsInstance(self.label, emmental.nowplaying.label.Label)
|
||||
self.assertIsInstance(self.label._menu,
|
||||
emmental.nowplaying.label.PreferArtistMenu)
|
||||
self.assertIsInstance(self.label._clicked, Gtk.GestureClick)
|
||||
|
||||
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_popover_menu(self):
|
||||
"""Test that the popover menu is wired up properly."""
|
||||
self.assertIsInstance(self.label._popover, Gtk.Popover)
|
||||
self.assertEqual(self.label._popover.get_parent(), self.label)
|
||||
self.assertEqual(self.label._popover.get_child(), self.label._menu)
|
||||
|
||||
self.label.prefer_artist = False
|
||||
self.assertFalse(self.label._menu.prefer_artist)
|
||||
self.label._menu.prefer_artist = True
|
||||
self.assertTrue(self.label.prefer_artist)
|
||||
|
||||
def test_popover_pointing_to(self):
|
||||
"""Test that the popover is pointing to the right spot."""
|
||||
(res, rect) = self.label._popover.get_pointing_to()
|
||||
self.assertTrue(res)
|
||||
self.assertEqual((rect.x, rect.y), (8, 8))
|
||||
self.assertEqual((rect.width, rect.height), (1, 1))
|
||||
|
||||
self.label.size = 48
|
||||
(res, rect) = self.label._popover.get_pointing_to()
|
||||
self.assertTrue(res)
|
||||
self.assertEqual((rect.x, rect.y), (48, 48))
|
||||
self.assertEqual((rect.width, rect.height), (1, 1))
|
||||
|
||||
def test_prefer_artist(self):
|
||||
"""Test situations where we want to use the artist property."""
|
||||
self.label.prefer_artist = True
|
||||
|
|
Loading…
Reference in New Issue