curds: Merge the PlaylistManager with the PlaylistManagerBase
Nothing else inherits from this class anymore, so let's merge it into one to make it easier to deal with going forward. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2c779b475d
commit
af54734726
|
@ -8,49 +8,8 @@ from .. import notify
|
|||
import os
|
||||
import random
|
||||
|
||||
class PlaylistManagerBase(list):
|
||||
def __init__(self, name="", icon="", alloc=None):
|
||||
self.name = name
|
||||
self.icon = icon
|
||||
self.alloc = alloc
|
||||
|
||||
def __getitem__(self, index):
|
||||
if index < len(self):
|
||||
return list.__getitem__(self, index)
|
||||
return None
|
||||
|
||||
def __str__(self):
|
||||
return f"<big>{self.name}</big>"
|
||||
|
||||
def index(self, plist):
|
||||
for (i, pl) in enumerate(self):
|
||||
if id(pl) == id(plist): return i
|
||||
return None
|
||||
|
||||
def lookup(self, name, allocate=False):
|
||||
name = self.normalize(name)
|
||||
for plist in self:
|
||||
if plist.name == name: return plist
|
||||
if allocate == True and self.alloc != None:
|
||||
plist = self.alloc(name)
|
||||
index = len(self)
|
||||
for i, p in enumerate(self):
|
||||
if plist < p:
|
||||
index = i
|
||||
break
|
||||
self.insert(index, plist)
|
||||
notify.notify("new-playlist", plist, index, len(self) == 1)
|
||||
return plist
|
||||
return None
|
||||
|
||||
def normalize(self, name):
|
||||
return name.title()
|
||||
|
||||
def reset(self):
|
||||
self.clear()
|
||||
|
||||
|
||||
class PlaylistManager(PlaylistManagerBase):
|
||||
class PlaylistManager(list):
|
||||
def __init__(self):
|
||||
self.append(collection.CollectionPlaylist())
|
||||
self.append(previous.PreviousPlaylist())
|
||||
|
@ -59,11 +18,27 @@ class PlaylistManager(PlaylistManagerBase):
|
|||
self.current = [ self.lookup("Collection") ]
|
||||
self.track = None
|
||||
|
||||
def __getitem__(self, index):
|
||||
if index < len(self):
|
||||
return list.__getitem__(self, index)
|
||||
return None
|
||||
|
||||
def __current_changed(self, old):
|
||||
if old != self.current[0]:
|
||||
old.changed()
|
||||
self.current[0].changed()
|
||||
|
||||
def index(self, plist):
|
||||
for (i, pl) in enumerate(self):
|
||||
if id(pl) == id(plist): return i
|
||||
return None
|
||||
|
||||
def lookup(self, name):
|
||||
name = name.title()
|
||||
for plist in self:
|
||||
if plist.name == name: return plist
|
||||
return None
|
||||
|
||||
def next(self):
|
||||
old = self.current[0]
|
||||
self.track = self.current[0].next()
|
||||
|
|
|
@ -48,7 +48,6 @@ class TestPlaylistManager(unittest.TestCase):
|
|||
|
||||
def test_manager_init(self):
|
||||
self.assertIsInstance(self.playman, manager.PlaylistManager)
|
||||
self.assertIsInstance(self.playman, manager.PlaylistManagerBase)
|
||||
self.assertIsInstance(self.playman, list)
|
||||
|
||||
self.assertIsInstance(self.playman.lookup("Collection"), collection.CollectionPlaylist)
|
||||
|
|
Loading…
Reference in New Issue