diff --git a/emmental/buttons.py b/emmental/buttons.py index b455477..19cba81 100644 --- a/emmental/buttons.py +++ b/emmental/buttons.py @@ -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.""" diff --git a/tests/test_buttons.py b/tests/test_buttons.py index 6d64572..3904c9b 100644 --- a/tests/test_buttons.py +++ b/tests/test_buttons.py @@ -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."""