nowplaying: Add a Jump button

This button will be used to scroll the displayed playlist to the
currently playing track.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-09-01 10:38:25 -04:00
parent 00f6ee9238
commit 6cade5d779
2 changed files with 34 additions and 1 deletions

View File

@ -42,6 +42,9 @@ class Card(Gtk.Box):
icon_size=Gtk.IconSize.LARGE,
has_frame=False, sensitive=False,
valign=Gtk.Align.CENTER)
self._jump = buttons.Button(icon_name="go-jump", has_frame=False,
icon_size=Gtk.IconSize.LARGE,
valign=Gtk.Align.CENTER, sensitive=False)
self._seeker = seeker.Scale(sensitive=False)
self.bind_property("artwork", self._artwork, "filepath")
@ -51,6 +54,7 @@ class Card(Gtk.Box):
GObject.BindingFlags.BIDIRECTIONAL)
for prop in ["playing", "have-next", "have-previous", "have-track"]:
self.bind_property(prop, self._controls, prop)
self.bind_property("have-db-track", self._jump, "sensitive")
self.bind_property("have-db-track", self._favorite, "sensitive")
self.bind_property("have-track", self._seeker, "sensitive")
self.bind_property("autopause", self._controls, "autopause",
@ -62,9 +66,11 @@ class Card(Gtk.Box):
for sig in ["play", "pause", "previous", "next"]:
self._controls.connect(sig, self.__on_control, sig)
self._jump.connect("clicked", self.__on_jump)
self._seeker.connect("change-value", self.__on_seek)
self._bottom_box.append(self._favorite)
self._bottom_box.append(self._jump)
self._bottom_box.append(self._seeker)
self._grid.attach(self._tags, 0, 0, 1, 1)
self._grid.attach(self._controls, 1, 0, 1, 1)
@ -77,10 +83,17 @@ class Card(Gtk.Box):
def __on_control(self, controls: controls.Controls, signal: str) -> None:
self.emit(signal)
def __on_jump(self, jump: Gtk.Button) -> None:
self.emit("jump")
def __on_seek(self, seek: seeker.Scale, scroll: Gtk.ScrollType,
value: float) -> None:
self.emit("seek", value)
@GObject.Signal
def jump(self) -> None:
"""Signal that the Tracklist should be scrolled."""
@GObject.Signal
def play(self) -> None:
"""Signal that the Play button has been clicked."""

View File

@ -105,11 +105,31 @@ class TestNowPlaying(unittest.TestCase):
self.card._favorite.active = False
self.assertFalse(self.card.favorite)
def test_jump_button(self):
"""Test the jump button."""
self.assertIsInstance(self.card._jump, emmental.buttons.Button)
self.assertEqual(self.card._favorite.get_next_sibling(),
self.card._jump)
self.assertEqual(self.card._jump.icon_name, "go-jump")
self.assertEqual(self.card._jump.icon_size, Gtk.IconSize.LARGE)
self.assertEqual(self.card._jump.get_valign(), Gtk.Align.CENTER)
self.assertFalse(self.card._jump.get_has_frame())
self.assertFalse(self.card._jump.get_sensitive())
self.card.have_db_track = True
self.assertTrue(self.card._jump.get_sensitive())
jumped = unittest.mock.Mock()
self.card.connect("jump", jumped)
self.card._jump.emit("clicked")
jumped.assert_called_with(self.card)
def test_seeker(self):
"""Test the seeker widget."""
self.assertIsInstance(self.card._seeker,
emmental.nowplaying.seeker.Scale)
self.assertEqual(self.card._favorite.get_next_sibling(),
self.assertEqual(self.card._jump.get_next_sibling(),
self.card._seeker)
self.assertFalse(self.card._seeker.get_sensitive())