diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-19 21:05:40 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-19 21:05:40 (GMT) |
commit | b84f029baa20608fc1598857ad45774af7064b90 (patch) | |
tree | e380477821181803de3d9697d820e3244548e8ea /Lib/tkinter/ttk.py | |
parent | 6c85091b5bf1e03a3907be9ded38de1d0433f39b (diff) | |
download | cpython-b84f029baa20608fc1598857ad45774af7064b90.zip cpython-b84f029baa20608fc1598857ad45774af7064b90.tar.gz cpython-b84f029baa20608fc1598857ad45774af7064b90.tar.bz2 |
Issue #27319: Methods selection_set(), selection_add(), selection_remove()
and selection_toggle() of ttk.TreeView now allow to pass multiple items as
multiple arguments instead of passing them as a tuple. Deprecated
undocumented ability of calling the selection() method with arguments.
Diffstat (limited to 'Lib/tkinter/ttk.py')
-rw-r--r-- | Lib/tkinter/ttk.py | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py index 7b71e77..71ac2a7 100644 --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -28,6 +28,8 @@ __all__ = ["Button", "Checkbutton", "Combobox", "Entry", "Frame", "Label", import tkinter from tkinter import _flatten, _join, _stringify, _splitdict +_sentinel = object() + # Verify if Tk is new enough to not need the Tile package _REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False @@ -1394,31 +1396,53 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): self.tk.call(self._w, "see", item) - def selection(self, selop=None, items=None): - """If selop is not specified, returns selected items.""" - if isinstance(items, (str, bytes)): - items = (items,) + def selection(self, selop=_sentinel, items=None): + """Returns the tuple of selected items.""" + if selop is _sentinel: + selop = None + elif selop is None: + import warnings + warnings.warn( + "The selop=None argument of selection() is deprecated " + "and will be removed in Python 3.7", + DeprecationWarning, 3) + elif selop in ('set', 'add', 'remove', 'toggle'): + import warnings + warnings.warn( + "The selop argument of selection() is deprecated " + "and will be removed in Python 3.7, " + "use selection_%s() instead" % (selop,), + DeprecationWarning, 3) + else: + raise TypeError('Unsupported operation') return self.tk.splitlist(self.tk.call(self._w, "selection", selop, items)) - def selection_set(self, items): - """items becomes the new selection.""" - self.selection("set", items) + def _selection(self, selop, items): + if len(items) == 1 and isinstance(items[0], (tuple, list)): + items = items[0] + + self.tk.call(self._w, "selection", selop, items) + + + def selection_set(self, *items): + """The specified items becomes the new selection.""" + self._selection("set", items) - def selection_add(self, items): - """Add items to the selection.""" - self.selection("add", items) + def selection_add(self, *items): + """Add all of the specified items to the selection.""" + self._selection("add", items) - def selection_remove(self, items): - """Remove items from the selection.""" - self.selection("remove", items) + def selection_remove(self, *items): + """Remove all of the specified items from the selection.""" + self._selection("remove", items) - def selection_toggle(self, items): - """Toggle the selection state of each item in items.""" - self.selection("toggle", items) + def selection_toggle(self, *items): + """Toggle the selection state of each specified item.""" + self._selection("toggle", items) def set(self, item, column=None, value=None): |