curds: Give nodes a first-child notification

The UI has been guessing this during scanning, but we can easily figure
this out and tell them when a tree node is given their first child.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-12-12 14:29:07 -05:00
parent 735f2bba6e
commit 0f03891225
2 changed files with 12 additions and 0 deletions

View File

@ -7,14 +7,20 @@ import unittest
class TestETree(unittest.TestCase):
def setUp(self):
notify.register("child-inserted", self.on_child_inserted)
notify.register("first-child", self.on_first_child)
def tearDown(self):
notify.cancel("child-inserted", self.on_child_inserted)
notify.cancel("first-child", self.on_first_child)
def on_child_inserted(self, child, path):
self.cb_child = child
self.cb_path = path
def on_first_child(self, parent, path):
self.cb_first = parent
self.cb_fpath = path
def test_etree_init(self):
etree = tree.ETree("Test Tree", "test-icon")
self.assertEqual(etree.name, "Test Tree")
@ -113,12 +119,16 @@ class TestETree(unittest.TestCase):
self.assertEqual(a.parent, root)
self.assertEqual(self.cb_child, a)
self.assertEqual(self.cb_path, [ 0 ])
self.assertEqual(self.cb_first, root)
self.assertEqual(self.cb_fpath, [ ])
self.cb_first = None
c = root.insert_child(tree.ETree("C", "icon"))
self.assertEqual(root.children, [ a, c ])
self.assertEqual(a.sibling, c)
self.assertEqual(self.cb_child, c)
self.assertEqual(self.cb_path, [ 1 ])
self.assertIsNone(self.cb_first)
b = root.insert_child(tree.ETree("B", "icon"))
self.assertEqual(root.children, [ a, b, c ])

View File

@ -28,6 +28,8 @@ class ETree:
with prev.tree_lock:
prev.sibling = child
if len(self.children) == 1:
notify.notify("first-child", self, self.get_path())
notify.notify("child-inserted", child, self.get_path() + [ index ])
return child