lib: Give Tags a stacked() function

This will be called when a tag is added to the tag stack to check if the
current track pointer needs to be reset.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-07-06 16:14:39 -04:00
parent d51ee8e0e2
commit 7037483508
2 changed files with 17 additions and 0 deletions

View File

@ -98,6 +98,11 @@ class Tag:
self.tracks.remove(track)
self.TrackRemoved.publish(self, track)
def stacked(self):
with self.lock:
if self.current >= len(self.tracks):
self.current = -1
class SuperTag(Tag):
def __init__(self, parent, name, sort=None):

View File

@ -167,6 +167,18 @@ class TestTag(unittest.TestCase):
self.assertEqual(t.next(), 0)
self.assertEqual(t.next(), 1)
def test_tag_stacked(self):
t = tag.Tag("test")
t.tracks = [ 0, 1, 2 ]
t.current = 3
t.stacked()
self.assertEqual(t.current, -1)
t.current = 1
t.stacked()
self.assertEqual(t.current, 1)
class TestSuperTag(unittest.TestCase):
def test_super_tag(self):