[Python-checkins] cpython (merge 3.5 -> default): Issue #26386: Fixed ttk.TreeView selection operations with item id's
serhiy.storchaka
python-checkins at python.org
Tue Jun 14 05:46:44 EDT 2016
https://hg.python.org/cpython/rev/d1c0bc1d0625
changeset: 102020:d1c0bc1d0625
parent: 102017:c4dd384ee3fa
parent: 102019:0885477fecfd
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue Jun 14 12:39:18 2016 +0300
summary:
Issue #26386: Fixed ttk.TreeView selection operations with item id's
containing spaces.
files:
Lib/tkinter/test/test_ttk/test_widgets.py | 51 +++++++++++
Lib/tkinter/ttk.py | 4 +-
Misc/NEWS | 3 +
3 files changed, 57 insertions(+), 1 deletions(-)
diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py
--- a/Lib/tkinter/test/test_ttk/test_widgets.py
+++ b/Lib/tkinter/test/test_ttk/test_widgets.py
@@ -1486,6 +1486,57 @@
value)
+ def test_selection(self):
+ # item 'none' doesn't exist
+ self.assertRaises(tkinter.TclError, self.tv.selection_set, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_add, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_remove, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_toggle, 'none')
+
+ item1 = self.tv.insert('', 'end')
+ item2 = self.tv.insert('', 'end')
+ c1 = self.tv.insert(item1, 'end')
+ c2 = self.tv.insert(item1, 'end')
+ c3 = self.tv.insert(item1, 'end')
+ self.assertEqual(self.tv.selection(), ())
+
+ self.tv.selection_set((c1, item2))
+ self.assertEqual(self.tv.selection(), (c1, item2))
+ self.tv.selection_set(c2)
+ self.assertEqual(self.tv.selection(), (c2,))
+
+ self.tv.selection_add((c1, item2))
+ self.assertEqual(self.tv.selection(), (c1, c2, item2))
+ self.tv.selection_add(item1)
+ self.assertEqual(self.tv.selection(), (item1, c1, c2, item2))
+
+ self.tv.selection_remove((item1, c3))
+ self.assertEqual(self.tv.selection(), (c1, c2, item2))
+ self.tv.selection_remove(c2)
+ self.assertEqual(self.tv.selection(), (c1, item2))
+
+ self.tv.selection_toggle((c1, c3))
+ self.assertEqual(self.tv.selection(), (c3, item2))
+ self.tv.selection_toggle(item2)
+ self.assertEqual(self.tv.selection(), (c3,))
+
+ self.tv.insert('', 'end', id='with spaces')
+ self.tv.selection_set('with spaces')
+ self.assertEqual(self.tv.selection(), ('with spaces',))
+
+ self.tv.insert('', 'end', id='{brace')
+ self.tv.selection_set('{brace')
+ self.assertEqual(self.tv.selection(), ('{brace',))
+
+ self.tv.insert('', 'end', id='unicode\u20ac')
+ self.tv.selection_set('unicode\u20ac')
+ self.assertEqual(self.tv.selection(), ('unicode\u20ac',))
+
+ self.tv.insert('', 'end', id=b'bytes\xe2\x82\xac')
+ self.tv.selection_set(b'bytes\xe2\x82\xac')
+ self.assertEqual(self.tv.selection(), ('bytes\xe2\x82\xac',))
+
+
def test_set(self):
self.tv['columns'] = ['A', 'B']
item = self.tv.insert('', 'end', values=['a', 'b'])
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -1396,7 +1396,9 @@
def selection(self, selop=None, items=None):
"""If selop is not specified, returns selected items."""
- return self.tk.call(self._w, "selection", selop, items)
+ if isinstance(items, (str, bytes)):
+ items = (items,)
+ return self.tk.splitlist(self.tk.call(self._w, "selection", selop, items))
def selection_set(self, items):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
Library
-------
+- Issue #26386: Fixed ttk.TreeView selection operations with item id's
+ containing spaces.
+
- Issue #8637: Honor a pager set by the env var MANPAGER (in preference to
one set by the env var PAGER).
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list