Browse Source

Add some stubbing for points

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
52d9878580
  1. 47
      clusterview/exceptions.py
  2. 35
      clusterview/mode.py
  3. 35
      main_window.py
  4. 8
      requirements.txt

47
clusterview/exceptions.py

@ -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")

35
clusterview/mode.py

@ -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
}

35
main_window.py

@ -4,18 +4,8 @@ from enum import Enum
from PyQt5 import QtWidgets, uic
from clusterview_ui import Ui_MainWindow
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
from clusterview.exceptions import handle_exceptions, InvalidMode
from clusterview.mode import Mode, MODE_MAP
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
"""
@ -38,22 +28,27 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.action_delete_points.triggered.connect(self.__delete_points)
self.action_solve.triggered.connect(self.__solve_launcher)
# Override handler for mouse press so we can draw points based on
# the OpenGL coordinate system inside of the OpenGL Widget.
self.opengl_widget.mousePressEvent = self.__ogl_click_dispatcher
# TODO: These handlers should probably be broken out into classes
# Such as "GraphicsDrawer", etc that implements these functions
# in isolation so this file remains relatively clean aside from
# the UI hooks to the functions above.
def __add_points(self):
self.__mode = Mode.ADD
print("ADDING POINT MODE ENABLED!")
# Should change the on-hover mouse to something else.
def __edit_points(self):
self.__mode = Mode.EDIT
print("EDITING POINT MODE ENABLED!")
# Should change the on-hover mouse to something else.
def __delete_points(self):
self.__mode = Mode.DELETE
print("DELETE POINT MODE ENABLED!")
# Should change the on-hover mouse to something else.
@handle_exceptions
def __solve_launcher(self):
"""
Launched the solve menu. This function will call into a subclass
@ -63,3 +58,13 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
solve window.
"""
print("LAUNCHING SOLVE DIALOG...")
def __ogl_click_dispatcher(self, event):
"""
Mode dispatcher for click actions on the OpenGL widget.
"""
if self.__mode == Mode.OFF:
raise InvalidMode(Mode.OFF)
MODE_MAP[self.__mode](self.opengl_widget, event)

8
requirements.txt

@ -1,14 +1,22 @@
backcall==0.1.0
Cython==0.29.13
decorator==4.4.0
entrypoints==0.3
flake8==3.7.8
ipython==7.7.0
ipython-genutils==0.2.0
jedi==0.14.1
mccabe==0.6.1
parso==0.5.1
pexpect==4.7.0
pickleshare==0.7.5
prompt-toolkit==2.0.9
ptyprocess==0.6.0
pycodestyle==2.5.0
pyflakes==2.1.1
Pygments==2.4.2
PyOpenGL==3.1.0
PyOpenGL-accelerate==3.1.3b1
PyQt5==5.13.0
PyQt5-sip==4.19.18
six==1.12.0

Loading…
Cancel
Save