sidebar: Create a TreeRow and {User,Library,}TreeRowFactorys

This is a Gtk.TreeExpander with some extra functions to work the way we
need it. We don't have a way to create Gtk.TreeListRows manually, so we
can't test the set_item() and unset_item() functions directly.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>

sidebar: Create a LibraryTreeRowFactory

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-10-12 12:00:18 -04:00
parent 3bd60b0f06
commit e1cab1de6f
2 changed files with 69 additions and 0 deletions

View File

@ -83,3 +83,51 @@ class LibraryGrid(Grid):
def unset_item(self, item):
super().unset_item(item)
self.menu.set_popover(None)
class TreeRow(Gtk.TreeExpander):
def __init__(self, child):
Gtk.TreeExpander.__init__(self)
self.set_child(child)
def set_item(self, listitem):
self.set_list_row(listitem)
self.get_child().set_item(listitem.get_item())
def unset_item(self, listitem):
self.get_child().unset_item(listitem.get_item())
self.set_list_row(None)
class TreeRowFactory(Gtk.SignalListItemFactory):
def __init__(self):
Gtk.SignalListItemFactory.__init__(self)
self.connect("setup", self.setup)
self.connect("bind", self.bind)
self.connect("unbind", self.unbind)
self.connect("teardown", self.teardown)
def setup(self, factory, treeitem):
treeitem.set_child(TreeRow(Grid()))
def bind(self, factory, treeitem):
treeitem.get_child().set_item(treeitem.get_item())
def unbind(self, factory, treeitem):
treeitem.get_child().unset_item(treeitem.get_item())
def teardown(self, factory, treeitem):
treeitem.set_child(None)
Factory = TreeRowFactory()
class UserTreeRowFactory(TreeRowFactory):
def setup(self, factory, treeitem):
treeitem.set_child(TreeRow(UserGrid()))
UserFactory = UserTreeRowFactory()
class LibraryTreeRowFactory(TreeRowFactory):
def setup(self, factory, treeitem):
treeitem.set_child(TreeRow(LibraryGrid()))
LibraryFactory = LibraryTreeRowFactory()

View File

@ -117,3 +117,24 @@ class TestLibraryGrid(unittest.TestCase):
self.assertIsInstance(grid.menu.get_popover(), widgets.LibraryPopover)
grid.unset_item(db.library.Table.find("/a/b/c"))
self.assertIsNone(grid.menu.get_popover())
class TestTreeRow(unittest.TestCase):
def test_init(self):
tree = row.TreeRow(row.Grid())
self.assertIsInstance(tree, Gtk.TreeExpander)
self.assertIsInstance(tree.get_child(), row.Grid)
def test_factory(self):
factory = row.TreeRowFactory()
self.assertIsInstance(factory, Gtk.SignalListItemFactory)
def test_user_factory(self):
factory = row.UserTreeRowFactory()
self.assertIsInstance(factory, Gtk.SignalListItemFactory)
self.assertIsInstance(row.Factory, row.TreeRowFactory)
def test_library_factory(self):
factory = row.LibraryTreeRowFactory()
self.assertIsInstance(factory, Gtk.SignalListItemFactory)
self.assertIsInstance(row.Factory, row.TreeRowFactory)