utils.py 661 Bytes
Newer Older
1
from qtpy.QtWidgets import QErrorMessage
2
3
4
5
6
7
from traceback import format_exc

def handle_error(fn):
    def wrapper(self, *args, **kwargs):
        try:
            return fn(self, *args, **kwargs)
Oscar Gustafsson's avatar
Oscar Gustafsson committed
8
        except Exception:
9
            self._window.logger.error(f"Unexpected error: {format_exc()}")
Oscar Gustafsson's avatar
Oscar Gustafsson committed
10
11
            QErrorMessage(self._window).showMessage(
                f"Unexpected error: {format_exc()}")
12
13
14
15
16
17
18
19
20

    return wrapper

def decorate_class(decorator):
    def decorate(cls):
        for attr in cls.__dict__:
            if callable(getattr(cls, attr)):
                setattr(cls, attr, decorator(getattr(cls, attr)))
        return cls
Oscar Gustafsson's avatar
Oscar Gustafsson committed
21
    return decorate