[pygobject] get/set_focus_on_click: Fix return value, add a test and document why the override is there



commit 1a2bc1d0806ab6178f65125bf0b2283eb3378d4d
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Apr 17 18:16:54 2020 +0200

    get/set_focus_on_click: Fix return value, add a test and document why the override is there
    
    Also make it conditional on the Gtk.Widget method existing since that was only
    added with gtk 3.20 and we support 3.18+.

 gi/overrides/Gtk.py         | 20 +++++++++++---------
 tests/test_overrides_gtk.py |  8 ++++++++
 2 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index b797cf8c..64a5088e 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1460,15 +1460,17 @@ class Button(Gtk.Button, Container):
         else:
             self._init(*args, **kwargs)
 
-    def set_focus_on_click(self, focus_on_click):
-        # Gtk.Button.set_focus_on_click is deprecated since version 3.20
-        # Use Gtk.Widget.set_focus_on_click instead
-        Gtk.Widget.set_focus_on_click(self, focus_on_click)
-
-    def get_focus_on_click(self):
-        # Gtk.Button.get_focus_on_click is deprecated since version 3.20
-        # Use Gtk.Widget.get_focus_on_click instead
-        Gtk.Widget.get_focus_on_click(self)
+    if hasattr(Gtk.Widget, "set_focus_on_click"):
+        def set_focus_on_click(self, *args, **kwargs):
+            # Gtk.Widget.set_focus_on_click should be used instead but it's
+            # no obvious how because of the shadowed method, so override here
+            return Gtk.Widget.set_focus_on_click(self, *args, **kwargs)
+
+    if hasattr(Gtk.Widget, "get_focus_on_click"):
+        def get_focus_on_click(self, *args, **kwargs):
+            # Gtk.Widget.get_focus_on_click should be used instead but it's
+            # no obvious how because of the shadowed method, so override here
+            return Gtk.Widget.get_focus_on_click(self, *args, **kwargs)
 
 
 Button = override(Button)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 8ed9775e..ff3acba9 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -2793,3 +2793,11 @@ class TestContainer(unittest.TestCase):
         self.assertEqual(expand, False)
         self.assertEqual(fill, False)
         self.assertEqual(padding, 21)
+
+
+def test_button_focus_on_click():
+    b = Gtk.Button()
+    b.set_focus_on_click(True)
+    assert b.get_focus_on_click()
+    b.set_focus_on_click(False)
+    assert not b.get_focus_on_click()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]