from EditorWindow
import EditorWindow
class OutputWindow(EditorWindow
):
"""An editor window that can serve as an output file.
Also the future base class for the Python shell window.
This class has no input facilities.
def __init__(self
, *args
):
EditorWindow
.__init
__(self
, *args
)
self
.text
.bind("<<goto-file-line>>", self
.goto_file_line
)
def ispythonsource(self
, filename
):
# Override base class method -- don't ask any questions
def write(self
, s
, tags
=(), mark
="insert"):
# Tk assumes that byte strings are Latin-1;
# we assume that they are in the locale's encoding
s
= unicode(s
, IOBinding
.encoding
)
# some other encoding; let Tcl deal with it
self
.text
.insert(mark
, s
, tags
)
# Our own right-button menu
("Go to file/line", "<<goto-file-line>>"),
r
'file "([^"]*)", line (\d+)',
def goto_file_line(self
, event
=None):
if self
.file_line_progs
is None:
for pat
in self
.file_line_pats
:
l
.append(re
.compile(pat
, re
.IGNORECASE
))
# x, y = self.event.x, self.event.y
# self.text.mark_set("insert", "@%d,%d" % (x, y))
line
= self
.text
.get("insert linestart", "insert lineend")
result
= self
._file
_line
_helper
(line
)
# Try the previous line. This is handy e.g. in tracebacks,
# where you tend to right-click on the displayed source line
line
= self
.text
.get("insert -1line linestart",
result
= self
._file
_line
_helper
(line
)
"The line you point at doesn't look like "
"a valid file name followed by a line number.",
filename
, lineno
= result
edit
= self
.flist
.open(filename
)
def _file_line_helper(self
, line
):
for prog
in self
.file_line_progs
:
filename
, lineno
= m
.group(1, 2)
return filename
, int(lineno
)
# These classes are currently not used but might come in handy
class OnDemandOutputWindow
:
# XXX Should use IdlePrefs.ColorPrefs
"stdout": {"foreground": "blue"},
"stderr": {"foreground": "#007700"},
def __init__(self
, flist
):
def write(self
, s
, tags
, mark
):
self
.owin
.write(s
, tags
, mark
)
self
.owin
= owin
= OutputWindow(self
.flist
)
for tag
, cnf
in self
.tagdefs
.items():
text
.tag_configure(tag
, **cnf
)
self
.write
= self
.owin
.write
# def __init__(self, owin, tags, mark="end"):
# self.owin.write(s, self.tags, self.mark)
# def writelines(self, l):