rind: Calculate an estimate for how long until we pause
I either round to the nearest minute or nearest 5-second interval depending on how much time is left. This will eventually be used to populate a GtkPopover to display the remaining time. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
01c4988cce
commit
25c55fdac4
11
rind/gst.py
11
rind/gst.py
|
@ -166,6 +166,17 @@ class EmmentalAudio:
|
|||
self.pause_count = min(99, self.pause_count + 1)
|
||||
self.pause_changed(self.playbin.get_state(Gst.Format.TIME)[1])
|
||||
|
||||
def pause_time(self):
|
||||
tracks = curds.PlaylistManager.peek(self.pause_count)
|
||||
tracks.append(curds.PlaylistManager.track)
|
||||
length = [ t.length for t in tracks if t is not None ]
|
||||
(m, s) = divmod(sum(length) - self.position(), 60)
|
||||
if s >= 30:
|
||||
m += 1
|
||||
if m == 0:
|
||||
return f"About {round(s/5.0) * 5} seconds"
|
||||
return f"About {int(m)} minute{'s' if m != 1 else ''}"
|
||||
|
||||
def play(self, *args):
|
||||
self.playbin.set_state(Gst.State.PLAYING)
|
||||
|
||||
|
|
|
@ -203,16 +203,25 @@ class TestGst(unittest.TestCase):
|
|||
self.assertNotEqual(curds.PlaylistManager.track, track2)
|
||||
|
||||
def test_gst_automatic_pause_up(self):
|
||||
plist = curds.PlaylistManager.lookup("Collection")
|
||||
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
|
||||
curds.playlist.library.join()
|
||||
|
||||
gst.PauseUp.clicked()
|
||||
self.assertEqual(self.audio.pause_count, 0)
|
||||
self.assertTrue( gst.PauseDown.is_sensitive())
|
||||
self.assertTrue( gst.PauseUp.is_sensitive())
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "This Track")
|
||||
self.assertEqual(gst.PauseEntry.get_icon_name(gst.PauseIcon), "media-playback-pause")
|
||||
self.assertEqual(self.audio.pause_time(), "About 0 seconds")
|
||||
|
||||
gst.PauseUp.clicked()
|
||||
self.assertEqual(self.audio.pause_count, 1)
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "Next Track")
|
||||
self.assertEqual(self.audio.pause_time(), f"About 10 seconds")
|
||||
|
||||
self.audio.pause_count = 11
|
||||
self.assertEqual(self.audio.pause_time(), "About 1 minute")
|
||||
|
||||
self.audio.pause_count = 98
|
||||
self.audio.pause_changed(self.audio.playbin.get_state(Gst.Format.TIME))
|
||||
|
@ -222,43 +231,58 @@ class TestGst(unittest.TestCase):
|
|||
self.assertEqual(gst.PauseEntry.get_text(), "99 Tracks")
|
||||
self.assertTrue( gst.PauseDown.is_sensitive())
|
||||
self.assertFalse(gst.PauseUp.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 9 minutes")
|
||||
|
||||
gst.PauseUp.clicked()
|
||||
self.assertEqual(self.audio.pause_count, 99)
|
||||
|
||||
def test_gst_automatic_pause_down(self):
|
||||
plist = curds.PlaylistManager.lookup("Collection")
|
||||
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
|
||||
curds.playlist.library.join()
|
||||
|
||||
self.audio.pause_count = 99
|
||||
self.audio.pause_changed(self.audio.playbin.get_state(Gst.Format.TIME))
|
||||
self.assertEqual(self.audio.pause_time(), "About 9 minutes")
|
||||
|
||||
gst.PauseDown.clicked()
|
||||
self.assertEqual(self.audio.pause_count, 98)
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "98 Tracks")
|
||||
self.assertTrue( gst.PauseDown.is_sensitive())
|
||||
self.assertTrue( gst.PauseUp.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 9 minutes")
|
||||
|
||||
self.audio.pause_count = 1
|
||||
self.audio.pause_changed(self.audio.playbin.get_state(Gst.Format.TIME))
|
||||
self.assertEqual(self.audio.pause_time(), "About 10 seconds")
|
||||
|
||||
gst.PauseDown.clicked()
|
||||
self.assertEqual(self.audio.pause_count, 0)
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "This Track")
|
||||
self.assertEqual(self.audio.pause_time(), "About 0 seconds")
|
||||
|
||||
gst.PauseDown.clicked()
|
||||
self.assertEqual(self.audio.pause_count, -1)
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "Paused")
|
||||
self.assertFalse( gst.PauseDown.is_sensitive())
|
||||
self.assertTrue( gst.PauseUp.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 0 seconds")
|
||||
|
||||
gst.PauseDown.clicked()
|
||||
self.assertEqual(self.audio.pause_count, -1)
|
||||
|
||||
def test_gst_automatic_pause_entry(self):
|
||||
plist = curds.PlaylistManager.lookup("Collection")
|
||||
curds.PlaylistManager.lookup("Library").lookup(test_album, allocate=True)
|
||||
curds.playlist.library.join()
|
||||
|
||||
gst.PauseEntry.set_text("3")
|
||||
gst.PauseEntry.activate()
|
||||
self.assertEqual(self.audio.pause_count, 3)
|
||||
self.assertEqual(gst.PauseEntry.get_text(), "3 Tracks")
|
||||
self.assertTrue( gst.PauseUp.is_sensitive())
|
||||
self.assertTrue( gst.PauseDown.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 15 seconds")
|
||||
|
||||
gst.PauseEntry.set_text("100")
|
||||
gst.PauseEntry.activate()
|
||||
|
@ -266,6 +290,7 @@ class TestGst(unittest.TestCase):
|
|||
self.assertEqual(gst.PauseEntry.get_text(), "99 Tracks")
|
||||
self.assertFalse(gst.PauseUp.is_sensitive())
|
||||
self.assertTrue( gst.PauseDown.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 9 minutes")
|
||||
|
||||
gst.PauseEntry.set_text("-5")
|
||||
gst.PauseEntry.activate()
|
||||
|
@ -273,6 +298,7 @@ class TestGst(unittest.TestCase):
|
|||
self.assertEqual(gst.PauseEntry.get_text(), "Paused")
|
||||
self.assertTrue( gst.PauseUp.is_sensitive())
|
||||
self.assertFalse(gst.PauseDown.is_sensitive())
|
||||
self.assertEqual(self.audio.pause_time(), "About 0 seconds")
|
||||
|
||||
def test_gst_about_to_finish(self):
|
||||
plist = curds.PlaylistManager.lookup("Collection")
|
||||
|
|
Loading…
Reference in New Issue