Browse Source

Improvements to modes

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
328dfb7aa1
  1. 8
      clusterview/exceptions.py
  2. 18
      clusterview/mode.py
  3. 7
      main_window.py

8
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.")

18
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,

7
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.

Loading…
Cancel
Save