6 from Carbon
import List
11 def __init__(self
, title
= "Traceback"):
12 app
= W
.getapplication() # checks if W is properly initialized
17 self
.lastwindowtitle
= ""
18 self
.bounds
= (360, 298)
20 def traceback(self
, start
= 0, lastwindowtitle
= ""):
22 self
.lastwindowtitle
= lastwindowtitle
24 self
.type, self
.value
, self
.tb
= sys
.exc_info()
25 if self
.type is not SyntaxError:
27 if type(self
.type) == types
.ClassType
:
28 errortext
= self
.type.__name
__
30 errortext
= str(self
.type)
31 value
= str(self
.value
)
32 if self
.value
and value
:
33 errortext
= errortext
+ ": " + value
34 self
.w
.text
.set(errortext
)
36 self
.w
.list.set(self
.textlist
)
37 self
.w
.list.setselection([len(self
.textlist
) - 1])
38 self
.w
.wid
.SelectWindow()
45 def syntaxerror(self
):
47 value
, (filename
, lineno
, charno
, line
) = self
.value
52 if not filename
and self
.lastwindowtitle
:
53 filename
= self
.lastwindowtitle
55 filename
= "<unknown>"
56 if filename
and os
.path
.exists(filename
):
57 filename
= os
.path
.split(filename
)[1]
58 if lineno
and charno
is not None:
60 text
= str(value
) + '\rFile: "' + str(filename
) + '", line ' + str(lineno
) + '\r\r' + line
[:charno
] + "\xa5" + line
[charno
:-1]
62 text
= str(value
) + '\rFile: "' + str(filename
) + '"'
63 self
.syntaxdialog
= W
.ModalDialog((360, 120), "Syntax Error")
64 self
.syntaxdialog
.text
= W
.TextBox((10, 10, -10, -40), text
)
65 self
.syntaxdialog
.cancel
= W
.Button((-190, -32, 80, 16), "Cancel", self
.syntaxclose
)
66 self
.syntaxdialog
.edit
= W
.Button((-100, -32, 80, 16), "Edit", self
.syntaxedit
)
67 self
.syntaxdialog
.setdefaultbutton(self
.syntaxdialog
.edit
)
68 self
.syntaxdialog
.bind("cmd.", self
.syntaxdialog
.cancel
.push
)
69 self
.syntaxdialog
.open()
71 def syntaxclose(self
):
72 self
.syntaxdialog
.close()
77 value
, (filename
, lineno
, charno
, line
) = self
.value
81 if not filename
and self
.lastwindowtitle
:
82 filename
= self
.lastwindowtitle
84 filename
= "<unknown>"
89 W
.getapplication().openscript(filename
, lineno
, charno
- 1)
91 W
.getapplication().openscript(filename
)
98 self
.w
.wid
.ShowWindow()
99 self
.w
.wid
.SelectWindow()
107 self
.bounds
= self
.w
.getbounds()
109 self
.type, self
.value
, self
.tb
= None, None, None
112 def activate(self
, onoff
):
119 def setupwidgets(self
):
120 self
.w
= W
.Window(self
.bounds
, self
.title
, minsize
= (316, 168))
121 self
.w
.text
= W
.TextBox((10, 10, -10, 30))
122 self
.w
.tbtitle
= W
.TextBox((10, 40, -10, 10), "Traceback (innermost last):")
123 self
.w
.list = W
.TwoLineList((10, 60, -10, -40), callback
= self
.listhit
)
125 self
.w
.editbutton
= W
.Button((10, -30, 60, 16), "Edit", self
.edit
)
126 self
.w
.editbutton
.enable(0)
128 self
.w
.browselocalsbutton
= W
.Button((80, -30, 100, 16), "Browse locals\xc9", self
.browselocals
)
129 self
.w
.browselocalsbutton
.enable(0)
131 self
.w
.postmortembutton
= W
.Button((190, -30, 100, 16), "Post mortem\xc9", self
.postmortem
)
133 self
.w
.setdefaultbutton(self
.w
.editbutton
)
134 self
.w
.bind("cmdb", self
.w
.browselocalsbutton
.push
)
135 self
.w
.bind("<close>", self
.close
)
136 self
.w
.bind("<activate>", self
.activate
)
138 def buildtblist(self
):
140 for i
in range(self
.start
):
141 if tb
.tb_next
is None:
144 self
.tblist
= traceback
.extract_tb(tb
)
146 for filename
, lineno
, func
, line
in self
.tblist
:
148 if os
.path
.exists(filename
):
149 filename
= os
.path
.split(filename
)[1]
150 tbline
= 'File "%s", line %r, in %r' % (filename
, lineno
, func
)
152 tbline
= tbline
+ '\r ' + line
153 self
.textlist
.append(tbline
[:255])
156 sel
= self
.w
.list.getselection()
158 filename
, lineno
, func
, line
= self
.tblist
[i
]
159 W
.getapplication().openscript(filename
, lineno
)
161 def browselocals(self
):
162 sel
= self
.w
.list.getselection()
165 for j
in range(i
+ self
.start
):
167 self
.browse(tb
.tb_frame
.f_locals
)
169 def browse(self
, object):
171 PyBrowser
.Browser(object)
173 def postmortem(self
):
175 PyDebugger
.postmortem(self
.type, self
.value
, self
.tb
)
177 def listhit(self
, isdbl
):
179 self
.w
.editbutton
.push()
183 def checkbuttons(self
):
184 havefile
= len(self
.w
.list.getselection()) > 0
185 self
.w
.editbutton
.enable(havefile
)
186 self
.w
.browselocalsbutton
.enable(havefile
)
187 self
.w
.setdefaultbutton(havefile
and self
.w
.editbutton
or self
.w
.postmortembutton
)