2 from EditorWindow
import EditorWindow
7 class OutputWindow(EditorWindow
):
9 """An editor window that can serve as an output file.
11 Also the future base class for the Python shell window.
12 This class has no input facilities.
15 def __init__(self
, *args
):
16 EditorWindow
.__init
__(self
, *args
)
17 self
.text
.bind("<<goto-file-line>>", self
.goto_file_line
)
19 # Customize EditorWindow
21 def ispythonsource(self
, filename
):
22 # No colorization needed
25 def short_title(self
):
29 # Override base class method -- don't ask any questions
37 def write(self
, s
, tags
=(), mark
="insert"):
38 # Tk assumes that byte strings are Latin-1;
39 # we assume that they are in the locale's encoding
40 if isinstance(s
, str):
42 s
= unicode(s
, IOBinding
.encoding
)
44 # some other encoding; let Tcl deal with it
46 self
.text
.insert(mark
, s
, tags
)
50 def writelines(self
, l
):
56 # Our own right-button menu
59 ("Go to file/line", "<<goto-file-line>>"),
63 # order of patterns matters
64 r
'file "([^"]*)", line (\d+)',
66 r
'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces
67 r
'([^\s]+):\s*(\d+):', # filename or path, ltrim
68 r
'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim
71 file_line_progs
= None
73 def goto_file_line(self
, event
=None):
74 if self
.file_line_progs
is None:
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
)
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
)
90 tkMessageBox
.showerror(
92 "The line you point at doesn't look like "
93 "a valid file name followed by a line number.",
96 filename
, lineno
= result
97 edit
= self
.flist
.open(filename
)
100 def _file_line_helper(self
, line
):
101 for prog
in self
.file_line_progs
:
102 match
= prog
.search(line
)
104 filename
, lineno
= match
.group(1, 2)
106 f
= open(filename
, "r")
114 return filename
, int(lineno
)
118 # These classes are currently not used but might come in handy
120 class OnDemandOutputWindow
:
123 # XXX Should use IdlePrefs.ColorPrefs
124 "stdout": {"foreground": "blue"},
125 "stderr": {"foreground": "#007700"},
128 def __init__(self
, flist
):
132 def write(self
, s
, tags
, mark
):
135 self
.owin
.write(s
, tags
, mark
)
138 self
.owin
= owin
= OutputWindow(self
.flist
)
140 for tag
, cnf
in self
.tagdefs
.items():
142 text
.tag_configure(tag
, **cnf
)
143 text
.tag_raise('sel')
144 self
.write
= self
.owin
.write