From f15514edd1e49a5bfabcb5d6f9887442cd96a48f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 22 Nov 2021 11:33:20 -0500 Subject: [PATCH] playlist: Create a JumpButton For jumping to the current track Signed-off-by: Anna Schumaker --- playlist/__init__.py | 7 +++++++ playlist/header.py | 17 +++++++++++++++++ playlist/test_header.py | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/playlist/__init__.py b/playlist/__init__.py index 5912382..17af829 100644 --- a/playlist/__init__.py +++ b/playlist/__init__.py @@ -1,4 +1,5 @@ # Copyright 2021 (c) Anna Schumaker. +import audio from gi.repository import Gtk from . import footer from . import header @@ -18,7 +19,13 @@ class Panel(Gtk.Box): self.append(Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)) self.append(self.footer) + self.header.get_jump_button().connect("clicked", self.jump_clicked) + def get_playlist(self): return self.window.get_playlist() def set_playlist(self, plist): self.header.set_playlist(plist) self.window.set_playlist(plist) + + def jump_clicked(self, button): + view = self.window.get_child() + view.track_changed(audio.Player, None, audio.Player.track) diff --git a/playlist/header.py b/playlist/header.py index 2e60520..b91dac3 100644 --- a/playlist/header.py +++ b/playlist/header.py @@ -62,6 +62,16 @@ class SortButton(Gtk.MenuButton): self.set_sensitive(plist != db.user.Table.find("Previous")) +class JumpButton(Gtk.Button): + def __init__(self): + Gtk.Button.__init__(self) + self.set_icon_name("go-jump") + self.set_sensitive(False) + + def set_playlist(self, plist): + self.set_sensitive(plist is not None) + + class ControlBox(Gtk.Box): def __init__(self): Gtk.Box.__init__(self) @@ -69,12 +79,16 @@ class ControlBox(Gtk.Box): self.append(RandomToggle()) self.append(LoopToggle()) self.append(SortButton()) + self.append(JumpButton()) self.set_margin_top(5) self.set_margin_bottom(5) self.set_margin_start(5) self.set_margin_end(5) + def get_jump_button(self): + return self.get_last_child() + def set_playlist(self, plist): child = self.get_first_child() while child: @@ -88,5 +102,8 @@ class Header(Gtk.Box): self.append(FilterEntry()) self.append(ControlBox()) + def get_jump_button(self): + return self.get_last_child().get_jump_button() + def set_playlist(self, plist): self.get_last_child().set_playlist(plist) diff --git a/playlist/test_header.py b/playlist/test_header.py index c6a5e90..de736ad 100644 --- a/playlist/test_header.py +++ b/playlist/test_header.py @@ -113,6 +113,20 @@ class TestSortButton(unittest.TestCase): self.assertTrue(sort.get_sensitive()) +class TestJumpButton(unittest.TestCase): + def test_init(self): + jump = header.JumpButton() + self.assertIsInstance(jump, Gtk.Button) + self.assertEqual(jump.get_icon_name(), "go-jump") + self.assertFalse(jump.get_sensitive()) + + def test_set_playlist(self): + jump = header.JumpButton() + self.assertFalse(jump.get_sensitive()) + jump.set_playlist(db.user.Table.find("Collection")) + self.assertTrue(jump.get_sensitive()) + + class TestControlBox(unittest.TestCase): def test_init(self): box = header.ControlBox() @@ -140,11 +154,16 @@ class TestControlBox(unittest.TestCase): child = child.get_next_sibling() self.assertIsInstance(child, header.SortButton) + child = child.get_next_sibling() + self.assertIsInstance(child, header.JumpButton) + self.assertEqual(box.get_jump_button(), child) + class TestHeader(unittest.TestCase): def test_init(self): box = header.Header() self.assertIsInstance(box, Gtk.Box) + self.assertIsInstance(box.get_jump_button(), header.JumpButton) self.assertEqual(box.get_orientation(), Gtk.Orientation.HORIZONTAL) def test_children(self):