playlist: Add a ControlBox box

Containing the RandomToggle, LoopToggle, and SortButton

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-11-03 11:40:12 -04:00
parent c5aff410b4
commit b09baf3d99
2 changed files with 48 additions and 0 deletions

View File

@ -60,3 +60,23 @@ class SortButton(Gtk.MenuButton):
def set_playlist(self, plist):
self.get_popover().set_playlist(plist)
self.set_sensitive(plist != db.user.Table.find("Previous"))
class ControlBox(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
self.add_css_class("linked")
self.append(RandomToggle())
self.append(LoopToggle())
self.append(SortButton())
self.set_margin_top(5)
self.set_margin_bottom(5)
self.set_margin_start(5)
self.set_margin_end(5)
def set_playlist(self, plist):
child = self.get_first_child()
while child:
child.set_playlist(plist)
child = child.get_next_sibling()

View File

@ -111,3 +111,31 @@ class TestSortButton(unittest.TestCase):
self.assertFalse(sort.get_sensitive())
sort.set_playlist(db.user.Table.find("Queued Tracks"))
self.assertTrue(sort.get_sensitive())
class TestControlBox(unittest.TestCase):
def test_init(self):
box = header.ControlBox()
self.assertIsInstance(box, Gtk.Box)
self.assertEqual(box.get_orientation(), Gtk.Orientation.HORIZONTAL)
self.assertEqual(box.get_margin_top(), 5)
self.assertEqual(box.get_margin_bottom(), 5)
self.assertEqual(box.get_margin_start(), 5)
self.assertEqual(box.get_margin_end(), 5)
self.assertTrue(box.has_css_class("linked"))
def test_children(self):
collection = db.user.Table.find("Collection")
box = header.ControlBox()
box.set_playlist(collection)
child = box.get_first_child()
self.assertIsInstance(child, header.RandomToggle)
self.assertEqual(child.playlist, collection)
child = child.get_next_sibling()
self.assertIsInstance(child, header.LoopToggle)
self.assertEqual(child.playlist, collection)
child = child.get_next_sibling()
self.assertIsInstance(child, header.SortButton)