audio: Create a custom AutoPauseControlBox

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-09-02 11:35:13 -04:00
parent d551e0ea13
commit 68f0541079
2 changed files with 22 additions and 0 deletions

View File

@ -53,6 +53,15 @@ class ControlScaleBox(scale.ScaleButtonBox):
pass
class AutoPauseControlBox(ControlScaleBox):
def __init__(self, apscale):
ControlScaleBox.__init__(self, apscale)
def on_value_changed(self, scale, icon):
name = "start" if scale.get_value() == -1 else "pause"
icon.set_from_icon_name(f"media-playback-{name}")
class VolumeControlBox(ControlScaleBox):
def __init__(self, player):
ControlScaleBox.__init__(self, scale.VolumeScale(player))

View File

@ -84,6 +84,19 @@ class TestControlScaleBox(unittest.TestCase):
self.assertTrue(ctrlbox.get_first_child().has_css_class("large-icons"))
class TestAutoPauseControlBox(unittest.TestCase):
def test_autopause_control_box(self):
apscale = scale.AutoPauseScale()
apbox = controls.AutoPauseControlBox(apscale)
icon = apbox.get_first_child()
self.assertIsInstance(apbox, controls.ControlScaleBox)
apscale.set_value(-1)
self.assertEqual(icon.get_icon_name(), "media-playback-start")
apscale.set_value(0)
self.assertEqual(icon.get_icon_name(), "media-playback-pause")
class TestVolumeControlbox(unittest.TestCase):
def test_volume_control_box(self):
fake = FakePlayer()