curds: Swap out the LibraryManager for the LibraryNode

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-17 10:01:28 -04:00
parent c29313dde8
commit eee4e134b0
6 changed files with 36 additions and 86 deletions

View File

@ -64,15 +64,6 @@ class GenreManager(PlaylistManagerBase):
notify.register("new-track", self.add_track)
class LibraryManager(PlaylistManagerBase):
def __init__(self):
PlaylistManagerBase.__init__(self, "Library", "folder-music",
library.LibraryPlaylist)
def normalize(self, path):
return os.path.abspath(path)
class Placeholder(PlaylistManagerBase):
def __init__(self):
PlaylistManagerBase.__init__(self)
@ -91,7 +82,7 @@ class PlaylistManager(PlaylistManagerBase):
self.append(Placeholder())
self.append(GenreManager())
self.append(Placeholder())
self.append(LibraryManager())
self.append(library.LibraryNode())
self.current = [ self.lookup("Collection") ]
self.track = None
@ -142,7 +133,7 @@ class PlaylistManager(PlaylistManagerBase):
if isinstance(child, genre.GenrePlaylist):
parent = self.lookup("Genre")
elif isinstance(child, library.LibraryPlaylist):
parent = self.lookup("Library")
return child.parent
return parent if child in parent else None
def previous(self):

View File

