Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/OutputWindow.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 9895483e9601 |
| children | f72965374b2a |
| 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() | |
| 43 | |
|
42507
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
44 def writelines(self, lines): |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
45 for line in lines: |
|
df4cd9297098
Fix remaining map() issues.
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
46 self.write(line) |
| 13975 | 47 |
| 48 def flush(self): | |
| 49 pass | |
| 50 | |
| 51 # Our own right-button menu | |
| 52 | |
| 53 rmenu_specs = [ | |
| 54 ("Go to file/line", "<<goto-file-line>>"), | |
| 55 ] | |
| 56 | |
| 57 file_line_pats = [ | |
|
53825
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
58 # order of patterns matters |
| 13975 | 59 r'file "([^"]*)", line (\d+)', |
| 60 r'([^\s]+)\((\d+)\)', | |
|
53825
9895483e9601
Merged revisions 72227 via svnmerge from
Kurt B. Kaiser <kbk@shore.net>
parents:
53534
diff
changeset
|
61 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
|
62 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
|
63 r'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim |
| 13975 | 64 ] |
| 65 | |
| 66 file_line_progs = None | |
| 67 | |
| 68 def goto_file_line(self, event=None): | |
| 69 if self.file_line_progs is None: | |
| 70 l = [] | |
| 71 for pat in self.file_line_pats: | |
| 72 l.append(re.compile(pat, re.IGNORECASE)) | |
| 73 self.file_line_progs = l | |
| 74 # x, y = self.event.x, self.event.y | |
| 75 # self.text.mark_set("insert", "@%d,%d" % (x, y)) | |
| 76 line = self.text.get("insert linestart", "insert lineend") | |
| 77 result = self._file_line_helper(line) | |
| 78 if not result: | |
| 79 # Try the previous line. This is handy e.g. in tracebacks, | |
| 80 # where you tend to right-click on the displayed source line | |
| 81 line = self.text.get("insert -1line linestart", | |
| 82 "insert -1line lineend") | |
| 83 result = self._file_line_helper(line) | |
| 84 if not result: | |
| 85 tkMessageBox.showerror( | |
| 86 "No special line", | |
| 87 "The line you point at doesn't look like " | |
| 88 "a valid file name followed by a line number.", | |
| 89 master=self.text) | |
| 90 return | |
| 91 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
|
92 edit = self.flist.open(filename) |
| 13975 | 93 edit.gotoline(lineno) |
| 94 | |
| 95 def _file_line_helper(self, line): | |
| 96 for prog in self.file_line_progs: | |
|
53534
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
97 match = prog.search(line) |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
98 if match: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
99 filename, lineno = match.group(1, 2) |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
100 try: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
101 f = open(filename, "r") |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
102 f.close() |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
103 break |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
104 except IOError: |
|
2ce26c4679cb
Merged revisions 71995 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47130
diff
changeset
|
105 continue |
| 13975 | 106 else: |
| 107 return None | |
| 108 try: | |
| 109 return filename, int(lineno) | |
| 110 except TypeError: | |
| 111 return None | |
| 112 | |
|
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
|
113 # These classes are currently not used but might come in handy |
| 13975 | 114 |
| 115 class OnDemandOutputWindow: | |
| 116 | |
| 117 tagdefs = { | |
| 118 # XXX Should use IdlePrefs.ColorPrefs | |
| 119 "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
|
120 "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
|
121 } |
|
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 |
| 13975 | 123 def __init__(self, flist): |
| 124 self.flist = flist | |
| 125 self.owin = None | |
| 126 | |
|
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
|
127 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
|
128 if not self.owin: |
| 13975 | 129 self.setup() |
| 130 self.owin.write(s, tags, mark) | |
| 131 | |
| 132 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
|
133 self.owin = owin = OutputWindow(self.flist) |
| 13975 | 134 text = owin.text |
| 135 for tag, cnf in self.tagdefs.items(): | |
| 136 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
|
137 text.tag_configure(tag, **cnf) |
| 13975 | 138 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
|
139 self.write = self.owin.write |
