|
1 | 1 | import sys |
2 | | -import traceback |
3 | 2 | import typing as t |
4 | 3 | from pathlib import Path |
5 | 4 | from types import TracebackType |
|
45 | 44 | import construct_editor.gallery.test_tflagsenum |
46 | 45 | import construct_editor.gallery.test_timestamp |
47 | 46 | from construct_editor.wx_widgets import WxConstructHexEditor |
| 47 | +from construct_editor.wx_widgets.wx_exception_dialog import ( |
| 48 | + ExceptionInfo, |
| 49 | + WxExceptionDialog, |
| 50 | +) |
48 | 51 |
|
49 | 52 |
|
50 | 53 | class ConstructGalleryFrame(wx.Frame): |
@@ -75,7 +78,9 @@ def on_uncaught_exception( |
75 | 78 | :param string `trace`: the traceback header, if any (otherwise, it prints the |
76 | 79 | standard Python header: ``Traceback (most recent call last)``. |
77 | 80 | """ |
78 | | - dial = ExceptionDialog(None, etype, value, trace) |
| 81 | + dial = WxExceptionDialog( |
| 82 | + None, "Uncaught Exception...", ExceptionInfo(etype, value, trace) |
| 83 | + ) |
79 | 84 | dial.ShowModal() |
80 | 85 |
|
81 | 86 |
|
@@ -396,73 +401,6 @@ def on_load_binary_file_clicked(self, event): |
396 | 401 | ) |
397 | 402 |
|
398 | 403 |
|
399 | | -class ExceptionDialog(wx.Dialog): |
400 | | - def __init__( |
401 | | - self, |
402 | | - parent, |
403 | | - etype: t.Type[BaseException], |
404 | | - value: BaseException, |
405 | | - trace: TracebackType, |
406 | | - ): |
407 | | - wx.Dialog.__init__( |
408 | | - self, |
409 | | - parent, |
410 | | - id=wx.ID_ANY, |
411 | | - title="Uncaught Exception...", |
412 | | - pos=wx.DefaultPosition, |
413 | | - size=wx.Size(800, 600), |
414 | | - style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, |
415 | | - ) |
416 | | - |
417 | | - self._init_gui() |
418 | | - |
419 | | - self.exception_txt.SetValue( |
420 | | - "".join(traceback.format_exception_only(etype, value)) |
421 | | - ) |
422 | | - self.traceback_txt.SetValue("".join(traceback.format_tb(trace))) |
423 | | - |
424 | | - def _init_gui(self): |
425 | | - self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) |
426 | | - |
427 | | - sizer = wx.BoxSizer(wx.VERTICAL) |
428 | | - |
429 | | - self.ok_btn = wx.Button( |
430 | | - self, wx.ID_ANY, "OK", wx.DefaultPosition, wx.DefaultSize, 0 |
431 | | - ) |
432 | | - sizer.Add(self.ok_btn, 0, wx.ALL | wx.EXPAND, 5) |
433 | | - |
434 | | - self.exception_txt = wx.TextCtrl( |
435 | | - self, |
436 | | - wx.ID_ANY, |
437 | | - wx.EmptyString, |
438 | | - wx.DefaultPosition, |
439 | | - wx.Size(-1, -1), |
440 | | - wx.TE_MULTILINE | wx.TE_READONLY, |
441 | | - ) |
442 | | - sizer.Add(self.exception_txt, 1, wx.ALL | wx.EXPAND, 5) |
443 | | - |
444 | | - self.traceback_txt = wx.TextCtrl( |
445 | | - self, |
446 | | - wx.ID_ANY, |
447 | | - wx.EmptyString, |
448 | | - wx.DefaultPosition, |
449 | | - wx.Size(-1, -1), |
450 | | - wx.TE_MULTILINE | wx.TE_READONLY, |
451 | | - ) |
452 | | - sizer.Add(self.traceback_txt, 2, wx.ALL | wx.EXPAND, 5) |
453 | | - |
454 | | - self.SetSizer(sizer) |
455 | | - self.Layout() |
456 | | - |
457 | | - self.Centre(wx.BOTH) |
458 | | - |
459 | | - # Connect Events |
460 | | - self.ok_btn.Bind(wx.EVT_BUTTON, self.on_ok_clicked) |
461 | | - |
462 | | - def on_ok_clicked(self, event): |
463 | | - self.Close() |
464 | | - |
465 | | - |
466 | 404 | def main(): |
467 | 405 | if sys.platform == "win32": |
468 | 406 | # Windows Icon fix: https://stackoverflow.com/a/1552105 |
|
0 commit comments