playlist: Create a JumpButton

For jumping to the current track

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-11-22 11:33:20 -05:00
parent cee0f4e075
commit f15514edd1
3 changed files with 43 additions and 0 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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):