summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2020-11-15 19:38:40 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2020-11-15 19:38:40 +0100
commit2ab352aa24f15ef3808416315720d376308775ba (patch)
tree5716c8b62e66951fb0f93a8d4c1dc9f34182d0bf
parentd6e029c5b8d15bf2a3c68668b43a08a00e46ea59 (diff)
downloadpygobject-2ab352aa24f15ef3808416315720d376308775ba.tar.gz
Clean up Widget overrides
-rw-r--r--gi/overrides/Gtk.py21
-rw-r--r--tests/test_overrides_gtk.py14
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')