2 from idlelib
.EditorWindow
import EditorWindow
5 from idlelib
import IOBinding
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
, lines
):
57 # Our own right-button menu
60 ("Go to file/line", "<<goto-file-line>>"),
64 # order of patterns matters
65 r
'file "([^"]*)", line (\d+)',
67 r
'^(\s*\S.*?):\s*(\d+):', # Win filename, maybe starting with spaces
68 r
'([^\s]+):\s*(\d+):', # filename or path, ltrim
69 r
'^\s*(\S.*?):\s*(\d+):', # Win abs path with embedded spaces, ltrim
72 file_line_progs
= None
74 def goto_file_line(self
, event
=None):
75 if self
.file_line_progs
is None:
77 for pat
in self
.file_line_pats
:
78 l
.append(re
.compile(pat
, re
.IGNORECASE
))
79 self
.file_line_progs
= l
80 # x, y = self.event.x, self.event.y
81 # self.text.mark_set("insert", "@%d,%d" % (x, y))
82 line
= self
.text
.get("insert linestart", "insert lineend")
83 result
= self
._file
_line
_helper
(line
)
85 # Try the previous line. This is handy e.g. in tracebacks,
86 # where you tend to right-click on the displayed source line
87 line
= self
.text
.get("insert -1line linestart",
88 "insert -1line lineend")
89 result
= self
._file
_line
_helper
(line
)
91 tkMessageBox
.showerror(
93 "The line you point at doesn't look like "
94 "a valid file name followed by a line number.",
97 filename
, lineno
= result
98 edit
= self
.flist
.open(filename
)
101 def _file_line_helper(self
, line
):
102 for prog
in self
.file_line_progs
:
103 match
= prog
.search(line
)
105 filename
, lineno
= match
.group(1, 2)
107 f
= open(filename
, "r")
115 return filename
, int(lineno
)
119 # These classes are currently not used but might come in handy
121 class OnDemandOutputWindow
:
124 # XXX Should use IdlePrefs.ColorPrefs
125 "stdout": {"foreground": "blue"},
126 "stderr": {"foreground": "#007700"},
129 def __init__(self
, flist
):
133 def write(self
, s
, tags
, mark
):
136 self
.owin
.write(s
, tags
, mark
)
139 self
.owin
= owin
= OutputWindow(self
.flist
)
141 for tag
, cnf
in self
.tagdefs
.items():
143 text
.tag_configure(tag
, **cnf
)
144 text
.tag_raise('sel')
145 self
.write
= self
.owin
.write