from PyQt5.QtWidgets import QErrorMessage from voronoiview.mode import Mode class ExceededWindowBoundsError(Exception): pass class InvalidStateError(Exception): pass class InvalidModeError(Exception): """ An exception to specify an invalid mode has been provided. """ def __init__(self, mode): """ Initializes the InvalidMode exception with a mode. """ if not isinstance(mode, Mode): raise ValueError('Mode argument to InvalidMode must be of ' + ' type mode') # Mode cases for invalid mode if mode == Mode.OFF: super().__init__('You must select a mode before continuing.') def handle_exceptions(func): """ A decorator designed to make exceptions thrown from a function easier to handle. The result will be that all exceptions coming from the decorated function will be caught and displayed as a error message box. Usage: @handle_exceptions def my_qt_func(): raises SomeException """ def wrapped(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: error_dialog = QErrorMessage() error_dialog.showMessage(str(e)) error_dialog.exec_() return wrapped