[pygobject] Drop set_value usage in Gtk.List/TreeStore.set override
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Drop set_value usage in Gtk.List/TreeStore.set override
- Date: Thu, 16 Nov 2017 17:42:44 +0000 (UTC)
commit bd165405754ba44dea12fd3f31b841b5c8ba0f1a
Author: Sander Sweers <infirit gmail com>
Date: Sun Aug 20 22:44:15 2017 +0200
Drop set_value usage in Gtk.List/TreeStore.set override
this causes multiple updates to the store each emitting a signal.
https://bugzilla.gnome.org/show_bug.cgi?id=790346
gi/overrides/Gtk.py | 48 +++++++++++++++++++++++-------------------
tests/test_overrides_gtk.py | 12 ++++++++++
2 files changed, 38 insertions(+), 22 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 08d2612..90c9d30 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1007,28 +1007,30 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
Gtk.ListStore.set_value(self, treeiter, column, value)
def set(self, treeiter, *args):
-
- def _set_lists(columns, values):
- if len(columns) != len(values):
+ def _set_lists(cols, vals):
+ if len(cols) != len(vals):
raise TypeError('The number of columns do not match the number of values')
- for col_num, val in zip(columns, values):
+
+ columns = []
+ values = []
+ for col_num, value in zip(cols, vals):
if not isinstance(col_num, int):
raise TypeError('TypeError: Expected integer argument for column.')
- self.set_value(treeiter, col_num, val)
+
+ columns.append(col_num)
+ values.append(self._convert_value(col_num, value))
+
+ Gtk.ListStore.set(self, treeiter, columns, values)
if args:
if isinstance(args[0], int):
- columns = args[::2]
- values = args[1::2]
- _set_lists(columns, values)
+ _set_lists(args[::2], args[1::2])
elif isinstance(args[0], (tuple, list)):
if len(args) != 2:
raise TypeError('Too many arguments')
_set_lists(args[0], args[1])
elif isinstance(args[0], dict):
- columns = args[0].keys()
- values = args[0].values()
- _set_lists(columns, values)
+ _set_lists(list(args[0]), args[0].values())
else:
raise TypeError('Argument list must be in the form of (column, value, ...), ((columns,...),
(values, ...)) or {column: value}. No -1 termination is needed.')
@@ -1269,28 +1271,30 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
Gtk.TreeStore.set_value(self, treeiter, column, value)
def set(self, treeiter, *args):
-
- def _set_lists(columns, values):
- if len(columns) != len(values):
+ def _set_lists(cols, vals):
+ if len(cols) != len(vals):
raise TypeError('The number of columns do not match the number of values')
- for col_num, val in zip(columns, values):
+
+ columns = []
+ values = []
+ for col_num, value in zip(cols, vals):
if not isinstance(col_num, int):
raise TypeError('TypeError: Expected integer argument for column.')
- self.set_value(treeiter, col_num, val)
+
+ columns.append(col_num)
+ values.append(self._convert_value(col_num, value))
+
+ Gtk.TreeStore.set(self, treeiter, columns, values)
if args:
if isinstance(args[0], int):
- columns = args[::2]
- values = args[1::2]
- _set_lists(columns, values)
+ _set_lists(args[::2], args[1::2])
elif isinstance(args[0], (tuple, list)):
if len(args) != 2:
raise TypeError('Too many arguments')
_set_lists(args[0], args[1])
elif isinstance(args[0], dict):
- columns = args[0].keys()
- values = args[0].values()
- _set_lists(columns, values)
+ _set_lists(args[0].keys(), args[0].values())
else:
raise TypeError('Argument list must be in the form of (column, value, ...), ((columns,...),
(values, ...)) or {column: value}. No -1 termination is needed.')
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index 61b7dc0..769e439 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1080,6 +1080,12 @@ class TestTreeModel(unittest.TestCase):
tree_store.insert(None, 1)
self.assertEqual(signals, ['row-inserted'])
+ # One set one signal
+ signals.pop()
+ tree_iter = tree_store.append(None, (10, False))
+ tree_store.set(tree_iter, (0, 1), (20, True))
+ self.assertEqual(signals, ['row-inserted', 'row-changed'])
+
def test_list_store(self):
class TestPyObject(object):
pass
@@ -1337,6 +1343,12 @@ class TestTreeModel(unittest.TestCase):
list_store.insert(1)
self.assertEqual(signals, ['row-inserted'])
+ # One set one signal
+ signals.pop()
+ tree_iter = list_store.append((10, False))
+ list_store.set(tree_iter, (0, 1), (20, True))
+ self.assertEqual(signals, ['row-inserted', 'row-changed'])
+
def test_tree_path(self):
p1 = Gtk.TreePath()
p2 = Gtk.TreePath.new_first()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]