diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2021-09-19 16:52:15 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2021-09-19 16:52:15 +0200 |
commit | db472c14416da879fdd1ba685928be9b7c919e57 (patch) | |
tree | efb680b080c994093977c610dc7eac2969a27fcd | |
parent | 993ae903b421b34ebb880fc8e1973a4607e61298 (diff) | |
download | pygobject-db472c14416da879fdd1ba685928be9b7c919e57.tar.gz |
gtk overrides: restore Gtk.ListStore.insert_with_valuesv with newer gtk4
It got renamed in gtk 4.1.0, see https://gitlab.gnome.org/GNOME/gtk/-/commit/a1216599ff6b39bca3e936fbf
To avoid an API break and make porting easier provide both versions for
all users.
Fixes #467
-rw-r--r-- | gi/overrides/Gtk.py | 9 | ||||
-rw-r--r-- | tests/test_docstring.py | 5 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 14 |
3 files changed, 25 insertions, 3 deletions
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index 7739751e..f53ec6bd 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -995,10 +995,17 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable): Gtk.ListStore.__init__(self) self.set_column_types(column_types) + # insert_with_valuesv got renamed to insert_with_values with 4.1.0 + # https://gitlab.gnome.org/GNOME/gtk/-/commit/a1216599ff6b39bca3e9 + if not hasattr(Gtk.ListStore, "insert_with_valuesv"): + insert_with_valuesv = Gtk.ListStore.insert_with_values + elif not hasattr(Gtk.ListStore, "insert_with_values"): + insert_with_values = Gtk.ListStore.insert_with_valuesv + def _do_insert(self, position, row): if row is not None: row, columns = self._convert_row(row) - treeiter = self.insert_with_valuesv(position, columns, row) + treeiter = self.insert_with_values(position, columns, row) else: treeiter = Gtk.ListStore.insert(self, position) diff --git a/tests/test_docstring.py b/tests/test_docstring.py index 29b7e5ef..49d030f5 100644 --- a/tests/test_docstring.py +++ b/tests/test_docstring.py @@ -93,8 +93,9 @@ class Test(unittest.TestCase): @unittest.skipUnless(Gtk, 'no Gtk') def test_shared_array_length_with_prior_out_arg(self): # Test the 'iter' out argument does not effect length argument skipping. - self.assertEqual(Gtk.ListStore.insert_with_valuesv.__doc__, - 'insert_with_valuesv(self, position:int, columns:list, values:list) -> iter:Gtk.TreeIter') + self.assertRegex( + Gtk.ListStore.insert_with_valuesv.__doc__, + 'insert_with_values.*\\(self, position:int, columns:list, values:list\\) -> iter:Gtk.TreeIter') def test_sub_class_doc(self): class A(GObject.Object): diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 72fd2c8e..6bd2345a 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -1377,6 +1377,20 @@ class TestCustomSorter(): assert result.props.name == member +@unittest.skipUnless(Gtk, 'Gtk not available') +class TestListStore(unittest.TestCase): + + def test_insert_with_values(self): + model = Gtk.ListStore(int) + assert hasattr(model, 'insert_with_values') + iter_ = model.insert_with_values(0, (0,), [42]) + assert isinstance(iter_, Gtk.TreeIter) + assert hasattr(model, 'insert_with_valuesv') + iter_ = model.insert_with_valuesv(0, (0,), [43]) + assert isinstance(iter_, Gtk.TreeIter) + assert len(model) == 2 + + @ignore_gi_deprecation_warnings @unittest.skipUnless(Gtk, 'Gtk not available') class TestTreeModel(unittest.TestCase): |