summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-11-03 12:34:25 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-11-03 12:34:25 (GMT)
commit4babb9111fddb0a4b746a3fda6e1627c827fc056 (patch)
treea721d2060cc4327d1536b80983517639592a4932 /Lib/tkinter
parent0de5362a408325e7dfe7736c93e34243b4584740 (diff)
parent0b9e815d8dfab1844d8095b916e0ccb75d7bf3da (diff)
downloadcpython-4babb9111fddb0a4b746a3fda6e1627c827fc056.zip
cpython-4babb9111fddb0a4b746a3fda6e1627c827fc056.tar.gz
cpython-4babb9111fddb0a4b746a3fda6e1627c827fc056.tar.bz2
Issue #6157: Fixed tkinter.Text.debug(). tkinter.Text.bbox() now raises
TypeError instead of TclError on wrong number of arguments. Original patch by Guilherme Polo.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py11
-rw-r--r--Lib/tkinter/test/test_tkinter/test_text.py11
-rw-r--r--Lib/tkinter/test/test_tkinter/test_widgets.py13
3 files changed, 30 insertions, 5 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index a9618b0..22a41ac 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -2911,11 +2911,11 @@ class Text(Widget, XView, YView):
"""
Widget.__init__(self, master, 'text', cnf, kw)
- def bbox(self, *args):
+ def bbox(self, index):
"""Return a tuple of (x,y,width,height) which gives the bounding
- box of the visible part of the character at the index in ARGS."""
+ box of the visible part of the character at the given index."""
return self._getints(
- self.tk.call((self._w, 'bbox') + args)) or None
+ self.tk.call(self._w, 'bbox', index)) or None
def tk_textSelectTo(self, index):
self.tk.call('tk_textSelectTo', self._w, index)
def tk_textBackspace(self):
@@ -2951,8 +2951,9 @@ class Text(Widget, XView, YView):
def debug(self, boolean=None):
"""Turn on the internal consistency checks of the B-Tree inside the text
widget according to BOOLEAN."""
- return self.tk.getboolean(self.tk.call(
- self._w, 'debug', boolean))
+ if boolean is None:
+ return self.tk.call(self._w, 'debug')
+ self.tk.call(self._w, 'debug', boolean)
def delete(self, index1, index2=None):
"""Delete the characters between INDEX1 and INDEX2 (not included)."""
self.tk.call(self._w, 'delete', index1, index2)
diff --git a/Lib/tkinter/test/test_tkinter/test_text.py b/Lib/tkinter/test/test_tkinter/test_text.py
index a93c4ce..4c3fa04 100644
--- a/Lib/tkinter/test/test_tkinter/test_text.py
+++ b/Lib/tkinter/test/test_tkinter/test_text.py
@@ -14,6 +14,17 @@ class TextTest(unittest.TestCase):
def tearDown(self):
self.text.destroy()
+ def test_debug(self):
+ text = self.text
+ olddebug = text.debug()
+ try:
+ text.debug(0)
+ self.assertEqual(text.debug(), 0)
+ text.debug(1)
+ self.assertEqual(text.debug(), 1)
+ finally:
+ text.debug(olddebug)
+ self.assertEqual(text.debug(), olddebug)
def test_search(self):
text = self.text
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
index 7b89c74..e38fb3f 100644
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -610,6 +610,19 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
else:
self.checkEnumParam(widget, 'wrap', 'char', 'none', 'word')
+ def test_bbox(self):
+ widget = self.create()
+ bbox = widget.bbox('1.1')
+ self.assertEqual(len(bbox), 4)
+ for item in bbox:
+ self.assertIsInstance(item, int)
+
+ self.assertIsNone(widget.bbox('end'))
+ self.assertRaises(tkinter.TclError, widget.bbox, 'noindex')
+ self.assertRaises(tkinter.TclError, widget.bbox, None)
+ self.assertRaises(TypeError, widget.bbox)
+ self.assertRaises(TypeError, widget.bbox, '1.1', 'end')
+
@add_standard_options(PixelSizeTests, StandardOptionsTests)
class CanvasTest(AbstractWidgetTest, unittest.TestCase):