nowplaying: Create an Autopause Button
This is a PopoverButton that has an autopause.Entry set as the child. I also override the displayed icon to show the current autopause count. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
7cd77d3aed
commit
bf8d7fac1b
|
@ -4,6 +4,7 @@ import re
|
|||
from gi.repository import GObject
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gtk
|
||||
from .. import buttons
|
||||
|
||||
|
||||
class Entry(Gtk.Entry):
|
||||
|
@ -87,3 +88,29 @@ class Entry(Gtk.Entry):
|
|||
self.value > -1)
|
||||
self.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY,
|
||||
self.value < 99)
|
||||
|
||||
|
||||
class Button(buttons.PopoverButton):
|
||||
"""A PopoverButton that displays Autopause count."""
|
||||
|
||||
value = GObject.Property(type=int, default=-1, minimum=-1, maximum=99)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
"""Initialize an Autopause Button."""
|
||||
super().__init__(popover_child=Entry(), **kwargs)
|
||||
self._arrow = Gtk.Image(icon_name="pan-down-symbolic", margin_top=6)
|
||||
self._count = Gtk.Label(yalign=0, halign=Gtk.Align.CENTER,
|
||||
margin_top=3)
|
||||
self._overlay = Gtk.Overlay(child=self._arrow)
|
||||
|
||||
self._overlay.add_overlay(self._count)
|
||||
self.bind_property("value", self.popover_child, "value",
|
||||
GObject.BindingFlags.BIDIRECTIONAL)
|
||||
self.connect("notify::value", self.__notify_value)
|
||||
|
||||
self._count.set_markup("<small></small>")
|
||||
self.set_child(self._overlay)
|
||||
|
||||
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>")
|
||||
|
|
|
@ -146,3 +146,50 @@ class TestAutopauseEntry(unittest.TestCase):
|
|||
self.entry.set_text(text)
|
||||
self.entry.emit("activate")
|
||||
self.assertEqual(self.entry.value, value, f"text=\"{text}\"")
|
||||
|
||||
|
||||
class TestAutopauseButton(unittest.TestCase):
|
||||
"""Test our Autopause Popover Button."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up common variables."""
|
||||
self.button = emmental.nowplaying.autopause.Button()
|
||||
|
||||
def test_init(self):
|
||||
"""Test the autopause button."""
|
||||
self.assertIsInstance(self.button, emmental.buttons.PopoverButton)
|
||||
self.assertIsInstance(self.button._overlay, Gtk.Overlay)
|
||||
self.assertIsInstance(self.button.popover_child,
|
||||
emmental.nowplaying.autopause.Entry)
|
||||
self.assertEqual(self.button.get_child(), self.button._overlay)
|
||||
|
||||
def test_arrow(self):
|
||||
"""Test that the arrow image was set up properly."""
|
||||
self.assertIsInstance(self.button._arrow, Gtk.Image)
|
||||
self.assertEqual(self.button._arrow.get_icon_name(),
|
||||
"pan-down-symbolic")
|
||||
self.assertEqual(self.button._arrow.get_margin_top(), 6)
|
||||
self.assertEqual(self.button._overlay.get_child(), self.button._arrow)
|
||||
|
||||
def test_count(self):
|
||||
"""Test that the count label was set up properly."""
|
||||
self.assertIsInstance(self.button._count, Gtk.Label)
|
||||
self.assertEqual(self.button._count.get_yalign(), 0)
|
||||
self.assertEqual(self.button._count.get_halign(), Gtk.Align.CENTER)
|
||||
self.assertEqual(self.button._count.get_margin_top(), 3)
|
||||
self.assertEqual(self.button._count.get_text(), "")
|
||||
|
||||
def test_value(self):
|
||||
"""Test the value property."""
|
||||
self.assertEqual(self.button.value, -1)
|
||||
|
||||
self.button.value = 0
|
||||
self.assertEqual(self.button.popover_child.value, 0)
|
||||
self.assertEqual(self.button._count.get_text(), "0")
|
||||
|
||||
self.button.popover_child.value = 1
|
||||
self.assertEqual(self.button.value, 1)
|
||||
self.assertEqual(self.button._count.get_text(), "1")
|
||||
|
||||
self.button.value = -1
|
||||
self.assertEqual(self.button._count.get_text(), "")
|
||||
|
|
Loading…
Reference in New Issue