playlist: Create a Runtime label
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0ed71f8792
commit
289a980390
|
@ -10,3 +10,22 @@ class VisibleTracks(Gtk.Label):
|
|||
def set_count(self, n):
|
||||
s = 's' if n != 1 else ''
|
||||
self.set_text(f"Showing {n} track{s}")
|
||||
|
||||
|
||||
class Runtime(Gtk.Label):
|
||||
def __init__(self):
|
||||
Gtk.Label.__init__(self)
|
||||
self.set_halign(Gtk.Align.END)
|
||||
self.set_hexpand(True)
|
||||
|
||||
def set_runtime(self, seconds):
|
||||
(min, sec) = divmod(seconds, 60)
|
||||
(hour, min) = divmod(min, 60)
|
||||
(day, hour) = divmod(hour, 24)
|
||||
(week, day) = divmod(day, 7)
|
||||
|
||||
vals = [ ("week", week), ("day", day), ("hour", hour),
|
||||
("minute", min), ("second", sec) ]
|
||||
text = [ f"{v} {k}{'s' if v != 1 else ''}" for (k, v) in vals if v != 0 ]
|
||||
|
||||
self.set_text(', '.join(text) if len(text) > 0 else "0 seconds")
|
||||
|
|
|
@ -18,3 +18,26 @@ class TestVisibleTracks(unittest.TestCase):
|
|||
self.assertEqual(visible.get_text(), "Showing 1 track")
|
||||
visible.set_count(2)
|
||||
self.assertEqual(visible.get_text(), "Showing 2 tracks")
|
||||
|
||||
|
||||
class TestRuntime(unittest.TestCase):
|
||||
def test_init(self):
|
||||
runtime = footer.Runtime()
|
||||
self.assertIsInstance(runtime, Gtk.Label)
|
||||
self.assertEqual(runtime.get_halign(), Gtk.Align.END)
|
||||
self.assertTrue(runtime.get_hexpand())
|
||||
|
||||
def test_runtime(self):
|
||||
runtime = footer.Runtime()
|
||||
runtime.set_runtime(0)
|
||||
self.assertEqual(runtime.get_text(), "0 seconds")
|
||||
runtime.set_runtime(61)
|
||||
self.assertEqual(runtime.get_text(), "1 minute, 1 second")
|
||||
runtime.set_runtime(3720)
|
||||
self.assertEqual(runtime.get_text(), "1 hour, 2 minutes")
|
||||
runtime.set_runtime(93600)
|
||||
self.assertEqual(runtime.get_text(), "1 day, 2 hours")
|
||||
runtime.set_runtime(777600)
|
||||
self.assertEqual(runtime.get_text(), "1 week, 2 days")
|
||||
runtime.set_runtime(1209600)
|
||||
self.assertEqual(runtime.get_text(), "2 weeks")
|
||||
|
|
Loading…
Reference in New Issue