Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/OutputWindow.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | f72965374b2a |
| children | 66643fcf6ee9 |
| rev | line source |
|---|---|
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
1 from tkinter import * |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42572
diff
changeset
|
2 from idlelib.EditorWindow import EditorWindow |
| 13975 | 3 import re |
|
47130
ef4cca2d6171
Tkinter, step 2: adapt imports.
Georg Brandl <georg@python.org>
parents:
43777
diff
changeset
|
4 import tkinter.messagebox as tkMessageBox |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42572
diff
changeset
|
5 from idlelib import IOBinding |
| 13975 | 6 |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
7 class OutputWindow(EditorWindow): |
| 13975 | 8 |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
9 """An editor window that can serve as an output file. |
| 13975 | 10 |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
11 Also the future base class for the Python shell window. |
|
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
12 This class has no input facilities. |
| 13975 | 13 """ |
| 14 | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
15 def __init__(self, *args): |
|
29794
94e5d1b8f696
SF patch #768187: replace apply(f, args, kwds) with f(*args, **kwds)
Raymond Hettinger <python@rcn.com>
parents:
29477
diff
changeset
|
16 EditorWindow.__init__(self, *args) |
| 13975 | 17 self.text.bind("<<goto-file-line>>", self.goto_file_line) |
| 18 | |
| 19 # Customize EditorWindow | |
| 20 | |
| 21 def ispythonsource(self, filename): | |
| 22 # No colorization needed | |
| 23 return 0 | |
| 24 | |
| 25 def short_title(self): | |
| 26 return "Output" | |
| 27 | |
| 28 def maybesave(self): | |
| 29 # Override base class method -- don't ask any questions | |
| 30 if self.get_saved(): | |
| 31 return "yes" | |
| 32 else: | |
| 33 return "no" | |
| 34 | |
| 35 # Act as output file | |
| 36 | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
37 def write(self, s, tags=(), mark="insert"): |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
42714
diff
changeset
|
38 if isinstance(s, (bytes, bytes)): |
|
42572
a724279fc931
Allow str8 in .write().
Martin v. Löwis <martin@v.loewis.de>
parents:
42570
diff
changeset
|
39 s = s.decode(IOBinding.encoding, "replace") |
|
25096
98ddc4297f36
(Re)Apply Sourceforge Python patch 520483, Sourceforge Idlefork patch
Kurt B. Kaiser <kbk@shore.net>
parents:
23784
diff
changeset
|
40 self.text.insert(mark, s, tags) |
| 13975 | 41 self.text.see(mark) |
| 42 self.text.update() | |
|
78276
f72965374b2a
Issue #7163: Propagate return value of sys.stdout.write.
Martin v. Löwis <martin@v.loewis.de>
parents:
53825
diff
changeset
|
43 return len(s) |
| 13975 | 44 |
|
42507
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
45 def writelines(self, lines): |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
46 for line in lines: |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
47 self.write(line) |
| 13975 | 48 |
| 49 def flush(self): | |
| 50 pass | |
| 51 | |
| 52 # Our own right-button menu | |
| 53 | |
| 54 rmenu_specs = [ | |
| 55 ("Go to file/line", "<<goto-file-line>>"), | |
| 56 ] | |
| 57 | |
| 58 file_line_pats = [ | |
|
53825
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
59 # order of patterns matters |
| 13975 | 60 r'file "([^"]*)", line (\d+)', |
| 61 r'([^\s]+)\((\d+)\)', | |
|
53825
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
62 r'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces |
|
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
63 r'([^\s]+):\s*(\d+):', # filename or path, ltrim |
|
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
64 r'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim |
| 13975 | 65 ] |
| 66 | |
| 67 file_line_progs = None | |
| 68 | |
| 69 def goto_file_line(self, event=None): | |
| 70 if self.file_line_progs is None: | |
| 71 l = [] | |
| 72 for pat in self.file_line_pats: | |
| 73 l.append(re.compile(pat, re.IGNORECASE)) | |
| 74 self.file_line_progs = l | |
| 75 # x, y = self.event.x, self.event.y | |
| 76 # self.text.mark_set("insert", "@%d,%d" % (x, y)) | |
| 77 line = self.text.get("insert linestart", "insert lineend") | |
| 78 result = self._file_line_helper(line) | |
| 79 if not result: | |
| 80 # Try the previous line. This is handy e.g. in tracebacks, | |
| 81 # where you tend to right-click on the displayed source line | |
| 82 line = self.text.get("insert -1line linestart", | |
| 83 "insert -1line lineend") | |
| 84 result = self._file_line_helper(line) | |
| 85 if not result: | |
| 86 tkMessageBox.showerror( | |
| 87 "No special line", | |
| 88 "The line you point at doesn't look like " | |
| 89 "a valid file name followed by a line number.", | |
| 90 master=self.text) | |
| 91 return | |
| 92 filename, lineno = result | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
93 edit = self.flist.open(filename) |
| 13975 | 94 edit.gotoline(lineno) |
| 95 | |
| 96 def _file_line_helper(self, line): | |
| 97 for prog in self.file_line_progs: | |
|
53534
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
98 match = prog.search(line) |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
99 if match: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
100 filename, lineno = match.group(1, 2) |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
101 try: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
102 f = open(filename, "r") |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
103 f.close() |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
104 break |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
105 except IOError: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
106 continue |
| 13975 | 107 else: |
| 108 return None | |
| 109 try: | |
| 110 return filename, int(lineno) | |
| 111 except TypeError: | |
| 112 return None | |
| 113 | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
114 # These classes are currently not used but might come in handy |
| 13975 | 115 |
| 116 class OnDemandOutputWindow: | |
| 117 | |
| 118 tagdefs = { | |
| 119 # XXX Should use IdlePrefs.ColorPrefs | |
| 120 "stdout": {"foreground": "blue"}, | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
121 "stderr": {"foreground": "#007700"}, |
|
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
122 } |
|
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
123 |
| 13975 | 124 def __init__(self, flist): |
| 125 self.flist = flist | |
| 126 self.owin = None | |
| 127 | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
128 def write(self, s, tags, mark): |
|
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
129 if not self.owin: |
| 13975 | 130 self.setup() |
| 131 self.owin.write(s, tags, mark) | |
| 132 | |
| 133 def setup(self): | |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
134 self.owin = owin = OutputWindow(self.flist) |
| 13975 | 135 text = owin.text |
| 136 for tag, cnf in self.tagdefs.items(): | |
| 137 if cnf: | |
|
29794
94e5d1b8f696
SF patch #768187: replace apply(f, args, kwds) with f(*args, **kwds)
Raymond Hettinger <python@rcn.com>
parents:
29477
diff
changeset
|
138 text.tag_configure(tag, **cnf) |
| 13975 | 139 text.tag_raise('sel') |
|
23784
24b0f6d693e3
Rework the code to have only the GvR RPC. Output from execution of user
Kurt B. Kaiser <kbk@shore.net>
parents:
22012
diff
changeset
|
140 self.write = self.owin.write |
