35 import wx |
35 import wx |
36 |
36 |
37 Max_Traceback_List_Size = 20 |
37 Max_Traceback_List_Size = 20 |
38 |
38 |
39 |
39 |
40 def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path): |
40 def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path, exit): |
41 trcbck_lst = [] |
41 trcbck_lst = [] |
42 for i, line in enumerate(traceback.extract_tb(e_tb)): |
42 for i, line in enumerate(traceback.extract_tb(e_tb)): |
43 trcbck = " " + str(i+1) + ". " |
43 trcbck = " " + str(i+1) + ". " |
44 if line[0].find(os.getcwd()) == -1: |
44 if line[0].find(os.getcwd()) == -1: |
45 trcbck += "file : " + str(line[0]) + ", " |
45 trcbck += "file : " + str(line[0]) + ", " |
123 lst.sort() |
125 lst.sort() |
124 for a in lst: |
126 for a in lst: |
125 output.write(a + ":\n" + str(info[a]) + "\n\n") |
127 output.write(a + ":\n" + str(info[a]) + "\n\n") |
126 output.close() |
128 output.close() |
127 |
129 |
128 def handle_exception(e_type, e_value, e_traceback): |
130 def handle_exception(e_type, e_value, e_traceback, exit = False): |
129 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
131 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
130 last_tb = get_last_traceback(e_traceback) |
132 last_tb = get_last_traceback(e_traceback) |
131 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
133 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
132 if ex not in ignored_exceptions: |
134 if ex not in ignored_exceptions: |
133 ignored_exceptions.append(ex) |
135 ignored_exceptions.append(ex) |
134 date = time.ctime() |
136 date = time.ctime() |
135 path = tempfile.gettempdir()+os.sep+wx.GetApp().GetAppName() |
137 path = tempfile.gettempdir()+os.sep+wx.GetApp().GetAppName() |
136 bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt" |
138 bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt" |
137 save_bug_report(e_type, e_value, e_traceback, bug_report_path, date) |
139 save_bug_report(e_type, e_value, e_traceback, bug_report_path, date) |
138 Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path) |
140 wx.CallAfter(Display_Exception_Dialog, e_type, e_value, e_traceback, bug_report_path, exit) |
139 # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
141 # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
140 sys.excepthook = handle_exception |
142 sys.excepthook = handle_exception |
141 |
143 |
142 init_old = threading.Thread.__init__ |
144 init_old = threading.Thread.__init__ |
143 |
145 |