blob: 456c45bd9365bfd371b79baee278b95c8c931177 [file] [log] [blame]
Guido van Rossum504b0bf1999-01-02 21:28:54 +00001from Tkinter import *
2from EditorWindow import EditorWindow
3import re
4import tkMessageBox
5
6class OutputWindow(EditorWindow):
7
8 """An editor window that can serve as an output file.
9
10 Also the future base class for the Python shell window.
11 This class has no input facilities.
12 """
13
14 def __init__(self, *args):
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
36 def write(self, s, tags=(), mark="insert"):
37 self.text.insert(mark, str(s), tags)
38 self.text.see(mark)
39 self.text.update()
40
41 def writelines(self, l):
42 map(self.write, l)
43
Guido van Rossum3d0ff001999-04-22 20:50:33 +000044 def flush(self):
45 pass
46
Guido van Rossum504b0bf1999-01-02 21:28:54 +000047 # 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 for prog in self.file_line_progs:
71 m = prog.search(line)
72 if m:
73 break
74 else:
75 tkMessageBox.showerror("No special line",
76 "The line you point at doesn't look like "
77 "a file name followed by a line number.",
78 master=self.text)
79 return
80 filename, lineno = m.group(1, 2)
81 try:
82 f = open(filename, "r")
83 f.close()
84 except IOError, msg:
85 self.text.bell()
86 return
87 edit = self.flist.open(filename)
88 try:
89 lineno = int(lineno)
90 except ValueError, msg:
91 self.text.bell()
92 return
93 edit.gotoline(lineno)