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