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.

51 lines
1.2 KiB

from PyQt5.QtWidgets import QErrorMessage
from clusterview.mode import Mode
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
class InvalidMode(Exception):
"""
An exception to specify an invalid mode has been provided.
"""
_exc = None
def __init__(self, mode):
"""
Initializes the InvalidMode exception with a
mode.
"""
if type(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.")