diff --git a/clusterview/exceptions.py b/clusterview/exceptions.py index 149a370..bd18e46 100644 --- a/clusterview/exceptions.py +++ b/clusterview/exceptions.py @@ -20,7 +20,7 @@ def handle_exceptions(func): """ def wrapped(self, *args, **kwargs): try: - return func(*args, **kwargs) + return func(self, *args, **kwargs) except Exception as e: error_dialog = QErrorMessage() error_dialog.showMessage(str(e)) @@ -41,7 +41,11 @@ class InvalidMode(Exception): 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") + + # Mode cases for invalid mode + if mode == Mode.OFF: + super().__init__("You must select a mode before continuing.") diff --git a/clusterview/mode.py b/clusterview/mode.py index a7180e5..05ff71c 100644 --- a/clusterview/mode.py +++ b/clusterview/mode.py @@ -17,16 +17,26 @@ def __handle_add_point(ctx, event): the openGL widget that will perform the function. """ - print("GOT POINT: ({}, {})".format(event.x(), event.y())) + print("[ADD] GOT POINT: ({}, {})".format(event.x(), event.y())) def __handle_edit_point(ctx, event): - print("GOT POINT: ({}, {})".format(event.x(), event.y())) + # TODO: This function and delete definitely need to make sure they are + # on a point we have. + # + # Since points are unique consider a hashmap of points to make O(1) + # lookups for addition and deletion. This list can be maintained here + # in this module. It should be a dictionary - from point to + # attributes in the case of algorithms that require points to have + # weights or something. + # + print("[EDIT] GOT POINT: ({}, {})".format(event.x(), event.y())) def __handle_delete_point(ctx, event): - print("GOT POINT: ({}, {})".format(event.x(), event.y())) + print("[DELETE] GOT POINT: ({}, {})".format(event.x(), event.y())) -# Simple dispatch to make life easy for the window. +# Simple dispatcher to make it easy to dispatch the right mode +# function when the OpenGL window is clicked. MODE_MAP = { Mode.OFF: lambda: None, Mode.ADD: __handle_add_point, diff --git a/main_window.py b/main_window.py index 3a7871b..a9b5f08 100644 --- a/main_window.py +++ b/main_window.py @@ -38,15 +38,15 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # the UI hooks to the functions above. def __add_points(self): self.__mode = Mode.ADD - # Should change the on-hover mouse to something else. + # Should change the mouse icon to something else that indicates adding. def __edit_points(self): self.__mode = Mode.EDIT - # Should change the on-hover mouse to something else. + # Should change the mouse icon to something else that indicates editing. def __delete_points(self): self.__mode = Mode.DELETE - # Should change the on-hover mouse to something else. + # Should change the mouse icon to osmething else that indicates deleting. @handle_exceptions def __solve_launcher(self): @@ -60,6 +60,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): print("LAUNCHING SOLVE DIALOG...") + @handle_exceptions def __ogl_click_dispatcher(self, event): """ Mode dispatcher for click actions on the OpenGL widget.