[pygobject] overrides: Fix Gtk.Adjustment.__init__ overrides not setting "value" sometimes. Fixes #151



commit e5a21f56cd375373741dcb2f2e8eefae349cffbc
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Mon Jan 15 20:44:27 2018 +0100

    overrides: Fix Gtk.Adjustment.__init__ overrides not setting "value" sometimes. Fixes #151
    
    Gtk.Adjustment allows passing positional arguments to __init__ which get
    translated to a dict for passing to GObject.Object.__init__. In case of the
    first argument "value", if "value" is passed before the upper and
    lower bound to Object.__init__ it will be set to 0 instead.
    
    In Python 2 this happened to work (at least on my machine) because
    "value" got placed after the bounds (in terms of iteration order)
    in the final dict value passed to Object.__init__.
    
    To work around this, set "value" again after __init__().
    A similar work around already exists when "value" is passed as a kwarg.

 gi/overrides/Gtk.py         | 2 ++
 tests/test_overrides_gtk.py | 6 ++++++
 2 files changed, 8 insertions(+)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index c495fd1d..37092448 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1475,6 +1475,8 @@ class Adjustment(Gtk.Adjustment):
         # was set, we set it again here.
         if 'value' in kwargs:
             self.set_value(kwargs['value'])
+        elif len(args) >= 1:
+            self.set_value(args[0])
 
 
 Adjustment = override(Adjustment)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 769e439c..f20ca4fd 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -463,6 +463,12 @@ class TestGtk(unittest.TestCase):
         adjustment = Gtk.Adjustment()
         self.adjustment_check(adjustment)
 
+        adjustment = Gtk.Adjustment(1, -1, 3, 0, 0, 0)
+        self.adjustment_check(adjustment, value=1, lower=-1, upper=3)
+
+        adjustment = Gtk.Adjustment(1, -1, 3, 0, 0, 0, value=2)
+        self.adjustment_check(adjustment, value=2, lower=-1, upper=3)
+
     @unittest.skipIf(Gtk._version == "4.0", "not in gtk4")
     def test_table(self):
         table = Gtk.Table()


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