sidebar: Create ParentTagBoxes

For use displaying Tags and SuperTags

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-07-02 10:40:37 -04:00
parent ab515326c9
commit 43033b4e21
4 changed files with 29 additions and 4 deletions

View File

@ -44,9 +44,11 @@ def add_stack_page(name, page):
toggle.set_active(settings.get("sidebar.page") == name)
add_stack_page("Playlists", user.TagBox)
add_stack_page("Artists", tagbox.TagBox(trackdb.tags.Artist, "avatar-default-symbolic", header=True))
add_stack_page("Artists", tagbox.ParentTagBox(trackdb.tags.Artist, "avatar-default-symbolic",
trackdb.tags.Album, "media-optical", header=True))
add_stack_page("Genres", tagbox.TagBox(trackdb.tags.Genre, "emblem-generic", header=True))
add_stack_page("Decades", tagbox.TagBox(trackdb.tags.Decade, "x-office-calendar"))
add_stack_page("Decades", tagbox.ParentTagBox(trackdb.tags.Decade, "x-office-calendar",
trackdb.tags.Year, "x-office-calendar-symbolic"))
add_stack_page("Libraries", library.Box)

View File

@ -72,3 +72,10 @@ class TagBox(Gtk.ScrolledWindow):
def tag_removed(self, tag):
self.bus.board(self.on_tag_removed, tag)
class ParentTagBox(TagBox):
def __init__(self, tagstore, icon, childstore, childicon, header=False):
TagBox.__init__(self, tagstore, icon, header)
self.childstore = childstore
self.childicon = childicon

View File

@ -108,3 +108,19 @@ class TestTagBox(unittest.TestCase):
self.assertEqual(tbox[0].tag, tagA)
self.assertEqual(tbox[1].tag, tagB)
self.assertEqual(tbox[2].tag, tagC)
class TestParentTagBox(unittest.TestCase):
def test_parent_tagbox(self):
store = lib.tagstore.TagStore()
superstore = lib.tagstore.TagSuperStore()
ptbox = tagbox.ParentTagBox(store, "missing-icon",
superstore, "missing-icon")
self.assertIsInstance(ptbox, tagbox.ParentTagBox)
self.assertIsInstance(ptbox, tagbox.TagBox)
self.assertEqual(ptbox.tagstore, store)
self.assertEqual(ptbox.icon, "missing-icon")
self.assertEqual(ptbox.childstore, superstore)
self.assertEqual(ptbox.childicon, "missing-icon")

View File

@ -38,7 +38,7 @@ class TestSidebar(unittest.TestCase):
self.assertEqual(settings.get("sidebar.page"), "Playlists")
self.assertIsInstance(sidebar.Stack.get_child_by_name("Artists"),
sidebar.tagbox.TagBox)
sidebar.tagbox.ParentTagBox)
self.assertEqual(sidebar.Toggles[1].get_icon_name(), "avatar-default-symbolic")
self.assertEqual(sidebar.Toggles[1].get_name(), "Artists")
sidebar.Toggles[1].set_active(True)
@ -54,7 +54,7 @@ class TestSidebar(unittest.TestCase):
self.assertEqual(settings.get("sidebar.page"), "Genres")
self.assertIsInstance(sidebar.Stack.get_child_by_name("Decades"),
sidebar.tagbox.TagBox)
sidebar.tagbox.ParentTagBox)
self.assertEqual(sidebar.Toggles[3].get_icon_name(), "x-office-calendar")
self.assertEqual(sidebar.Toggles[3].get_name(), "Decades")
sidebar.Toggles[3].set_active(True)