[pygobject] Make Gtk.List/TreeStore.insert_before/after atomic
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Make Gtk.List/TreeStore.insert_before/after atomic
- Date: Tue, 27 Mar 2018 13:18:55 +0000 (UTC)
commit 908d099c600a622f85abe452bd10968fb4a15e3d
Author: Christoph Reiter <reiter christoph gmail com>
Date: Tue Mar 27 14:40:36 2018 +0200
Make Gtk.List/TreeStore.insert_before/after atomic
Instead of adding a row and then setting the values do it in one
go using insert_with_values().
This gets rid of a row-changed signal and things like cellrenderers
don't have to deal with potentially empty rows. It's also a bit faster.
gi/overrides/Gtk.py | 52 +++++++++++++++++++++------------------------
tests/test_overrides_gtk.py | 16 +++++++-------
2 files changed, 32 insertions(+), 36 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 71001832..40ccf090 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -986,27 +986,25 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
def insert(self, position, row=None):
return self._do_insert(position, row)
- # FIXME: sends two signals; check if this can use an atomic
- # insert_with_valuesv()
-
def insert_before(self, sibling, row=None):
- treeiter = Gtk.ListStore.insert_before(self, sibling)
-
if row is not None:
- self.set_row(treeiter, row)
-
- return treeiter
+ if sibling is None:
+ position = -1
+ else:
+ position = self.get_path(sibling).get_indices()[-1]
+ return self._do_insert(position, row)
- # FIXME: sends two signals; check if this can use an atomic
- # insert_with_valuesv()
+ return Gtk.ListStore.insert_before(self, sibling)
def insert_after(self, sibling, row=None):
- treeiter = Gtk.ListStore.insert_after(self, sibling)
-
if row is not None:
- self.set_row(treeiter, row)
+ if sibling is None:
+ position = 0
+ else:
+ position = self.get_path(sibling).get_indices()[-1] + 1
+ return self._do_insert(position, row)
- return treeiter
+ return Gtk.ListStore.insert_after(self, sibling)
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value)
@@ -1250,27 +1248,25 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
def insert(self, parent, position, row=None):
return self._do_insert(parent, position, row)
- # FIXME: sends two signals; check if this can use an atomic
- # insert_with_valuesv()
-
def insert_before(self, parent, sibling, row=None):
- treeiter = Gtk.TreeStore.insert_before(self, parent, sibling)
-
if row is not None:
- self.set_row(treeiter, row)
-
- return treeiter
+ if sibling is None:
+ position = -1
+ else:
+ position = self.get_path(sibling).get_indices()[-1]
+ return self._do_insert(parent, position, row)
- # FIXME: sends two signals; check if this can use an atomic
- # insert_with_valuesv()
+ return Gtk.TreeStore.insert_before(self, parent, sibling)
def insert_after(self, parent, sibling, row=None):
- treeiter = Gtk.TreeStore.insert_after(self, parent, sibling)
-
if row is not None:
- self.set_row(treeiter, row)
+ if sibling is None:
+ position = 0
+ else:
+ position = self.get_path(sibling).get_indices()[-1] + 1
+ return self._do_insert(parent, position, row)
- return treeiter
+ return Gtk.TreeStore.insert_after(self, parent, sibling)
def set_value(self, treeiter, column, value):
value = self._convert_value(column, value)
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 526632db..0a1d08fd 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1404,14 +1404,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_before(None, [1234])
assert store.get_path(iter_).get_indices() == [3]
assert store.get_value(iter_, 0) == 1234
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_before(iter_, [4321])
assert store.get_path(iter_).get_indices() == [3]
assert store.get_value(iter_, 0) == 4321
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
assert [r[0] for r in store] == [0, None, None, 4321, 1234]
@@ -1452,14 +1452,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_after(None, [1234])
assert store.get_path(iter_).get_indices() == [0]
assert store.get_value(iter_, 0) == 1234
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_after(iter_, [4321])
assert store.get_path(iter_).get_indices() == [1]
assert store.get_value(iter_, 0) == 4321
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
assert [r[0] for r in store] == [1234, 4321, None, None, 0]
@@ -1505,14 +1505,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_before(parent, None, [1234])
assert store.get_path(iter_).get_indices() == [0, 3]
assert store.get_value(iter_, 0) == 1234
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_before(parent, iter_, [4321])
assert store.get_path(iter_).get_indices() == [0, 3]
assert store.get_value(iter_, 0) == 4321
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
def func(model, path, iter_, rows):
@@ -1565,14 +1565,14 @@ class TestTreeModel(unittest.TestCase):
iter_ = store.insert_after(parent, None, [1234])
assert store.get_path(iter_).get_indices() == [0, 0]
assert store.get_value(iter_, 0) == 1234
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
# insert non-empty
iter_ = store.insert_after(parent, iter_, [4321])
assert store.get_path(iter_).get_indices() == [0, 1]
assert store.get_value(iter_, 0) == 4321
- assert signals == ['row-inserted', 'row-changed']
+ assert signals == ['row-inserted']
del signals[:]
def func(model, path, iter_, rows):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]