curds: Change the PlaylistManager into a PlaylistNode

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-18 10:53:37 -04:00
parent cd208134ec
commit 277aabb7bd
2 changed files with 10 additions and 39 deletions

View File

@ -2,25 +2,19 @@
from . import collection
from . import genre
from . import library
from . import playlist
from . import node
from . import previous
from .. import notify
import os
import random
class PlaylistManager:
class PlaylistManager(node.PlaylistNode):
def __init__(self):
self.children = [ ]
self.parent = None
node.PlaylistNode.__init__(self, "root")
self.children.append(collection.CollectionPlaylist())
self.children.append(previous.PreviousPlaylist())
self.children.append(genre.GenreNode())
self.children.append(library.LibraryNode())
for plist in self.children:
plist.parent = self
self.append_child(collection.CollectionPlaylist())
self.append_child(previous.PreviousPlaylist())
self.append_child(genre.GenreNode())
self.append_child(library.LibraryNode())
self.current = [ self.lookup("Collection") ]
self.track = None
@ -30,24 +24,6 @@ class PlaylistManager:
old.changed()
self.current[0].changed()
def get_node(self, path):
if len(path) == 1:
return self.nth_child(path[0])
elif len(path) > 1:
if path[0] < self.n_children():
node = self.nth_child(path[0])
return node.get_node(path[1:])
return None
def get_path(self):
return [ ]
def lookup(self, name):
name = name.title()
for plist in self.children:
if plist.name == name: return plist
return None
def next(self):
old = self.current[0]
self.track = self.current[0].next()
@ -58,14 +34,6 @@ class PlaylistManager:
self.__current_changed(old)
return self.track
def n_children(self):
return len(self.children)
def nth_child(self, n):
if n < len(self.children):
return self.children[n]
return None
def __peek_pl(self, plist, n):
cur = plist.current
res = [ ]

View File

@ -3,6 +3,7 @@ from . import collection
from . import genre
from . import library
from . import manager
from . import node
from . import playlist
from . import previous
from .. import notify
@ -48,12 +49,14 @@ class TestPlaylistManager(unittest.TestCase):
def test_manager_init(self):
self.assertIsInstance(self.playman, manager.PlaylistManager)
self.assertIsInstance(self.playman, node.PlaylistNode)
self.assertIsInstance(self.playman.lookup("Collection"), collection.CollectionPlaylist)
self.assertIsInstance(self.playman.lookup("Previous"), previous.PreviousPlaylist)
self.assertIsInstance(self.playman.lookup("Genres"), genre.GenreNode)
self.assertIsInstance(self.playman.lookup("Libraries"), library.LibraryNode)
self.assertEqual(self.playman.name, "Root")
self.assertEqual(self.playman.current, [ self.playman.lookup("Collection") ])
self.assertEqual(self.playman.track, None)