diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:05:40 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:05:40 -0800 |
commit | b2fa705fd3887c326e811c418469c784353027f4 (patch) | |
tree | b3428f73de91453edbfd4df1a5d4a212d182eb44 /Lib/tkinter/ttk.py | |
parent | 134e58fd3aaa2e91390041e143f3f0a21a60142b (diff) | |
parent | b53654b6dbfce8318a7d4d1cdaddca7a7fec194b (diff) | |
download | cpython-b2fa705fd3887c326e811c418469c784353027f4.tar.gz |
Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
Diffstat (limited to 'Lib/tkinter/ttk.py')
-rw-r--r-- | Lib/tkinter/ttk.py | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py index f4a6d8cf54..c474e60713 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 @@ -381,7 +383,9 @@ class Style(object): a sequence identifying the value for that option.""" if query_opt is not None: kw[query_opt] = None - return _val_or_dict(self.tk, kw, self._name, "configure", style) + result = _val_or_dict(self.tk, kw, self._name, "configure", style) + if result or query_opt: + return result def map(self, style, query_opt=None, **kw): @@ -466,12 +470,14 @@ class Style(object): def element_names(self): """Returns the list of elements defined in the current theme.""" - return self.tk.splitlist(self.tk.call(self._name, "element", "names")) + return tuple(n.lstrip('-') for n in self.tk.splitlist( + self.tk.call(self._name, "element", "names"))) def element_options(self, elementname): """Return the list of elementname's options.""" - return self.tk.splitlist(self.tk.call(self._name, "element", "options", elementname)) + return tuple(o.lstrip('-') for o in self.tk.splitlist( + self.tk.call(self._name, "element", "options", elementname))) def theme_create(self, themename, parent=None, settings=None): @@ -1390,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): |