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 r
'file "([^"]*)", line (\d+)',
65 r
'([^\s]+):\s*(\d+):',
68 file_line_progs
= None
70 def goto_file_line(self
, event
=None):
71 if self
.file_line_progs
is None:
73 for pat
in self
.file_line_pats
:
74 l
.append(re
.compile(pat
, re
.IGNORECASE
))
75 self
.file_line_progs
= l
76 # x, y = self.event.x, self.event.y
77 # self.text.mark_set("insert", "@%d,%d" % (x, y))
78 line
= self
.text
.get("insert linestart", "insert lineend")
79 result
= self
._file
_line
_helper
(line
)
81 # Try the previous line. This is handy e.g. in tracebacks,
82 # where you tend to right-click on the displayed source line
83 line
= self
.text
.get("insert -1line linestart",
84 "insert -1line lineend")
85 result
= self
._file
_line
_helper
(line
)
87 tkMessageBox
.showerror(
89 "The line you point at doesn't look like "
90 "a valid file name followed by a line number.",
93 filename
, lineno
= result
94 edit
= self
.flist
.open(filename
)
97 def _file_line_helper(self
, line
):
98 for prog
in self
.file_line_progs
:
104 filename
, lineno
= m
.group(1, 2)
106 f
= open(filename
, "r")
111 return filename
, int(lineno
)
115 # These classes are currently not used but might come in handy
117 class OnDemandOutputWindow
:
120 # XXX Should use IdlePrefs.ColorPrefs
121 "stdout": {"foreground": "blue"},
122 "stderr": {"foreground": "#007700"},
125 def __init__(self
, flist
):
129 def write(self
, s
, tags
, mark
):
132 self
.owin
.write(s
, tags
, mark
)
135 self
.owin
= owin
= OutputWindow(self
.flist
)
137 for tag
, cnf
in self
.tagdefs
.items():
139 text
.tag_configure(tag
, **cnf
)
140 text
.tag_raise('sel')
141 self
.write
= self
.owin
.write
145 # def __init__(self, owin, tags, mark="end"):
150 # def write(self, s):
151 # self.owin.write(s, self.tags, self.mark)
153 # def writelines(self, l):