[Python-checkins] cpython: Issue #6167: Scrollbar.activate() now returns the name of active element if
serhiy.storchaka
python-checkins at python.org
Wed Jul 23 21:18:26 CEST 2014
http://hg.python.org/cpython/rev/6ae34a948cb4
changeset: 91790:6ae34a948cb4
parent: 91786:f7643c893587
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Jul 23 22:00:44 2014 +0300
summary:
Issue #6167: Scrollbar.activate() now returns the name of active element if
the argument is not specified. Scrollbar.set() now always accepts only 2
arguments. Added tests for Scrollbar.activate() and Scrollbar.set().
files:
Lib/tkinter/__init__.py | 16 +++++---
Lib/tkinter/test/test_tkinter/test_widgets.py | 19 ++++++++++
Misc/NEWS | 4 ++
3 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2875,10 +2875,14 @@
relief, repeatdelay, repeatinterval, takefocus,
troughcolor, width."""
Widget.__init__(self, master, 'scrollbar', cnf, kw)
- def activate(self, index):
- """Display the element at INDEX with activebackground and activerelief.
- INDEX can be "arrow1","slider" or "arrow2"."""
- self.tk.call(self._w, 'activate', index)
+ def activate(self, index=None):
+ """Marks the element indicated by index as active.
+ The only index values understood by this method are "arrow1",
+ "slider", or "arrow2". If any other value is specified then no
+ element of the scrollbar will be active. If index is not specified,
+ the method returns the name of the element that is currently active,
+ or None if no element is active."""
+ return self.tk.call(self._w, 'activate', index) or None
def delta(self, deltax, deltay):
"""Return the fractional change of the scrollbar setting if it
would be moved by DELTAX or DELTAY pixels."""
@@ -2896,10 +2900,10 @@
"""Return the current fractional values (upper and lower end)
of the slider position."""
return self._getdoubles(self.tk.call(self._w, 'get'))
- def set(self, *args):
+ def set(self, first, last):
"""Set the fractional values of the slider position (upper and
lower ends as value between 0 and 1)."""
- self.tk.call((self._w, 'set') + args)
+ self.tk.call(self._w, 'set', first, last)
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -916,6 +916,25 @@
self.checkEnumParam(widget, 'orient', 'vertical', 'horizontal',
errmsg='bad orientation "{}": must be vertical or horizontal')
+ def test_activate(self):
+ sb = self.create()
+ for e in ('arrow1', 'slider', 'arrow2'):
+ sb.activate(e)
+ self.assertEqual(sb.activate(), e)
+ sb.activate('')
+ self.assertIsNone(sb.activate())
+ self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2')
+
+ def test_set(self):
+ sb = self.create()
+ sb.set(0.2, 0.4)
+ self.assertEqual(sb.get(), (0.2, 0.4))
+ self.assertRaises(TclError, sb.set, 'abc', 'def')
+ self.assertRaises(TclError, sb.set, 0.6, 'def')
+ self.assertRaises(TclError, sb.set, 0.6, None)
+ self.assertRaises(TypeError, sb.set, 0.6)
+ self.assertRaises(TypeError, sb.set, 0.6, 0.7, 0.8)
+
@add_standard_options(StandardOptionsTests)
class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -108,6 +108,10 @@
Library
-------
+- Issue #6167: Scrollbar.activate() now returns the name of active element if
+ the argument is not specified. Scrollbar.set() now always accepts only 2
+ arguments.
+
- Issue #15275: Clean up and speed up the ntpath module.
- Issue #21888: plistlib's load() and loads() now work if the fmt parameter is
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list