@ -57,9 +57,7 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIsInstance(self.playman.lookup("Genre"), manager.PlaylistManagerBase)
self.assertIsInstance(self.playman.lookup("Genre"), list)
self.assertIsInstance(self.playman.lookup("Library"), manager.LibraryManager)
self.assertIsInstance(self.playman.lookup("Library"), manager.PlaylistManagerBase)
self.assertIsInstance(self.playman.lookup("Library"), list)
self.assertIsInstance(self.playman.lookup("Libraries"), library.LibraryNode)
self.assertEqual(self.playman.current, [ self.playman.lookup("Collection") ])
self.assertEqual(self.playman.track, None)
@ -72,7 +70,7 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIsInstance(self.playman[2], manager.Placeholder)
self.assertEqual( self.playman[3], self.playman.lookup("Genre"))
self.assertIsInstance(self.playman[4], manager.Placeholder)
self.assertEqual( self.playman[5], self.playman.lookup("Library"))
self.assertEqual( self.playman[5], self.playman.lookup("Libraries"))
self.assertIsNone(self.playman[999])
for i in range(len(self.playman)):
@ -87,54 +85,13 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIsNone(place.lookup("Test", allocate=True))
self.assertEqual(len(place), 0)
def test_manager_library(self):
plist = self.playman.lookup("Library").lookup(test_library + "/", allocate=True)
self.assertEqual(self.cb_plist, plist)
self.assertEqual(self.cb_index, 0)
self.assertTrue(self.cb_first)
self.assertEqual(str(self.playman.lookup("Library")), "<big>Library</big>")
self.assertEqual(self.playman.lookup("Library").name, "Library")
self.assertEqual(self.playman.lookup("Library").icon, "folder-music")
self.assertEqual(plist.name, test_library)
self.assertIsInstance(plist, library.LibraryPlaylist)
self.cb_plist = None
self.assertEqual(self.playman.lookup("Library").lookup(test_library), plist)
self.assertIsNone(self.cb_plist)
self.assertIsNone(self.playman.lookup("Library").lookup(test_album))
alist = self.playman.lookup("Library").lookup(test_album, allocate=True)
self.assertEqual(self.cb_plist, alist)
self.assertEqual(self.cb_index, 0)
self.assertFalse(self.cb_first)
self.assertIsInstance(alist, library.LibraryPlaylist)
self.assertNotEqual(id(plist), id(alist))
self.assertIn(alist, self.playman.lookup("Library"))
self.assertIn(plist, self.playman.lookup("Library"))
self.assertEqual(self.playman.lookup("Library").lookup(test_album), alist)
self.assertEqual(self.playman.lookup("Library").lookup(test_library + "/"), plist)
self.assertIsNone(self.playman.lookup("Library").lookup("No such library"))
parent = self.playman.parent(plist)
self.assertEqual(parent, self.playman.lookup("Library"))
parent = self.playman.parent(alist)
self.assertEqual(parent, self.playman.lookup("Library"))
parent = self.playman.parent(self.playman.lookup("Library"))
self.assertEqual(parent, self.playman)
self.playman.reset()
self.assertEqual(len(self.playman.lookup("Library")), 0)
def test_manager_genre(self):
genreman = self.playman.lookup("Genre")
self.assertEqual(str(genreman), "<big>Genre</big>")
self.assertEqual(genreman.name, "Genre")
self.assertEqual(genreman.icon, "audio-x-generic-symbolic")
self.playman.lookup("Library").lookup(test_library, allocate=True)
self.playman.lookup("Libraries").lookup(test_library)
library.join()
plist = genreman.lookup("Test Genre 1")
@ -156,17 +113,10 @@ class TestPlaylistManager(unittest.TestCase):
self.assertIn((genreman.add_track, False), notify.registered["new-track"])
def test_manager_on_scan(self):
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
self.assertEqual(self.playman.lookup("Library").index(plist), 0)
self.assertEqual(self.playman.lookup("Library")[0], plist)
alist = self.playman.lookup("Library").lookup(test_album, allocate=True)
self.assertEqual(self.playman.lookup("Library").index(alist), 0)
self.assertEqual(self.playman.lookup("Library").index(plist), 1)
self.assertEqual(self.playman.lookup("Library")[0], alist)
self.assertEqual(self.playman.lookup("Library")[1], plist)
plist = self.playman.lookup("Libraries").lookup(test_library)
alist = self.playman.lookup("Libraries").lookup(test_album)
library.join()
self.assertEqual(len(plist), 1250)
self.assertEqual(len(alist), 12)
self.assertEqual(len(self.playman.lookup("Collection")), len(alist) + len(plist))
@ -180,7 +130,7 @@ class TestPlaylistManager(unittest.TestCase):
clist = self.playman.lookup("Collection")
prev = self.playman.lookup("Previous")
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
plist = self.playman.lookup("Libraries").lookup(test_library)
library.join()
track1 = self.playman.next()
@ -210,7 +160,7 @@ class TestPlaylistManager(unittest.TestCase):
self.assertEqual(self.playman.peek(3), [ ])
clist = self.playman.lookup("Collection")
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
plist = self.playman.lookup("Libraries").lookup(test_library)
library.join()
random.seed(1)
@ -233,7 +183,7 @@ class TestPlaylistManager(unittest.TestCase):
def test_manager_select_playlist(self):
clist = self.playman.lookup("Collection")
plist = self.playman.lookup("Library").lookup(test_library, allocate=True)
plist = self.playman.lookup("Libraries").lookup(test_library)
library.join()
glist = self.playman.lookup("Genre").lookup("Test Genre 1")

View File

