curds: Add a way to find a node's path
A path is a list of indices in the tree, which can easily be translated into a GtkTreePath Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
7aa2244f97
commit
79ab9d3a40
|
@ -29,6 +29,11 @@ class PlaylistNode:
|
|||
self.__link_children__(prev, child)
|
||||
return self.children.index(child)
|
||||
|
||||
def get_path(self):
|
||||
if self.parent == None:
|
||||
return [ ]
|
||||
return self.parent.get_path() + [ self.node_index() ]
|
||||
|
||||
def node_index(self):
|
||||
if self.parent == None:
|
||||
return None
|
||||
|
|
|
@ -124,3 +124,18 @@ class TestPlaylistNode(unittest.TestCase):
|
|||
self.assertEqual(b.parent, a)
|
||||
self.assertEqual(a.parent, root)
|
||||
self.assertIsNone(root.parent)
|
||||
|
||||
def test_node_get_path(self):
|
||||
root = node.PlaylistNode()
|
||||
a = node.PlaylistNode("a")
|
||||
b = node.PlaylistNode("b")
|
||||
c = node.PlaylistNode("c")
|
||||
|
||||
root.append_child(a)
|
||||
a.append_child(b)
|
||||
b.append_child(c)
|
||||
|
||||
self.assertEqual(root.get_path(), [ ])
|
||||
self.assertEqual(a.get_path(), [ 0 ])
|
||||
self.assertEqual(b.get_path(), [ 0, 0 ])
|
||||
self.assertEqual(c.get_path(), [ 0, 0, 0 ])
|
||||
|
|
Loading…
Reference in New Issue