Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 256705b

Browse files
committed
SF patch 546244 by John Williams: add Text.dump() method.
1 parent 4e1dd7d commit 256705b

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

Lib/lib-tk/Tkinter.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,6 @@ def set(self, *args):
26272627

26282628
class Text(Widget):
26292629
"""Text widget which can display text in various forms."""
2630-
# XXX Add dump()
26312630
def __init__(self, master=None, cnf={}, **kw):
26322631
"""Construct a text widget with the parent MASTER.
26332632
@@ -2671,6 +2670,44 @@ def dlineinfo(self, index):
26712670
and baseline position of the visible part of the line containing
26722671
the character at INDEX."""
26732672
return self._getints(self.tk.call(self._w, 'dlineinfo', index))
2673+
def dump(self, index1, index2=None, command=None, **kw):
2674+
"""Return the contents of the widget between index1 and index2.
2675+
2676+
The type of contents returned in filtered based on the keyword
2677+
parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
2678+
given and true, then the corresponding items are returned. The result
2679+
is a list of triples of the form (key, value, index). If none of the
2680+
keywords are true then 'all' is used by default.
2681+
2682+
If the 'command' argument is given, it is called once for each element
2683+
of the list of triples, with the values of each triple serving as the
2684+
arguments to the function. In this case the list is not returned."""
2685+
args = []
2686+
func_name = None
2687+
result = None
2688+
if not command:
2689+
# Never call the dump command without the -command flag, since the
2690+
# output could involve Tcl quoting and would be a pain to parse
2691+
# right. Instead just set the command to build a list of triples
2692+
# as if we had done the parsing.
2693+
result = []
2694+
def append_triple(key, value, index, result=result):
2695+
result.append((key, value, index))
2696+
command = append_triple
2697+
try:
2698+
if not isinstance(command, str):
2699+
func_name = command = self._register(command)
2700+
args += ["-command", command]
2701+
for key in kw:
2702+
if kw[key]: args.append("-" + key)
2703+
args.append(index1)
2704+
if index2:
2705+
args.append(index2)
2706+
self.tk.call(self._w, "dump", *args)
2707+
return result
2708+
finally:
2709+
if func_name:
2710+
self.deletecommand(func_name)
26742711
def get(self, index1, index2=None):
26752712
"""Return the text from INDEX1 to INDEX2 (not included)."""
26762713
return self.tk.call(self._w, 'get', index1, index2)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ Truida Wiedijk
487487
Gerry Wiener
488488
Bryce "Zooko" Wilcox-O'Hearn
489489
Gerald S. Williams
490+
John Williams
490491
Sue Williams
491492
Frank Willison
492493
Greg V. Wilson

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Extension modules
9191

9292
Library
9393

94+
- New Text.dump() method in Tkinter module.
95+
9496
- New distutils commands for building packagers were added to
9597
support pkgtool on Solaris and swinstall on HP-UX.
9698

0 commit comments

Comments
 (0)