Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/OutputWindow.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 9fef1f1657c8 |
| children | eab361617f6a |
| rev | line source |
|---|---|
|
47183
b53604fad54b
Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents:
47101
diff
changeset
|
1 from Tkinter import * |
| 13975 | 2 from EditorWindow import EditorWindow |
| 3 import re | |
|
47183
b53604fad54b
Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents:
47101
diff
changeset
|
4 import tkMessageBox |
|
29477
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
5 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"): |
|
29477
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
38 # Tk assumes that byte strings are Latin-1; |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
39 # we assume that they are in the locale's encoding |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
40 if isinstance(s, str): |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
41 try: |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
42 s = unicode(s, IOBinding.encoding) |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
43 except UnicodeError: |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
44 # some other encoding; let Tcl deal with it |
|
892dfc9e7256
Forwardport Patch from IDLEfork SF 615312
Kurt B. Kaiser <kbk@shore.net>
parents:
26959
diff
changeset
|
45 pass |
|
25096
98ddc4297f36
(Re)Apply Sourceforge Python patch 520483, Sourceforge Idlefork patch
Kurt B. Kaiser <kbk@shore.net>
parents:
23784
diff
changeset
|
46 self.text.insert(mark, s, tags) |
| 13975 | 47 self.text.see(mark) |
| 48 self.text.update() | |
| 49 | |
| 50 def writelines(self, l): | |
| 51 map(self.write, l) | |
| 52 | |
| 53 def flush(self): | |
| 54 pass | |
| 55 | |
| 56 # Our own right-button menu | |
| 57 | |
| 58 rmenu_specs = [ | |
| 59 ("Go to file/line", "<<goto-file-line>>"), | |
| 60 ] | |
| 61 | |
| 62 file_line_pats = [ | |
|
53697
9fef1f1657c8
Further development of issue5559, handle Windows files
Kurt B. Kaiser <kbk@shore.net>
parents:
53495
diff
changeset
|
63 # order of patterns matters |
| 13975 | 64 r'file "([^"]*)", line (\d+)', |
| 65 r'([^\s]+)\((\d+)\)', | |
|
53697
9fef1f1657c8
Further development of issue5559, handle Windows files
Kurt B. Kaiser <kbk@shore.net>
parents:
53495
diff
changeset
|
66 r'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces |
|
9fef1f1657c8
Further development of issue5559, handle Windows files
Kurt B. Kaiser <kbk@shore.net>
parents:
53495
diff
changeset
|
67 r'([^\s]+):\s*(\d+):', # filename or path, ltrim |
|
9fef1f1657c8
Further development of issue5559, handle Windows files
Kurt B. Kaiser <kbk@shore.net>
parents:
53495
diff
changeset
|
68 r'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim |
| 13975 | 69 ] |
| 70 | |
| 71 file_line_progs = None | |
| 72 | |
| 73 def goto_file_line(self, event=None): | |
| 74 if self.file_line_progs is None: | |
| 75 l = [] | |
| 76 for pat in self.file_line_pats: | |
| 77 l.append(re.compile(pat, re.IGNORECASE)) | |
| 78 self.file_line_progs = l | |
| 79 # x, y = self.event.x, self.event.y | |
| 80 # self.text.mark_set("insert", "@%d,%d" % (x, y)) | |
| 81 line = self.text.get("insert linestart", "insert lineend") | |
| 82 result = self._file_line_helper(line) | |
| 83 if not result: | |
| 84 # Try the previous line. This is handy e.g. in tracebacks, | |
| 85 # where you tend to right-click on the displayed source line | |
| 86 line = self.text.get("insert -1line linestart", | |
| 87 "insert -1line lineend") | |
| 88 result = self._file_line_helper(line) | |
| 89 if not result: | |
| 90 tkMessageBox.showerror( | |
| 91 "No special line", | |
| 92 "The line you point at doesn't look like " | |
| 93 "a valid file name followed by a line number.", | |
| 94 master=self.text) | |
| 95 return | |
| 96 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
|
97 edit = self.flist.open(filename) |
| 13975 | 98 edit.gotoline(lineno) |
| 99 | |
| 100 def _file_line_helper(self, line): | |
| 101 for prog in self.file_line_progs: | |
|
53495
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
102 match = prog.search(line) |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
103 if match: |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
104 filename, lineno = match.group(1, 2) |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
105 try: |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
106 f = open(filename, "r") |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
107 f.close() |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
108 break |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
109 except IOError: |
|
d2cfd3d3bc54
Right click 'go to file/line' not working if spaces
Kurt B. Kaiser <kbk@shore.net>
parents:
47183
diff
changeset
|
110 continue |
| 13975 | 111 else: |
| 112 return None | |
| 113 try: | |
| 114 return filename, int(lineno) | |
| 115 except TypeError: | |
| 116 return None | |
| 117 | |
|
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
|
118 # These classes are currently not used but might come in handy |
| 13975 | 119 |
| 120 class OnDemandOutputWindow: | |
| 121 | |
| 122 tagdefs = { | |
| 123 # XXX Should use IdlePrefs.ColorPrefs | |
| 124 "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
|
125 "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
|
126 } |
|
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 |
| 13975 | 128 def __init__(self, flist): |
| 129 self.flist = flist | |
| 130 self.owin = None | |
| 131 | |
|
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
|
132 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
|
133 if not self.owin: |
| 13975 | 134 self.setup() |
| 135 self.owin.write(s, tags, mark) | |
| 136 | |
| 137 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
|
138 self.owin = owin = OutputWindow(self.flist) |
| 13975 | 139 text = owin.text |
| 140 for tag, cnf in self.tagdefs.items(): | |
| 141 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
|
142 text.tag_configure(tag, **cnf) |
| 13975 | 143 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
|
144 self.write = self.owin.write |
