1
# Copyright (C) 2005 by Async Open Source and Sicem S.L.
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU Lesser General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU Lesser General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
class DebugWindow(gtk.Dialog):
32
def __init__(self, parent=None):
33
gtk.Dialog.__init__(self, 'An Error Occurred', parent,
34
gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR)
37
#self.send = self._create_button(gtk.STOCK_NETWORK, _('_Report bug ...'))
38
#self.send.connect('clicked', self._on_send__clicked)
39
#self.action_area.pack_end(self.send)
42
quit = self._create_button(gtk.STOCK_OK, _('_Continue'))
43
self.add_action_widget(quit, gtk.RESPONSE_ACCEPT)
45
self._pwd = os.getcwd()
47
def _create_button(self, stock, text):
49
#a = gtk.Alignment(0.5, 0.5, 1.0, 1.0)
53
i.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
56
l.set_use_underline(True)
65
# 416 = 600 / sqrt(2) = golden number
66
self.set_default_size(600, 416)
67
self.set_border_width(12)
70
self.vbox.pack_start(hbox, False, False)
71
self.vbox.set_spacing(6)
72
lbl = gtk.Label('<b>Exception type:</b>')
73
lbl.set_use_markup(True)
74
hbox.pack_start(lbl, False, False, 6)
76
self._info_label = gtk.Label()
77
hbox.pack_start(self._info_label, False, False)
78
self._info_label.show()
81
self.notebook = gtk.Notebook()
82
self.vbox.pack_start(self.notebook)
84
sw = gtk.ScrolledWindow()
85
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
86
sw.set_shadow_type(gtk.SHADOW_IN)
89
self._buffer = gtk.TextBuffer()
90
self._buffer.create_tag('filename', style=pango.STYLE_ITALIC, foreground='gray20')
91
self._buffer.create_tag('name', foreground='#000055')
92
self._buffer.create_tag('lineno', weight=pango.WEIGHT_BOLD)
93
self._buffer.create_tag('exc', foreground='#880000', weight=pango.WEIGHT_BOLD)
95
self._textview = gtk.TextView(self._buffer)
96
self._textview.set_editable(False)
97
self._textview.set_cursor_visible(False)
98
sw.add(self._textview)
101
self.notebook.append_page(sw, tab_label=gtk.Label("Exception"))
104
lsw = gtk.ScrolledWindow()
105
lsw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
106
lsw.set_shadow_type(gtk.SHADOW_IN)
107
self._lbuf = gtk.TextBuffer()
108
self._lview = gtk.TextView(self._lbuf)
110
self.notebook.append_page(lsw, tab_label=gtk.Label("Log"))
112
isw = gtk.ScrolledWindow()
113
isw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
114
isw.set_shadow_type(gtk.SHADOW_IN)
115
self._ibuf = gtk.TextBuffer()
116
self._iview = gtk.TextView(self._ibuf)
119
self.notebook.append_page(isw, tab_label=gtk.Label("Stdio"))
121
self.notebook.show_all()
123
def show_exception(self, exctype, value, tb):
124
self._info_label.set_text(str(exctype))
126
lines = traceback.format_exception_only(exctype, value)
128
msg = traceback.format_exception_only(exctype, value)[0]
129
result = msg.split(' ', 1)
134
msg, arguments = result
135
self._insert(msg, 'exc')
136
self._insert(' ' + arguments)
141
logfn = self.application.registry.files.log.value()
142
iofn = '%s.io' % logfn
143
lf = open(logfn, 'r')
144
self._lbuf.set_text(lf.read())
147
self._ibuf.set_text(of.read())
150
def _print(self, line):
151
self._buffer.insert_at_cursor(line + '\n')
153
def _insert(self, text, *tags):
154
end_iter = self._buffer.get_end_iter()
155
self._buffer.insert_with_tags_by_name(end_iter, text, *tags)
157
def _print_file(self, filename, lineno, name):
158
if filename.startswith(self._pwd):
159
filename = filename.replace(self._pwd, '')[1:]
161
self._insert(' File ')
162
self._insert(filename, 'filename')
163
self._insert(', line ')
164
self._insert(str(lineno), 'lineno')
165
self._insert(', in ')
166
self._insert(name, 'name')
169
def print_tb(self, tb, limit=None):
170
"""Print up to 'limit' stack trace entries from the traceback 'tb'.
172
If 'limit' is omitted or None, all entries are printed. If 'file'
173
is omitted or None, the output goes to sys.stderr; otherwise
174
'file' should be an open file or file-like object with a write()
179
if hasattr(sys, 'tracebacklimit'):
180
limit = sys.tracebacklimit
182
while tb is not None and (limit is None or n < limit):
184
lineno = tb.tb_lineno
186
filename = co.co_filename
188
self._print_file(filename, lineno, name)
189
line = linecache.getline(filename, lineno)
191
self._print(' ' + line.strip())
195
def _start_debugger(self):
199
def _on_send__clicked(self, button):
200
exception_text = self._buffer.get_text(*self._buffer.get_bounds())
201
if DebugWindow.application.send_bugreport(exception_text, self):
202
# the bug was sent and we don't want the user to send it again
203
self.send.set_sensitive(False)
205
def _on_save__clicked(self, button):
206
DebugWindow.application._save_cb(None)
208
def _should_save_be_sensitive(self):
209
#if not DebugWindow.application._project:
212
#if not DebugWindow.application._project._changed:
217
def show(exctype, value, tb):
218
if exctype is not KeyboardInterrupt:
220
dw.show_exception(exctype, value, tb)
227
dw.notebook.set_current_page(1)
231
if __name__ == '__main__':