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-name", self._primary, "icon-name")
|
||||||
self.bind_property("icon-size", self._primary, "icon-size")
|
self.bind_property("icon-size", self._primary, "icon-size")
|
||||||
|
self._primary.connect("activate", self.__activate)
|
||||||
self._primary.connect("clicked", self.__clicked)
|
self._primary.connect("clicked", self.__clicked)
|
||||||
|
|
||||||
self.append(self._primary)
|
self.append(self._primary)
|
||||||
|
@ -67,14 +68,24 @@ class SplitButton(Gtk.Box):
|
||||||
|
|
||||||
self.add_css_class("emmental-splitbutton")
|
self.add_css_class("emmental-splitbutton")
|
||||||
|
|
||||||
|
def __activate(self, button: Button) -> None:
|
||||||
|
self.emit("activate-primary")
|
||||||
|
|
||||||
def __clicked(self, button: Button) -> None:
|
def __clicked(self, button: Button) -> None:
|
||||||
self.emit("clicked")
|
self.emit("clicked")
|
||||||
|
|
||||||
|
def activate(self, *args) -> None:
|
||||||
|
self._primary.activate()
|
||||||
|
|
||||||
@GObject.Property(type=Gtk.Button, flags=GObject.ParamFlags.READABLE)
|
@GObject.Property(type=Gtk.Button, flags=GObject.ParamFlags.READABLE)
|
||||||
def secondary(self) -> Gtk.Button:
|
def secondary(self) -> Gtk.Button:
|
||||||
"""Get the secondary button attached to the SplitButton."""
|
"""Get the secondary button attached to the SplitButton."""
|
||||||
return self._secondary
|
return self._secondary
|
||||||
|
|
||||||
|
@GObject.Signal
|
||||||
|
def activate_primary(self) -> None:
|
||||||
|
"""Signal that the primary button has been activated."""
|
||||||
|
|
||||||
@GObject.Signal
|
@GObject.Signal
|
||||||
def clicked(self) -> None:
|
def clicked(self) -> None:
|
||||||
"""Signal that the primary button has been clicked."""
|
"""Signal that the primary button has been clicked."""
|
||||||
|
|
|
@ -148,6 +148,18 @@ class TestSplitButton(unittest.TestCase):
|
||||||
self.button._primary.emit("clicked")
|
self.button._primary.emit("clicked")
|
||||||
on_click.assert_called_with(self.button)
|
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):
|
class TestImageToggle(unittest.TestCase):
|
||||||
"""Test an ImageToggle button."""
|
"""Test an ImageToggle button."""
|
||||||
|
|
Loading…
Reference in New Issue