2 from EditorWindow
import EditorWindow
6 class OutputWindow(EditorWindow
):
8 """An editor window that can serve as an output file.
10 Also the future base class for the Python shell window.
11 This class has no input facilities.
14 def __init__(self
, *args
):
15 apply(EditorWindow
.__init
__, (self
,) + args
)
16 self
.text
.bind("<<goto-file-line>>", self
.goto_file_line
)
18 # Customize EditorWindow
20 def ispythonsource(self
, filename
):
21 # No colorization needed
24 def short_title(self
):
28 # Override base class method -- don't ask any questions
36 def write(self
, s
, tags
=(), mark
="insert"):
37 self
.text
.insert(mark
, str(s
), tags
)
41 def writelines(self
, l
):
47 # Our own right-button menu
50 ("Go to file/line", "<<goto-file-line>>"),
54 r
'file "([^"]*)", line (\d+)',
56 r
'([^\s]+):\s*(\d+):',
59 file_line_progs
= None
61 def goto_file_line(self
, event
=None):
62 if self
.file_line_progs
is None:
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
)
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
)
78 tkMessageBox
.showerror(
80 "The line you point at doesn't look like "
81 "a valid file name followed by a line number.",
84 filename
, lineno
= result
85 edit
= self
.flist
.open(filename
)
88 def _file_line_helper(self
, line
):
89 for prog
in self
.file_line_progs
:
95 filename
, lineno
= m
.group(1, 2)
97 f
= open(filename
, "r")
102 return filename
, int(lineno
)
106 # These classes are currently not used but might come in handy
108 class OnDemandOutputWindow
:
111 # XXX Should use IdlePrefs.ColorPrefs
112 "stdout": {"foreground": "blue"},
113 "stderr": {"foreground": "#007700"},
116 def __init__(self
, flist
):
120 def write(self
, s
, tags
, mark
):
123 self
.owin
.write(s
, tags
, mark
)
126 self
.owin
= owin
= OutputWindow(self
.flist
)
128 for tag
, cnf
in self
.tagdefs
.items():
130 apply(text
.tag_configure
, (tag
,), cnf
)
131 text
.tag_raise('sel')
132 self
.write
= self
.owin
.write
136 def __init__(self
, owin
, tags
, mark
="end"):
142 self
.owin
.write(s
, self
.tags
, self
.mark
)
144 def writelines(self
, l
):