diff options
-rw-r--r-- | gi/overrides/Gtk.py | 21 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 14 |
2 files changed, 24 insertions, 11 deletions
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index 55cd0fca..2c8e1efb 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -152,16 +152,17 @@ class Widget(Gtk.Widget): target_list = Gtk.TargetList.new(_construct_target_list(target_list)) super(Widget, self).drag_source_set_target_list(target_list) - def style_get_property(self, property_name, value=None): - if value is None: - prop = self.find_style_property(property_name) - if prop is None: - raise ValueError('Class "%s" does not contain style property "%s"' % - (self, property_name)) - value = GObject.Value(prop.value_type) - - Gtk.Widget.style_get_property(self, property_name, value) - return value.get_value() + if GTK2 or GTK3: + def style_get_property(self, property_name, value=None): + if value is None: + prop = self.find_style_property(property_name) + if prop is None: + raise ValueError('Class "%s" does not contain style property "%s"' % + (self, property_name)) + value = GObject.Value(prop.value_type) + + Gtk.Widget.style_get_property(self, property_name, value) + return value.get_value() Widget = override(Widget) diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 5f5521e6..bb458cc4 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -902,8 +902,8 @@ class TestGtk(unittest.TestCase): @unittest.skipUnless(Gtk, 'Gtk not available') -@unittest.skipIf(Gtk_version == "4.0", "not in gtk4") class TestWidget(unittest.TestCase): + @unittest.skipIf(Gtk_version == "4.0", "not in gtk4") def test_style_get_property_gvalue(self): button = Gtk.Button() value = GObject.Value(int, -42) @@ -912,6 +912,7 @@ class TestWidget(unittest.TestCase): # set it. self.assertNotEqual(value.get_int(), -42) + @unittest.skipIf(Gtk_version == "4.0", "not in gtk4") def test_style_get_property_return_with_explicit_gvalue(self): button = Gtk.Button() value = GObject.Value(int, -42) @@ -919,17 +920,28 @@ class TestWidget(unittest.TestCase): self.assertIsInstance(result, int) self.assertNotEqual(result, -42) + @unittest.skipIf(Gtk_version == "4.0", "not in gtk4") def test_style_get_property_return_with_implicit_gvalue(self): button = Gtk.Button() result = button.style_get_property('focus-padding') self.assertIsInstance(result, int) self.assertNotEqual(result, -42) + @unittest.skipIf(Gtk_version == "4.0", "not in gtk4") def test_style_get_property_error(self): button = Gtk.Button() with self.assertRaises(ValueError): button.style_get_property('not-a-valid-style-property') + @unittest.skipIf(Gtk_version != "4.0", "only in gtk4") + def test_translate_coordinates(self): + box = Gtk.Box() + child = Gtk.Button() + box.append(child) + with realized(box): + assert box.translate_coordinates(child, 42, 24) == (42.0, 24.0) + assert box.translate_coordinates(Gtk.Button(), 0, 0) is None + @unittest.skipIf(sys.platform == "darwin", "hangs") @unittest.skipUnless(Gtk, 'Gtk not available') |