buttons: Watch for ImageToggle tooltip text changes

If the application changes the active or inactive tooltip text, then we
want to apply that to the button depending on what state it currently
has.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2023-08-22 13:26:18 -04:00
parent f7349cd864
commit eb6b4d8ef4
2 changed files with 18 additions and 0 deletions

View File

@ -119,6 +119,13 @@ class ImageToggle(Button):
inactive_tooltip_text=inactive_tooltip_text,
tooltip_text=inactive_tooltip_text,
active=active, **kwargs)
self.connect("notify", self.__notify)
def __notify(self, toggle: Button, param: GObject.ParamSpec) -> None:
match (param.name, self.active):
case ("active-tooltip-text", True) | \
("inactive-tooltip-text", False):
self.set_tooltip_text(self.get_property(param.name))
def do_clicked(self) -> None:
"""Handle a click event."""

View File

@ -211,6 +211,17 @@ class TestImageToggle(unittest.TestCase):
button2.active = False
self.assertEqual(button2.get_tooltip_text(), "inactive tooltip text")
def test_changing_tooltip_text(self):
"""Test changing the tooltip text for the current state."""
self.assertEqual(self.button.props.tooltip_text, None)
self.button.inactive_tooltip_text = "inactive tooltip"
self.assertEqual(self.button.props.tooltip_text, "inactive tooltip")
self.button.active = True
self.assertEqual(self.button.props.tooltip_text, None)
self.button.active_tooltip_text = "active tooltip"
self.assertEqual(self.button.props.tooltip_text, "active tooltip")
def test_toggle(self):
"""Test the toggle signal."""
toggled = unittest.mock.Mock()