@ -61,7 +61,10 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
def do_iter_n_children(self, iter):
plist = self.iter_playlist(iter)
if plist and not isinstance(plist, curds.Playlist):
return len(plist)
try:
return plist.n_children()
except:
return len(plist)
return 0
def do_iter_nth_child(self, iter, n):
@ -109,8 +112,11 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
if iter and iter.user_data > 0:
plist = curds.PlaylistManager[iter.user_data - 1]
if plist != None and iter.user_data2 > 0:
valid = not isinstance(plist, curds.Playlist)
plist = plist[iter.user_data2 - 1] if valid == True else None
try:
plist = plist.nth_child(iter.user_data2 - 1)
except:
valid = not isinstance(plist, curds.Playlist)
plist = plist[iter.user_data2 - 1] if valid == True else None
return plist
def iter_valid(self, iter):
@ -157,7 +163,10 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
iter.user_data = parent.index(plist) + 1
else:
iter = self.playlist_iter(parent)
iter.user_data2 = parent.index(plist) + 1
try:
iter.user_data2 = plist.node_index() + 1
except:
iter.user_data2 = parent.index(plist) + 1
return iter
def set_filter_text(self, entry):
@ -184,7 +193,7 @@ def library_cancel_clicked(self, *args):
def library_ok_clicked(self, *args):
path = LibraryChooser.get_filename()
LibraryPopover.popdown()
curds.PlaylistManager.lookup("Library").lookup(path, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(path)
LibraryAdd = gtk.Builder.get_object("library_add")

View File

@ -152,7 +152,7 @@ class TestGst(unittest.TestCase):
gst.PrevButton.clicked()
self.assertIsNone(curds.PlaylistManager.track)
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
self.assertEqual(curds.PlaylistManager.lookup("Collection").current, -1)
@ -212,7 +212,7 @@ class TestGst(unittest.TestCase):
def test_gst_automatic_pause_up(self):
plist = curds.PlaylistManager.lookup("Collection")
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
plist.list.sort(key=self.sort_key)
@ -262,7 +262,7 @@ class TestGst(unittest.TestCase):
def test_gst_automatic_pause_down(self):
plist = curds.PlaylistManager.lookup("Collection")
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
plist.list.sort(key=self.sort_key)
@ -310,7 +310,7 @@ class TestGst(unittest.TestCase):
def test_gst_automatic_pause_entry(self):
plist = curds.PlaylistManager.lookup("Collection")
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
gst.PauseEntry.set_text("3")
@ -339,7 +339,7 @@ class TestGst(unittest.TestCase):
def test_gst_about_to_finish(self):
plist = curds.PlaylistManager.lookup("Collection")
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
curds.PlaylistManager.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
self.audio.next()

View File

@ -178,7 +178,7 @@ class TestManager(unittest.TestCase):
iter = self.model.iter_next(iter)
def test_model_iter_previous(self):
iter = self.model.playlist_iter(plist_mgr.lookup("Library"))
iter = self.model.playlist_iter(plist_mgr.lookup("Libraries"))
for i in range(len(curds.PlaylistManager) - 1, -1, -1):
self.assertTreeIterEqual(iter, (i + 1, 0, 0))
iter = self.model.iter_previous(iter)
@ -320,18 +320,18 @@ class TestManager(unittest.TestCase):
manager.LibraryAdd.clicked()
gtk.main_loop()
self.assertTrue(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
self.assertEqual(plist_mgr.lookup("Libraries").n_children(), 0)
manager.LibraryCancel.clicked()
gtk.main_loop(iteration_delay=0.1)
self.assertFalse(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
self.assertEqual(plist_mgr.lookup("Libraries").n_children(), 0)
manager.LibraryAdd.clicked()
gtk.main_loop()
self.assertEqual(manager.LibraryChooser.get_filename(), music_dir)
self.assertTrue(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
self.assertEqual(plist_mgr.lookup("Libraries").n_children(), 0)
manager.LibraryChooser.set_filename(test_album1)
gtk.main_loop(delay=0.1)
@ -339,5 +339,5 @@ class TestManager(unittest.TestCase):
manager.LibraryOk.clicked()
gtk.main_loop(iteration_delay=0.1)
self.assertEqual(len(plist_mgr.lookup("Library")), 1)
self.assertEqual(plist_mgr.lookup("Libraries").n_children(), 1)
self.assertFalse(manager.LibraryPopover.is_visible())

View File

@ -39,7 +39,7 @@ class TestEmmental(unittest.TestCase):
self.assertEqual(curds.tags.tag_map, {})
self.assertTrue(curds.playlist.library.library_thread.is_alive())
self.assertEqual(len(curds.PlaylistManager.lookup("Collection")), 0)
self.assertEqual(len(curds.PlaylistManager.lookup("Library")), 0)
self.assertEqual(curds.PlaylistManager.lookup("Libraries").n_children(), 0)
curds.stop()
self.assertFalse(curds.playlist.library.library_thread.is_alive())