Taylor Bockman
5 years ago
4 changed files with 110 additions and 15 deletions
@ -0,0 +1,47 @@
|
||||
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(*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. |
||||
""" |
||||
super().__init__("You must select a mode before continuing.") |
||||
if type(mode) != Mode: |
||||
raise ValueError("Mode argument to InvalidMode must be of "+ |
||||
" type mode") |
@ -0,0 +1,35 @@
|
||||
from enum import Enum |
||||
|
||||
class Mode(Enum): |
||||
""" |
||||
Class to make it easier to figure out what mode |
||||
we are operating in when the OpenGL window is |
||||
clicked. |
||||
""" |
||||
OFF = 0 |
||||
ADD = 1 |
||||
EDIT = 2 |
||||
DELETE = 3 |
||||
|
||||
def __handle_add_point(ctx, event): |
||||
""" |
||||
TODO: These functions should all take a context to |
||||
the openGL widget that will perform the |
||||
function. |
||||
""" |
||||
print("GOT POINT: ({}, {})".format(event.x(), event.y())) |
||||
|
||||
def __handle_edit_point(ctx, event): |
||||
print("GOT POINT: ({}, {})".format(event.x(), event.y())) |
||||
|
||||
def __handle_delete_point(ctx, event): |
||||
print("GOT POINT: ({}, {})".format(event.x(), event.y())) |
||||
|
||||
|
||||
# Simple dispatch to make life easy for the window. |
||||
MODE_MAP = { |
||||
Mode.OFF: lambda: None, |
||||
Mode.ADD: __handle_add_point, |
||||
Mode.EDIT: __handle_edit_point, |
||||
Mode.DELETE: __handle_delete_point |
||||
} |
Loading…
Reference in new issue