Imported Upstream version 3.36.1 upstream/3.36.1
authorDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 25 Nov 2020 05:49:16 +0000 (14:49 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Wed, 25 Nov 2020 05:49:16 +0000 (14:49 +0900)
.gitlab-ci.yml
NEWS
gi/_gtktemplate.py
gi/gimodule.c
gi/overrides/Gtk.py
meson.build
setup.py
tests/test_glib.py
tests/test_gtk_template.py
tests/test_overrides_gtk.py

index f93d384..fb5bfea 100644 (file)
@@ -20,7 +20,7 @@ cache:
 .mingw-defaults: &mingw-defaults
   stage: build_and_test
   tags:
-    - win32
+    - win32-ps
   artifacts:
     paths:
       - coverage/
diff --git a/NEWS b/NEWS
index 552738b..0a5e423 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+3.36.1 - 2020-05-06
+-------------------
+
+* tests: Fix failing tests with pytest 5.4.0+
+* Gtk: Add override to make sure both TreeModelSort.new_with_model and
+  TreeModel.sort_new_with_model exist independend of the gtk version
+* Gtk.Template: Fix initialisation order errors with Widgets getting created from C
+  (potentially through other templates) :issue:`257` :issue:`386` :issue:`341` :mr:`140` (:user:`Jean Felder <jfelder>`)
+* Gtk.Template: Fix errors when calling init_template() multiple times :mr:`140` (:user:`Jean Felder <jfelder>`)
+
+
 3.36.0 - 2020-03-08
 -------------------
 
index efaca33..4b80106 100644 (file)
@@ -99,7 +99,7 @@ def register_template(cls):
 
 
 def init_template(self, cls, base_init_template):
-    self.init_template = lambda s: None
+    self.init_template = lambda: None
 
     if self.__class__ is not cls:
         raise TypeError(
index cf3c5ea..a63237d 100644 (file)
@@ -1070,6 +1070,7 @@ pygobject__g_instance_init(GTypeInstance   *instance,
     GObject *object = (GObject *) instance;
     PyObject *wrapper, *result;
     PyGILState_STATE state;
+    gboolean needs_init = FALSE;
 
     wrapper = g_object_get_qdata(object, pygobject_wrapper_key);
     if (wrapper == NULL) {
@@ -1096,16 +1097,20 @@ pygobject__g_instance_init(GTypeInstance   *instance,
          * will take the ref */
         pygobject_ref_float ((PyGObject *) wrapper);
 
-        result = PyObject_CallMethod (wrapper, "__init__", NULL);
+        needs_init = TRUE;
+    }
+
+    /* XXX: used for Gtk.Template */
+    if (PyObject_HasAttrString ((PyObject*) Py_TYPE (wrapper), "__dontuse_ginstance_init__")) {
+        result = PyObject_CallMethod (wrapper, "__dontuse_ginstance_init__", NULL);
         if (result == NULL)
             PyErr_Print ();
         else
             Py_DECREF (result);
     }
 
-    /* XXX: used for Gtk.Template */
-    if (PyObject_HasAttrString ((PyObject*) Py_TYPE (wrapper), "__dontuse_ginstance_init__")) {
-        result = PyObject_CallMethod (wrapper, "__dontuse_ginstance_init__", NULL);
+    if (needs_init) {
+        result = PyObject_CallMethod (wrapper, "__init__", NULL);
         if (result == NULL)
             PyErr_Print ();
         else
index 834f5eb..9453805 100644 (file)
@@ -834,6 +834,13 @@ class TreeModel(Gtk.TreeModel):
                 raise IndexError("could not find tree path '%s'" % key)
             return aiter
 
+    def sort_new_with_model(self):
+        super_object = super(TreeModel, self)
+        if hasattr(super_object, "sort_new_with_model"):
+            return super_object.sort_new_with_model()
+        else:
+            return TreeModelSort.new_with_model(self)
+
     def _coerce_path(self, path):
         if isinstance(path, Gtk.TreePath):
             return path
@@ -973,6 +980,11 @@ class TreeModelSort(Gtk.TreeModelSort):
                                arg_names=('model',),
                                category=PyGTKDeprecationWarning)
 
+    if not hasattr(Gtk.TreeModelSort, "new_with_model"):
+        @classmethod
+        def new_with_model(self, child_model):
+            return TreeModel.sort_new_with_model(child_model)
+
 
 TreeModelSort = override(TreeModelSort)
 __all__.append('TreeModelSort')
index 006fee4..4e59729 100644 (file)
@@ -1,5 +1,5 @@
 project('pygobject', 'c',
-  version : '3.36.0',
+  version : '3.36.1',
   meson_version : '>= 0.46.0',
   default_options : [ 'warning_level=1',
                       'buildtype=debugoptimized'])
index 19b8cfa..8a35829 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -41,7 +41,7 @@ from distutils import dir_util, log
 from distutils.spawn import find_executable
 
 
-PYGOBJECT_VERSION = "3.36.0"
+PYGOBJECT_VERSION = "3.36.1"
 GLIB_VERSION_REQUIRED = "2.48.0"
 GI_VERSION_REQUIRED = "1.46.0"
 PYCAIRO_VERSION_REQUIRED = "1.11.1"
index 565a872..70be98e 100644 (file)
@@ -18,7 +18,7 @@ from gi._compat import PY3
 
 class TestGLib(unittest.TestCase):
 
-    @pytest.mark.xfail(strict=True)
+    @pytest.mark.xfail()
     def test_pytest_capture_error_in_closure(self):
         # this test is supposed to fail
         ml = GLib.MainLoop()
index 3a1c1f0..db3c8d9 100644 (file)
@@ -590,3 +590,103 @@ def test_internal_child():
     child = child.get_children()[0]
     assert isinstance(child, Gtk.Label)
     assert child.props.label == "foo"
+
+
+def test_template_hierarchy():
+    testlabel = """
+    <interface>
+      <template class="TestLabel" parent="GtkLabel">
+      </template>
+     </interface>
+    """
+    @Gtk.Template(string=testlabel)
+    class TestLabel(Gtk.Label):
+
+        __gtype_name__ = "TestLabel"
+
+        def __init__(self):
+            super(TestLabel, self).__init__()
+            self.props.label = "TestLabel"
+
+    testbox = """
+    <interface>
+      <template class="TestBox" parent="GtkBox">
+        <child>
+          <object class="TestLabel" id="_testlabel"/>
+        </child>
+      </template>
+    </interface>
+    """
+    @Gtk.Template(string=testbox)
+    class TestBox(Gtk.Box):
+
+        __gtype_name__ = "TestBox"
+
+        _testlabel = Gtk.Template.Child()
+
+        def __init__(self):
+            super(TestBox, self).__init__()
+
+            assert isinstance(self._testlabel, TestLabel)
+
+    window = """
+    <interface>
+      <template class="MyWindow" parent="GtkWindow">
+        <property name="title">"Hellow World"</property>
+        <child>
+          <object class="TestBox" id="_testbox">
+            <child>
+              <object class="TestLabel" id="_testlabel"/>
+            </child>
+          </object>
+        </child>
+      </template>
+    </interface>
+    """
+    @Gtk.Template(string=window)
+    class MyWindow(Gtk.Window):
+
+        __gtype_name__ = "MyWindow"
+
+        _testbox = Gtk.Template.Child()
+        _testlabel = Gtk.Template.Child()
+
+        def __init__(self):
+            super(MyWindow, self).__init__()
+
+            assert isinstance(self._testbox, TestBox)
+            assert isinstance(self._testlabel, TestLabel)
+            assert len(self._testbox.get_children()) == 2
+
+    win = MyWindow()
+    assert isinstance(win, MyWindow)
+
+
+def test_multiple_init_template_calls():
+    xml = """
+    <interface>
+      <template class="MyBox" parent="GtkBox">
+        <child>
+          <object class="GtkLabel" id="_label"/>
+        </child>
+       </template>
+     </interface>
+    """
+    @Gtk.Template(string=xml)
+    class MyBox(Gtk.Box):
+
+        __gtype_name__ = "MyBox"
+
+        _label = Gtk.Template.Child()
+
+        def __init__(self):
+            super(MyBox, self).__init__()
+            self._label.props.label = "awesome label"
+
+    my_box = MyBox()
+    assert isinstance(my_box, MyBox)
+    assert len(my_box.get_children()) == 1
+
+    my_box.init_template()
+    assert isinstance(my_box, MyBox)
+    assert len(my_box.get_children()) == 1
index 9c32e8b..88b3f88 100644 (file)
@@ -1148,6 +1148,21 @@ class TestTreeModelRow(unittest.TestCase):
 @ignore_gi_deprecation_warnings
 @unittest.skipUnless(Gtk, 'Gtk not available')
 class TestTreeModel(unittest.TestCase):
+
+    def test_tree_model_sort_new_with_model_old(self):
+        # https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1134
+        model = Gtk.TreeStore(int)
+        sort_model = model.sort_new_with_model()
+        assert isinstance(sort_model, Gtk.TreeModelSort)
+        assert sort_model.get_model() == model
+
+    def test_tree_model_sort_new_with_model_new(self):
+        # https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1134
+        model = Gtk.TreeStore(int)
+        sort_model = Gtk.TreeModelSort.new_with_model(child_model=model)
+        assert isinstance(sort_model, Gtk.TreeModelSort)
+        assert sort_model.get_model() == model
+
     def test_tree_model_sort(self):
         self.assertEqual(Gtk.TreeModelSort, gi.overrides.Gtk.TreeModelSort)
         model = Gtk.TreeStore(int, bool)