Commit 256705bc authored by Guido van Rossum's avatar Guido van Rossum

SF patch 546244 by John Williams: add Text.dump() method.

parent 4e1dd7d6
...@@ -2627,7 +2627,6 @@ class Scrollbar(Widget): ...@@ -2627,7 +2627,6 @@ class Scrollbar(Widget):
class Text(Widget): class Text(Widget):
"""Text widget which can display text in various forms.""" """Text widget which can display text in various forms."""
# XXX Add dump()
def __init__(self, master=None, cnf={}, **kw): def __init__(self, master=None, cnf={}, **kw):
"""Construct a text widget with the parent MASTER. """Construct a text widget with the parent MASTER.
...@@ -2671,6 +2670,44 @@ class Text(Widget): ...@@ -2671,6 +2670,44 @@ class Text(Widget):
and baseline position of the visible part of the line containing and baseline position of the visible part of the line containing
the character at INDEX.""" the character at INDEX."""
return self._getints(self.tk.call(self._w, 'dlineinfo', index)) return self._getints(self.tk.call(self._w, 'dlineinfo', index))
def dump(self, index1, index2=None, command=None, **kw):
"""Return the contents of the widget between index1 and index2.
The type of contents returned in filtered based on the keyword
parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
given and true, then the corresponding items are returned. The result
is a list of triples of the form (key, value, index). If none of the
keywords are true then 'all' is used by default.
If the 'command' argument is given, it is called once for each element
of the list of triples, with the values of each triple serving as the
arguments to the function. In this case the list is not returned."""
args = []
func_name = None
result = None
if not command:
# Never call the dump command without the -command flag, since the
# output could involve Tcl quoting and would be a pain to parse
# right. Instead just set the command to build a list of triples
# as if we had done the parsing.
result = []
def append_triple(key, value, index, result=result):
result.append((key, value, index))
command = append_triple
try:
if not isinstance(command, str):
func_name = command = self._register(command)
args += ["-command", command]
for key in kw:
if kw[key]: args.append("-" + key)
args.append(index1)
if index2:
args.append(index2)
self.tk.call(self._w, "dump", *args)
return result
finally:
if func_name:
self.deletecommand(func_name)
def get(self, index1, index2=None): def get(self, index1, index2=None):
"""Return the text from INDEX1 to INDEX2 (not included).""" """Return the text from INDEX1 to INDEX2 (not included)."""
return self.tk.call(self._w, 'get', index1, index2) return self.tk.call(self._w, 'get', index1, index2)
......
...@@ -487,6 +487,7 @@ Truida Wiedijk ...@@ -487,6 +487,7 @@ Truida Wiedijk
Gerry Wiener Gerry Wiener
Bryce "Zooko" Wilcox-O'Hearn Bryce "Zooko" Wilcox-O'Hearn
Gerald S. Williams Gerald S. Williams
John Williams
Sue Williams Sue Williams
Frank Willison Frank Willison
Greg V. Wilson Greg V. Wilson
......
...@@ -91,6 +91,8 @@ Extension modules ...@@ -91,6 +91,8 @@ Extension modules
Library Library
- New Text.dump() method in Tkinter module.
- New distutils commands for building packagers were added to - New distutils commands for building packagers were added to
support pkgtool on Solaris and swinstall on HP-UX. support pkgtool on Solaris and swinstall on HP-UX.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment