nowplaying: Give the autopause widgets {inc,dec}rement() functions
These will be used for keyboard accelerators to set the autopause value. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
bb4ca1e9c4
commit
87b92ffc90
|
@ -91,6 +91,16 @@ class Entry(Gtk.Entry):
|
|||
self.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY,
|
||||
self.value < 99)
|
||||
|
||||
def decrement(self) -> None:
|
||||
"""Decrease the autopause count by 1."""
|
||||
if self.value > -1:
|
||||
self.value -= 1
|
||||
|
||||
def increment(self) -> None:
|
||||
"""Increase the autopause count by 1."""
|
||||
if self.value < 99:
|
||||
self.value += 1
|
||||
|
||||
|
||||
class Button(buttons.PopoverButton):
|
||||
"""A PopoverButton that displays Autopause count."""
|
||||
|
@ -116,3 +126,11 @@ class Button(buttons.PopoverButton):
|
|||
def __notify_value(self, button: buttons.PopoverButton, param) -> None:
|
||||
text = str(self.value) if self.value > -1 else ""
|
||||
self._count.set_markup(f"<small>{text}</small>")
|
||||
|
||||
def decrement(self) -> None:
|
||||
"""Decrease the autopause value."""
|
||||
self.popover_child.decrement()
|
||||
|
||||
def increment(self) -> None:
|
||||
"""Increase the autopause value."""
|
||||
self.popover_child.increment()
|
||||
|
|
|
@ -148,6 +148,26 @@ class TestAutopauseEntry(unittest.TestCase):
|
|||
self.entry.emit("activate")
|
||||
self.assertEqual(self.entry.value, value, f"text=\"{text}\"")
|
||||
|
||||
def test_decrement(self):
|
||||
"""Test the decrement() function."""
|
||||
self.entry.value = 1
|
||||
self.entry.decrement()
|
||||
self.assertEqual(self.entry.value, 0)
|
||||
self.entry.decrement()
|
||||
self.assertEqual(self.entry.value, -1)
|
||||
self.entry.decrement()
|
||||
self.assertEqual(self.entry.value, -1)
|
||||
|
||||
def test_increment(self):
|
||||
"""Test the increment() function."""
|
||||
self.entry.value = 97
|
||||
self.entry.increment()
|
||||
self.assertEqual(self.entry.value, 98)
|
||||
self.entry.increment()
|
||||
self.assertEqual(self.entry.value, 99)
|
||||
self.entry.increment()
|
||||
self.assertEqual(self.entry.value, 99)
|
||||
|
||||
|
||||
class TestAutopauseButton(unittest.TestCase):
|
||||
"""Test our Autopause Popover Button."""
|
||||
|
@ -194,3 +214,17 @@ class TestAutopauseButton(unittest.TestCase):
|
|||
|
||||
self.button.value = -1
|
||||
self.assertEqual(self.button._count.get_text(), "")
|
||||
|
||||
def test_decrement(self):
|
||||
"""Test the decrement() function."""
|
||||
with unittest.mock.patch.object(self.button.popover_child,
|
||||
"decrement") as mock_decrement:
|
||||
self.button.decrement()
|
||||
mock_decrement.assert_called()
|
||||
|
||||
def test_increment(self):
|
||||
"""Test the increment() functions."""
|
||||
with unittest.mock.patch.object(self.button.popover_child,
|
||||
"increment") as mock_increment:
|
||||
self.button.increment()
|
||||
mock_increment.assert_called()
|
||||
|
|
Loading…
Reference in New Issue