]> granicus.if.org Git - python/commitdiff
SF patch 546244 by John Williams: add Text.dump() method.
authorGuido van Rossum <guido@python.org>
Tue, 23 Apr 2002 13:29:43 +0000 (13:29 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 23 Apr 2002 13:29:43 +0000 (13:29 +0000)
Lib/lib-tk/Tkinter.py
Misc/ACKS
Misc/NEWS

index f35cbd8ae5311b3a1bc9adef3479dc2b3c00bbd4..c5bf136f80b7c0504bccf524697b33992ca078da 100644 (file)
@@ -2627,7 +2627,6 @@ class Scrollbar(Widget):
 
 class Text(Widget):
     """Text widget which can display text in various forms."""
-    # XXX Add dump()
     def __init__(self, master=None, cnf={}, **kw):
         """Construct a text widget with the parent MASTER.
 
@@ -2671,6 +2670,44 @@ class Text(Widget):
         and baseline position of the visible part of the line containing
         the character at 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):
         """Return the text from INDEX1 to INDEX2 (not included)."""
         return self.tk.call(self._w, 'get', index1, index2)
index 12605fccd7a9219aae72cc6ad0488ad3c9f51f76..b4135402dfafe99936ce1458577908d4be2d7457 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -487,6 +487,7 @@ Truida Wiedijk
 Gerry Wiener
 Bryce "Zooko" Wilcox-O'Hearn
 Gerald S. Williams
+John Williams
 Sue Williams
 Frank Willison
 Greg V. Wilson
index 2e36fc047dcaddd04a1137bdde7d2a857e982209..a0ae51e151611f5b07f0fa330ffc7627ac1ecadc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,8 @@ Extension modules
 
 Library
 
+- New Text.dump() method in Tkinter module.
+
 - New distutils commands for building packagers were added to
   support pkgtool on Solaris and swinstall on HP-UX.