A computational geometry learning and experimentation tool.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

from PyQt5.QtWidgets import QErrorMessage
from .mode import Mode
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(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
error_dialog = QErrorMessage()
error_dialog.showMessage(str(e))
error_dialog.exec_()
return wrapped