rind: Node model cleanups
- Listen for the "first-child" notification rather than "node-inserted" - Use the walrus operator in more places to tidy up the code - Use the playlist_iter() function to get iterators directly Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0f03891225
commit
a8cd9a84f3
|
@ -57,25 +57,22 @@ class NodeTreeModel(GObject.GObject, Gtk.TreeModel):
|
|||
return self.iter_n_children(iter) > 0
|
||||
|
||||
def do_iter_n_children(self, iter):
|
||||
plist = self.iter_playlist(iter)
|
||||
if plist:
|
||||
if (plist := self.iter_playlist(iter)):
|
||||
return plist.n_children()
|
||||
return 0
|
||||
|
||||
def do_iter_nth_child(self, iter, n):
|
||||
plist = self.iter_playlist(iter)
|
||||
if plist == None or n >= plist.n_children():
|
||||
return (False, None)
|
||||
child = plist.nth_child(n)
|
||||
return (True, self.playlist_iter(child))
|
||||
if (plist := self.iter_playlist(iter)) != None:
|
||||
if (child := plist.nth_child(n)) != None:
|
||||
return (True, self.playlist_iter(child))
|
||||
return (False, None)
|
||||
|
||||
def do_iter_next(self, iter):
|
||||
plist = self.iter_playlist(iter)
|
||||
next = plist.next_child() if plist != None else None
|
||||
if next == None:
|
||||
return (False, None)
|
||||
iter.user_data = id(next)
|
||||
return (True, iter)
|
||||
if (plist := self.iter_playlist(iter)) != None:
|
||||
if (next := plist.next_child()) != None:
|
||||
iter.user_data = id(next)
|
||||
return (True, iter)
|
||||
return (False, None)
|
||||
|
||||
def do_iter_parent(self, child):
|
||||
plist = self.iter_playlist(child)
|
||||
|
@ -89,15 +86,14 @@ class NodeTreeModel(GObject.GObject, Gtk.TreeModel):
|
|||
return curds.playlist.Root.lookup_byid(iter.user_data)
|
||||
return curds.playlist.Root
|
||||
|
||||
def on_first_child(self, parent, path):
|
||||
if parent.parent != None:
|
||||
self.row_has_child_toggled(Gtk.TreePath(path), self.playlist_iter(parent))
|
||||
|
||||
def on_playlist_changed(self, plist):
|
||||
if plist.parent:
|
||||
path = Gtk.TreePath(plist.get_path())
|
||||
self.row_changed(path, self.get_iter(path))
|
||||
|
||||
def on_node_inserted(self, plist, index):
|
||||
if not plist.parent.n_children() > 1:
|
||||
path = Gtk.TreePath(plist.parent.get_path())
|
||||
self.row_has_child_toggled(path, self.get_iter(path))
|
||||
self.row_changed(path, self.playlist_iter(plist))
|
||||
|
||||
def playlist_iter(self, plist):
|
||||
if plist == None or plist.parent == None:
|
||||
|
@ -107,5 +103,5 @@ class NodeTreeModel(GObject.GObject, Gtk.TreeModel):
|
|||
return iter
|
||||
|
||||
def reset(self):
|
||||
curds.notify.register("node-inserted", self.on_node_inserted, idle=True)
|
||||
curds.notify.register("first-child", self.on_first_child, idle=True)
|
||||
curds.notify.register("playlist-changed", self.on_playlist_changed, idle=True)
|
||||
|
|
|
@ -23,7 +23,7 @@ class TestNodeTreeModel(unittest.TestCase):
|
|||
curds.trak.lookup(os.path.join(test_album2, "01 - Test Track 01.ogg"))
|
||||
|
||||
def tearDown(self):
|
||||
curds.notify.cancel("node-inserted", self.model.on_node_inserted)
|
||||
curds.notify.cancel("first-child", self.model.on_first_child)
|
||||
curds.notify.cancel("playlist-changed", self.model.on_playlist_changed)
|
||||
|
||||
def tearDownClass():
|
||||
|
|
Loading…
Reference in New Issue