xfstestsdb/tests/gtk/test_button.py
Anna Schumaker 37079ca7f5 gtk: Add a custom StatusToggle button
This is a Gtk.Button that has been customized to act similarily to a
Gtk.ToggleButton, but instead of giving the button a "pressed in" look
it changes the opacity of the displayed icon.

I'm planning to use this in the window headerbar in a set of buttons
designed to controll testcase filter state.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
2023-08-14 13:35:01 -04:00

52 lines
2.0 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""Tests our custom button classes."""
import unittest
import xfstestsdb.gtk.button
from gi.repository import Gtk
class TestStatusToggle(unittest.TestCase):
"""Test our StatusToggle button."""
def setUp(self):
"""Set up common variables."""
self.button = xfstestsdb.gtk.button.StatusToggle("icon-name",
"css-class")
def test_button(self):
"""Test the StatusToggle button."""
self.assertIsInstance(self.button, Gtk.Button)
self.assertEqual(self.button.icon_name, "icon-name")
self.assertTrue(self.button.has_css_class("css-class"))
self.assertFalse(self.button.props.has_frame)
self.assertFalse(self.button.active)
button2 = xfstestsdb.gtk.button.StatusToggle("icon-name", "css-class",
active=True)
self.assertTrue(button2.active)
self.assertAlmostEqual(button2.props.child.props.opacity, 1.0)
def test_image(self):
"""Test that the image is set up correctly, and opacity changes."""
self.assertIsInstance(self.button.props.child, Gtk.Image)
self.assertEqual(self.button.props.child.props.icon_name, "icon-name")
self.button.active = True
self.assertAlmostEqual(self.button.props.child.props.opacity, 1.0)
self.button.active = False
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)
def test_clicked(self):
"""Test clicking the CSSToggle button."""
self.assertFalse(self.button.active)
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)
self.button.emit("clicked")
self.assertTrue(self.button.active)
self.assertAlmostEqual(self.button.props.child.props.opacity, 1.0)
self.button.emit("clicked")
self.assertFalse(self.button.active)
self.assertAlmostEqual(self.button.props.child.props.opacity, 0.4)