buttons: Give the SplitButton an activate() function
This is a keybinding function that calls into the primary button activate() function. At the same time, I add an "activate-primary" signal that is emitted when the primary button is activated. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0c1e5fcace
commit
41cb325ad0
|
@ -59,6 +59,7 @@ class SplitButton(Gtk.Box):
|
|||
|
||||
self.bind_property("icon-name", self._primary, "icon-name")
|
||||
self.bind_property("icon-size", self._primary, "icon-size")
|
||||
self._primary.connect("activate", self.__activate)
|
||||
self._primary.connect("clicked", self.__clicked)
|
||||
|
||||
self.append(self._primary)
|
||||
|
@ -67,14 +68,24 @@ class SplitButton(Gtk.Box):
|
|||
|
||||
self.add_css_class("emmental-splitbutton")
|
||||
|
||||
def __activate(self, button: Button) -> None:
|
||||
self.emit("activate-primary")
|
||||
|
||||
def __clicked(self, button: Button) -> None:
|
||||
self.emit("clicked")
|
||||
|
||||
def activate(self, *args) -> None:
|
||||
self._primary.activate()
|
||||
|
||||
@GObject.Property(type=Gtk.Button, flags=GObject.ParamFlags.READABLE)
|
||||
def secondary(self) -> Gtk.Button:
|
||||
"""Get the secondary button attached to the SplitButton."""
|
||||
return self._secondary
|
||||
|
||||
@GObject.Signal
|
||||
def activate_primary(self) -> None:
|
||||
"""Signal that the primary button has been activated."""
|
||||
|
||||
@GObject.Signal
|
||||
def clicked(self) -> None:
|
||||
"""Signal that the primary button has been clicked."""
|
||||
|
|
|
@ -148,6 +148,18 @@ class TestSplitButton(unittest.TestCase):
|
|||
self.button._primary.emit("clicked")
|
||||
on_click.assert_called_with(self.button)
|
||||
|
||||
def test_activate(self):
|
||||
"""Test the activate function."""
|
||||
activate = unittest.mock.Mock()
|
||||
primary = unittest.mock.Mock()
|
||||
|
||||
self.button.connect("activate-primary", primary)
|
||||
self.button._primary.connect("activate", activate)
|
||||
|
||||
self.button.activate()
|
||||
activate.assert_called()
|
||||
primary.assert_called()
|
||||
|
||||
|
||||
class TestImageToggle(unittest.TestCase):
|
||||
"""Test an ImageToggle button."""
|
||||
|
|
Loading…
Reference in New Issue