1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import gettext
26 import linecache
27 import os
28 import sys
29 import traceback
30
31 import pango
32 import gtk
33 from kiwi.ui.dialogs import HIGAlertDialog
34
35 _ = gettext.gettext
36
37
38 FILENAME_COLOR = 'gray20'
39 NAME_COLOR = '#000055'
40 EXCEPTION_COLOR = '#880000'
41
42
44
46 exctype, value, tb = excTuple
47 self._exctype = exctype
48 self._tb = tb
49 self._value = value
50
51 gtk.ScrolledWindow.__init__(self)
52 self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
53 self.set_shadow_type(gtk.SHADOW_ETCHED_IN)
54 self._createUI()
55 self._showException()
56
58 self._buffer = gtk.TextBuffer()
59 self._buffer.create_tag('filename', style=pango.STYLE_ITALIC,
60 foreground=FILENAME_COLOR)
61 self._buffer.create_tag('name', foreground=NAME_COLOR)
62 self._buffer.create_tag('lineno', weight=pango.WEIGHT_BOLD)
63 self._buffer.create_tag('exc', foreground=EXCEPTION_COLOR,
64 weight=pango.WEIGHT_BOLD)
65
66 textView = gtk.TextView(self._buffer)
67 self.add(textView)
68 textView.show()
69
71 self._buffer.insert_at_cursor(line + '\n')
72
81
82 - def _insertText(self, text, tagName=None):
83 end_iter = self._buffer.get_end_iter()
84 if tagName:
85 self._buffer.insert_with_tags_by_name(end_iter, text, tagName)
86 else:
87 self._buffer.insert(end_iter, text)
88
90 """Print up to 'limit' stack trace entries from the traceback 'tb'.
91
92 If 'limit' is omitted or None, all entries are printed. If 'file'
93 is omitted or None, the output goes to sys.stderr; otherwise
94 'file' should be an open file or file-like object with a write()
95 method.
96 """
97
98 for tb in self._getTracebacks():
99 co = tb.tb_frame.f_code
100 self._printFile(co.co_filename, tb.tb_lineno, co.co_name)
101 line = linecache.getline(co.co_filename, tb.tb_lineno)
102 if line:
103 self._print(' ' + line.strip())
104
106 widget = gtk.grab_get_current()
107 if widget is not None:
108 widget.grab_remove()
109
110 self._printTraceback()
111 msg = traceback.format_exception_only(self._exctype, self._value)[0]
112 result = msg.split(' ', 1)
113 if len(result) == 1:
114 msg = result[0]
115 arguments = ''
116 else:
117 msg, arguments = result
118 self._insertText(msg, 'exc')
119 self._insertText(' ' + arguments)
120
121
122 vadj = self.get_vadjustment()
123 vadj.set_value(vadj.upper)
124
126 if limit is None:
127 limit = getattr(sys, 'tracebacklimit', None)
128
129 n = 0
130 tb = self._tb
131 while tb is not None:
132 if limit is not None and n >= limit:
133 break
134 n += 1
135
136 yield tb
137 tb = tb.tb_next
138
139
140
149
151 return self._buffer.get_text(*self._buffer.get_bounds())
152
160
161
163 """I am a dialog that can display a python exception
164 and code to report a bug.
165 """
166 RESPONSE_BUG = 1
167
169 """
170 @param excTuple:
171 @type excTuple:
172 """
173 toplevels = gtk.window_list_toplevels()
174 if toplevels:
175
176 parent = toplevels[0]
177 else:
178 parent = None
179 HIGAlertDialog.__init__(self,
180 parent=parent,
181 flags=gtk.DIALOG_MODAL,
182 type=gtk.MESSAGE_ERROR,
183 buttons=gtk.BUTTONS_NONE)
184 self.set_primary(_("A programming error occurred."))
185 self.add_button(_("Report a bug"), ExceptionDialog.RESPONSE_BUG)
186 self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
187 self.set_default_response(gtk.RESPONSE_CLOSE)
188
189 self._dw = self._createTracebackViewer(excTuple)
190 self.set_details_widget(self._dw)
191
192
193 expander = self._dw.get_parent()
194 expander.set_label(_("Show debug information"))
195
197 dw = TracebackViewer(excTuple)
198
199
200 dw.set_size_request(500, 200)
201 dw.show()
202 return dw
203
206
209
212