dcs-retribution/qt_ui/errorreporter.py
Dan Albert 4a7dae9cc2 Upgrade to PySide6.
PySide2 renamed to PySide6 for Qt 6 support. It doesn't seem like
PySide2 is getting a 3.10 wheel, so upgrade to Qt 6 to prep for that.
2021-11-20 19:26:18 -08:00

18 lines
453 B
Python

import logging
from collections.abc import Iterator
from contextlib import contextmanager
from typing import Type
from PySide6.QtWidgets import QDialog, QMessageBox
@contextmanager
def report_errors(
title: str, parent: QDialog, error_type: Type[Exception] = Exception
) -> Iterator[None]:
try:
yield
except error_type as ex:
logging.exception(title)
QMessageBox().critical(parent, title, str(ex), QMessageBox.Ok)