-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_utils.py
More file actions
19 lines (15 loc) · 755 Bytes
/
ui_utils.py
File metadata and controls
19 lines (15 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from PyQt6.QtWidgets import QWidget, QMessageBox
class ExceptionCatcher:
def __init__(self, context: QWidget | None, message: str):
self.context = context
self.message = message
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, traceback):
if exc_type:
import traceback as tb
except_string = '\n'.join(tb.format_exception(exc_type, exc_value, traceback))
QMessageBox.critical(self.context, f"Error: {exc_type}", f"{self.message}: {exc_value}\n"
f"\n" +
except_string)
return True # Suppress exceptions