Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/OutputWindow.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | b8c72e86a12d |
| children | 892dfc9e7256 |
| rev | line source |
|---|---|
| 13975 | 1 from Tkinter import * |
| 2 from EditorWindow import EditorWindow | |
| 3 import re | |
| 4 import tkMessageBox | |
| 5 | |
|
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
|
6 class OutputWindow(EditorWindow): |
| 13975 | 7 |
|
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
|
8 """An editor window that can serve as an output file. |
| 13975 | 9 |
|
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
|
10 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
|
11 This class has no input facilities. |
| 13975 | 12 """ |
| 13 | |
|
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
|
14 def __init__(self, *args): |
| 13975 | 15 apply(EditorWindow.__init__, (self,) + args) |
| 16 self.text.bind("<<goto-file-line>>", self.goto_file_line) | |
| 17 | |
| 18 # Customize EditorWindow | |
| 19 | |
| 20 def ispythonsource(self, filename): | |
| 21 # No colorization needed | |
| 22 return 0 | |
| 23 | |
| 24 def short_title(self): | |
| 25 return "Output" | |
| 26 | |
| 27 def maybesave(self): | |
| 28 # Override base class method -- don't ask any questions | |
| 29 if self.get_saved(): | |
| 30 return "yes" | |
| 31 else: | |
| 32 return "no" | |
| 33 | |
| 34 # Act as output file | |
| 35 | |
|
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
|
36 def write(self, s, tags=(), mark="insert"): |
|
25096
98ddc4297f36
(Re)Apply Sourceforge Python patch 520483, Sourceforge Idlefork patch
Kurt B. Kaiser <kbk@shore.net>
parents:
23784
diff
changeset
|
37 self.text.insert(mark, s, tags) |
| 13975 | 38 self.text.see(mark) |
| 39 self.text.update() | |
| 40 | |
| 41 def writelines(self, l): | |
| 42 map(self.write, l) | |
| 43 | |
| 44 def flush(self): | |
| 45 pass | |
| 46 | |
| 47 # Our own right-button menu | |
| 48 | |
| 49 rmenu_specs = [ | |
| 50 ("Go to file/line", "<<goto-file-line>>"), | |
| 51 ] | |
| 52 | |
| 53 file_line_pats = [ | |
| 54 r'file "([^"]*)", line (\d+)', | |
| 55 r'([^\s]+)\((\d+)\)', | |
| 56 r'([^\s]+):\s*(\d+):', | |
| 57 ] | |
| 58 | |
| 59 file_line_progs = None | |
| 60 | |
| 61 def goto_file_line(self, event=None): | |
| 62 if self.file_line_progs is None: | |
| 63 l = [] | |
| 64 for pat in self.file_line_pats: | |
| 65 l.append(re.compile(pat, re.IGNORECASE)) | |
| 66 self.file_line_progs = l | |
| 67 # x, y = self.event.x, self.event.y | |
| 68 # self.text.mark_set("insert", "@%d,%d" % (x, y)) | |
| 69 line = self.text.get("insert linestart", "insert lineend") | |
| 70 result = self._file_line_helper(line) | |
| 71 if not result: | |
| 72 # Try the previous line. This is handy e.g. in tracebacks, | |
| 73 # where you tend to right-click on the displayed source line | |
| 74 line = self.text.get("insert -1line linestart", | |
| 75 "insert -1line lineend") | |
| 76 result = self._file_line_helper(line) | |
| 77 if not result: | |
| 78 tkMessageBox.showerror( | |
| 79 "No special line", | |
| 80 "The line you point at doesn't look like " | |
| 81 "a valid file name followed by a line number.", | |
| 82 master=self.text) | |
| 83 return | |
| 84 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
|
85 edit = self.flist.open(filename) |
| 13975 | 86 edit.gotoline(lineno) |
| 87 | |
| 88 def _file_line_helper(self, line): | |
| 89 for prog in self.file_line_progs: | |
| 90 m = prog.search(line) | |
| 91 if m: | |
| 92 break | |
| 93 else: | |
| 94 return None | |
| 95 filename, lineno = m.group(1, 2) | |
|
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
|
96 try: |
|
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 f = open(filename, "r") |
|
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
|
98 f.close() |
|
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
|
99 except IOError: |
|
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
|
100 return None |
| 13975 | 101 try: |
| 102 return filename, int(lineno) | |
| 103 except TypeError: | |
| 104 return None | |
| 105 | |
|
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
|
106 # These classes are currently not used but might come in handy |
| 13975 | 107 |
| 108 class OnDemandOutputWindow: | |
| 109 | |
| 110 tagdefs = { | |
| 111 # XXX Should use IdlePrefs.ColorPrefs | |
| 112 "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
|
113 "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
|
114 } |
|
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
|
115 |
| 13975 | 116 def __init__(self, flist): |
| 117 self.flist = flist | |
| 118 self.owin = None | |
| 119 | |
|
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 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
|
121 if not self.owin: |
| 13975 | 122 self.setup() |
| 123 self.owin.write(s, tags, mark) | |
| 124 | |
| 125 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
|
126 self.owin = owin = OutputWindow(self.flist) |
| 13975 | 127 text = owin.text |
| 128 for tag, cnf in self.tagdefs.items(): | |
| 129 if cnf: | |
| 130 apply(text.tag_configure, (tag,), cnf) | |
| 131 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
|
132 self.write = self.owin.write |
|
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 |
|
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 #class PseudoFile: |
|
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
|
135 # |
|
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
|
136 # def __init__(self, owin, tags, mark="end"): |
|
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
|
137 # self.owin = owin |
|
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.tags = tags |
|
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.mark = 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
|
140 |
|
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
|
141 # def write(self, s): |
|
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
|
142 # self.owin.write(s, self.tags, self.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
|
143 |
|
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 # def writelines(self, l): |
|
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
|
145 # map(self.write, l) |
|
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
|
146 |
|
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
|
147 # def flush(self): |
|
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
|
148 # pass |
