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.
81 lines
2.8 KiB
81 lines
2.8 KiB
import os |
|
from enum import Enum |
|
|
|
from PyQt5.QtCore import Qt |
|
from PyQt5.QtGui import QCursor |
|
from PyQt5 import QtWidgets, uic |
|
|
|
from clusterview_ui import Ui_MainWindow |
|
from clusterview.exceptions import handle_exceptions, InvalidMode |
|
from clusterview.mode import Mode, MODE_MAP |
|
|
|
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): |
|
""" |
|
A wrapper class for handling creating a window based |
|
on the `clusterview_ui.py` code generated from |
|
`clusterview.ui`. |
|
""" |
|
|
|
__mode = Mode.OFF |
|
|
|
def __init__(self, parent=None): |
|
super(MainWindow, self).__init__(parent) |
|
self.setupUi(self) |
|
|
|
# ------------------------------------- |
|
# UI Handlers |
|
# ------------------------------------- |
|
self.action_add_points.triggered.connect(self.__add_points) |
|
self.action_edit_points.triggered.connect(self.__edit_points) |
|
self.action_delete_points.triggered.connect(self.__delete_points) |
|
self.action_move_points.triggered.connect(self.__move_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 |
|
|
|
#----------------------------------------------------------------- |
|
# Mode changers - these will be used to signal the action in the |
|
# OpenGL Widget. |
|
#----------------------------------------------------------------- |
|
def __add_points(self): |
|
self.__mode = Mode.ADD |
|
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor)) |
|
|
|
def __edit_points(self): |
|
self.__mode = Mode.EDIT |
|
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor)) |
|
|
|
def __delete_points(self): |
|
self.__mode = Mode.DELETE |
|
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) |
|
|
|
def __move_points(self): |
|
self.__mode = Mode.MOVE |
|
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.SizeAllCursor)) |
|
|
|
@handle_exceptions |
|
def __solve_launcher(self): |
|
""" |
|
Launched the solve menu. This function will call into a subclass |
|
of the solve dialog widget from the UI. |
|
|
|
TODO: Write the subclass once you know the parameters for the |
|
solve window. |
|
""" |
|
print("LAUNCHING SOLVE DIALOG...") |
|
|
|
|
|
@handle_exceptions |
|
def __ogl_click_dispatcher(self, event): |
|
""" |
|
Mode dispatcher for click actions on the OpenGL widget. |
|
""" |
|
if self.__mode == Mode.OFF: |
|
raise InvalidMode(Mode.OFF) |
|
|
|
# Map from Mode -> function |
|
# where the function is a handler for the |
|
# OpenGL Widget. |
|
MODE_MAP[self.__mode](self.opengl_widget, event)
|
|
|