curds: Have the playlist track if loop and random values can change
This way, we control it all from one place instead of needing to derive a new playlist to set these values. Additionally, the UI can use these values to enable or disable the corresponding buttons Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
b0cbcd7f9d
commit
82cf07ff36
|
@ -4,14 +4,11 @@ from .. import notify
|
|||
|
||||
class CollectionPlaylist(playlist.Playlist):
|
||||
def __init__(self):
|
||||
playlist.Playlist.__init__(self, "Collection", "media-playback-start")
|
||||
playlist.Playlist.__init__(self, "Collection", "media-playback-start", can_loop=False)
|
||||
notify.register("new-track", self.add)
|
||||
self.loop = True
|
||||
|
||||
def reset(self):
|
||||
playlist.Playlist.reset(self)
|
||||
notify.register("new-track", self.add)
|
||||
self.set_loop(True)
|
||||
|
||||
def set_loop(self, loop):
|
||||
return playlist.Playlist.set_loop(self, True)
|
||||
self.loop = True
|
||||
|
|
|
@ -4,13 +4,15 @@ from .. import notify
|
|||
import random
|
||||
|
||||
class Playlist(node.PlaylistNode):
|
||||
def __init__(self, name, icon=""):
|
||||
def __init__(self, name, icon="", can_loop=True, can_random=True):
|
||||
node.PlaylistNode.__init__(self, name, icon)
|
||||
self.list = [ ]
|
||||
self.current = -1
|
||||
self.iter = -1
|
||||
self.loop = False
|
||||
self.random = False
|
||||
self.list = [ ]
|
||||
self.current = -1
|
||||
self.iter = -1
|
||||
self.can_loop = can_loop
|
||||
self.loop = False
|
||||
self.can_random = can_random
|
||||
self.random = False
|
||||
|
||||
def __getitem__(self, i):
|
||||
return self.list[i]
|
||||
|
@ -94,9 +96,11 @@ class Playlist(node.PlaylistNode):
|
|||
return ", ".join(res)
|
||||
|
||||
def set_loop(self, loop):
|
||||
self.loop = loop
|
||||
if self.can_loop == True:
|
||||
self.loop = loop
|
||||
return self.loop
|
||||
|
||||
def set_random(self, random):
|
||||
self.random = random
|
||||
if self.can_random == True:
|
||||
self.random = random
|
||||
return self.random
|
||||
|
|
|
@ -4,7 +4,7 @@ from .. import notify
|
|||
|
||||
class PreviousPlaylist(playlist.Playlist):
|
||||
def __init__(self):
|
||||
playlist.Playlist.__init__(self, "Previous", "edit-undo")
|
||||
playlist.Playlist.__init__(self, "Previous", "edit-undo", can_loop=False, can_random=False)
|
||||
|
||||
def add(self, track):
|
||||
if track is not None and track not in self:
|
||||
|
@ -12,9 +12,3 @@ class PreviousPlaylist(playlist.Playlist):
|
|||
self.current = 0
|
||||
notify.notify("add-track", self, track, 0)
|
||||
self.changed()
|
||||
|
||||
def set_loop(self, loop):
|
||||
return playlist.Playlist.set_loop(self, False)
|
||||
|
||||
def set_random(self, random):
|
||||
return playlist.Playlist.set_random(self, False)
|
||||
|
|
|
@ -22,9 +22,10 @@ class TestCollectionPlaylist(unittest.TestCase):
|
|||
self.assertEqual(len(plist), 1)
|
||||
self.assertEqual(plist[0], track1)
|
||||
|
||||
self.assertTrue(plist.loop)
|
||||
self.assertTrue(plist.set_loop(False))
|
||||
self.assertTrue(plist.loop)
|
||||
self.assertFalse(plist.can_loop)
|
||||
self.assertTrue( plist.loop)
|
||||
self.assertTrue( plist.set_loop(False))
|
||||
self.assertTrue( plist.loop)
|
||||
|
||||
notify.cancel("new-track", plist.add)
|
||||
plist.reset()
|
||||
|
|
|
@ -40,7 +40,9 @@ class TestPlaylist(unittest.TestCase):
|
|||
self.assertEqual(len(plist), 0)
|
||||
self.assertEqual(plist.runtime(), "")
|
||||
self.assertEqual(plist.current, -1)
|
||||
self.assertTrue( plist.can_loop)
|
||||
self.assertFalse(plist.loop)
|
||||
self.assertTrue( plist.can_random)
|
||||
self.assertFalse(plist.random)
|
||||
|
||||
def test_playlist_add(self):
|
||||
|
@ -110,6 +112,25 @@ class TestPlaylist(unittest.TestCase):
|
|||
self.assertEqual(self.cb_index, 0)
|
||||
self.assertEqual(self.cb_changed, plist)
|
||||
|
||||
def test_playlist_can_loop_random(self):
|
||||
plist = playlist.Playlist("Test Playlist", can_loop=False, can_random=False)
|
||||
|
||||
self.assertFalse(plist.can_loop)
|
||||
self.assertFalse(plist.loop)
|
||||
self.assertFalse(plist.set_loop(True))
|
||||
self.assertFalse(plist.loop)
|
||||
plist.loop = True
|
||||
self.assertTrue(plist.set_loop(False))
|
||||
self.assertTrue(plist.loop)
|
||||
|
||||
self.assertFalse(plist.can_random)
|
||||
self.assertFalse(plist.random)
|
||||
self.assertFalse(plist.set_random(True))
|
||||
self.assertFalse(plist.random)
|
||||
plist.random = True
|
||||
self.assertTrue(plist.set_random(False))
|
||||
self.assertTrue(plist.random)
|
||||
|
||||
def test_playlist_next(self):
|
||||
path = os.path.join(test_library, "Test Artist 01", "Test Album 1")
|
||||
plist = playlist.Playlist("Test Playlist")
|
||||
|
|
|
@ -32,10 +32,12 @@ class TestPreviousPlaylist(unittest.TestCase):
|
|||
self.assertEqual(plist.name, "Previous")
|
||||
self.assertEqual(plist.icon, "edit-undo")
|
||||
|
||||
self.assertFalse(plist.can_loop)
|
||||
self.assertFalse(plist.loop)
|
||||
self.assertFalse(plist.set_loop(True))
|
||||
self.assertFalse(plist.loop)
|
||||
|
||||
self.assertFalse(plist.can_random)
|
||||
self.assertFalse(plist.random)
|
||||
self.assertFalse(plist.set_random(True))
|
||||
self.assertFalse(plist.random)
|
||||
|
|
Loading…
Reference in New Issue