From c4adea15bbf1e0e85ab9a2383866b82fd5091922 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 28 Dec 2021 13:50:51 -0500 Subject: [PATCH] playlist: Split out the ControlBox as a base class And create a PlaylistBox inheriting from it containing the buttons. Signed-off-by: Anna Schumaker --- playlist/header.py | 29 +++++++++++++++-------------- playlist/test_header.py | 8 +++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/playlist/header.py b/playlist/header.py index b91dac3..b0cda70 100644 --- a/playlist/header.py +++ b/playlist/header.py @@ -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() diff --git a/playlist/test_header.py b/playlist/test_header.py index de736ad..53da155 100644 --- a/playlist/test_header.py +++ b/playlist/test_header.py @@ -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()