playlist: Split out the ControlBox as a base class

And create a PlaylistBox inheriting from it containing the buttons.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-12-28 13:50:51 -05:00
parent 328dce0be2
commit c4adea15bb
2 changed files with 22 additions and 15 deletions

View File

@ -74,20 +74,9 @@ class JumpButton(Gtk.Button):
class ControlBox(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
Gtk.Box.__init__(self, margin_top=5, margin_bottom=5,
margin_end=5, margin_start=5)
self.add_css_class("linked")
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()
@ -96,11 +85,23 @@ class ControlBox(Gtk.Box):
child = child.get_next_sibling()
class PlaylistBox(ControlBox):
def __init__(self):
ControlBox.__init__(self)
self.append(RandomToggle())
self.append(LoopToggle())
self.append(SortButton())
self.append(JumpButton())
def get_jump_button(self):
return self.get_last_child()
class Header(Gtk.Box):
def __init__(self):
Gtk.Box.__init__(self)
self.append(FilterEntry())
self.append(ControlBox())
self.append(PlaylistBox())
def get_jump_button(self):
return self.get_last_child().get_jump_button()

View File

@ -138,9 +138,15 @@ class TestControlBox(unittest.TestCase):
self.assertEqual(box.get_margin_end(), 5)
self.assertTrue(box.has_css_class("linked"))
class TestPlaylistBox(unittest.TestCase):
def test_init(self):
box = header.PlaylistBox()
self.assertIsInstance(box, header.ControlBox)
def test_children(self):
collection = db.user.Table.find("Collection")
box = header.ControlBox()
box = header.PlaylistBox()
box.set_playlist(collection)
child = box.get_first_child()