Browse Source

Some more work, moving still wonky but escape works now

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
5131f4e77c
  1. 43
      clusterview/mode_handlers.py
  2. 29
      clusterview/opengl_widget.py
  3. 24
      main_window.py

43
clusterview/mode_handlers.py

@ -83,6 +83,7 @@ def __handle_add_point(ctx, event):
__refresh_point_list(ctx) __refresh_point_list(ctx)
set_drawing_event(event) set_drawing_event(event)
set_current_points(__point_set) set_current_points(__point_set)
ctx.opengl_widget.update() ctx.opengl_widget.update()
@ -111,6 +112,30 @@ def __handle_edit_point(ctx, event):
# after this remove the point from the list # after this remove the point from the list
def ogl_keypress_handler(ctx, event):
"""
A keypress handler attached to the OpenGL widget.
It primarily exists to allow the user to cancel
selection with ESC.
@param ctx A handle to the window context.
@param event The event associated with this handler.
"""
global __left_click_flag
global __mouse_start
if (__left_click_flag is not __ClickFlag.NONE
and event.key() == Qt.Key_Escape):
__mouse_start = None
__left_click_flag = __ClickFlag.NONE
__point_set.clear_selection()
reset_move_bbs()
ctx.opengl_widget.update()
def __handle_move_points(ctx, event): def __handle_move_points(ctx, event):
""" """
A relatively complicated state machine that handles the process of A relatively complicated state machine that handles the process of
@ -126,7 +151,8 @@ def __handle_move_points(ctx, event):
set_drawing_event(event) set_drawing_event(event)
print(event.type()) # Necessary to capture keyboard events
ctx.opengl_widget.setFocusPolicy(Qt.StrongFocus)
# This if statement block is used to set the bounding box for # This if statement block is used to set the bounding box for
# drawing and call the selection procedure. # drawing and call the selection procedure.
@ -142,8 +168,6 @@ def __handle_move_points(ctx, event):
# tracking and translation # tracking and translation
__left_click_flag = __ClickFlag.SELECTION_MOVE __left_click_flag = __ClickFlag.SELECTION_MOVE
__mouse_start = (event.x(), event.y()) __mouse_start = (event.x(), event.y())
else:
__left_click_flag = __ClickFlag.NONE
elif (__left_click_flag is __ClickFlag.SELECTION_BOX elif (__left_click_flag is __ClickFlag.SELECTION_BOX
and event.type() == QEvent.MouseMove): and event.type() == QEvent.MouseMove):
@ -191,20 +215,7 @@ def __handle_move_points(ctx, event):
# Satisfy the post condition by resetting the bounding box # Satisfy the post condition by resetting the bounding box
reset_move_bbs() reset_move_bbs()
elif (__left_click_flag is not __ClickFlag.NONE
and event.type() == QEvent.KeyPress
and event.key() == Qt.Key_Escape):
# TODO: THIS KEY PRESS IS BROKEN AND THE CLICK TO CANCEL BEHAVIOR
# NEED TO BE REMOVED. YOU NEED TO OVERWRITE THE KEY PRESS
# EVENT ON THE OPENGL WIDGET. IF MODE IS MOVE AND ESCAPE IS
# PRESSED CANCEL ALL SELECTIONS!!
if __left_click_flag is __ClickFlag.SELECTION_MOVE:
__mouse_start = None
__left_click_flag = __ClickFlag.NONE
__point_set.clear_selection()
ctx.point_list_widget.update() ctx.point_list_widget.update()
ctx.opengl_widget.update() ctx.opengl_widget.update()

29
clusterview/opengl_widget.py

@ -201,8 +201,7 @@ def paint_gl():
""" """
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.MOVE, Mode.DELETE] and if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.MOVE, Mode.DELETE] and
__current_event is None): __current_event is None):
raise InvalidStateError("Event must exist for ADD, EDIT, MOVE, " + return
"and DELETE")
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and
__current_points is None): __current_points is None):
@ -235,19 +234,6 @@ def paint_gl():
highlight_selection() highlight_selection()
draw_points(__current_points, Color.GREY) draw_points(__current_points, Color.GREY)
if __move_bb_top_left is None and __move_bb_bottom_right is None:
# Currently this fires all the time - not great. Needs to only fire
# when, additionally, we have a selection chosen based on the box
# calculated in the mode handlers.
None
# Once the selection boxes go to None begin the highlight selected
# points procedure. This will store a point list of selected points
# highlight them, etc.
# Once thats done moving points will be difficult but do-able.
elif __current_mode is Mode.DELETE:
raise NotImplementedError("Drawing for DELETE not implemented.")
def __clamp_x(x): def __clamp_x(x):
""" """
@ -368,6 +354,19 @@ def draw_selection_box(color):
glEnd() glEnd()
def clear_selection():
"""
A helper designed to be called from the main window
in order to clear the selection internal to the graphics
and mode files. This way you dont have to do something
before the selection clears.
"""
global __current_points
if __current_points is not None:
__current_points.clear_selection()
def draw_points(point_set, color): def draw_points(point_set, color):
""" """
Simple point drawing function. Simple point drawing function.

24
main_window.py

@ -1,5 +1,6 @@
import os
from enum import Enum from enum import Enum
from functools import partial
import os
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
@ -7,8 +8,9 @@ from PyQt5 import QtWidgets, uic
from clusterview.exceptions import handle_exceptions, InvalidModeError from clusterview.exceptions import handle_exceptions, InvalidModeError
from clusterview.mode import Mode from clusterview.mode import Mode
from clusterview.mode_handlers import MODE_HANDLER_MAP from clusterview.mode_handlers import MODE_HANDLER_MAP, ogl_keypress_handler
from clusterview.opengl_widget import (initialize_gl, paint_gl, resize_gl, from clusterview.opengl_widget import (clear_selection, initialize_gl,
paint_gl, resize_gl,
set_drawing_mode, set_drawing_context) set_drawing_mode, set_drawing_context)
from clusterview_ui import Ui_MainWindow from clusterview_ui import Ui_MainWindow
@ -36,6 +38,14 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# tracked and fired properly. # tracked and fired properly.
self.opengl_widget.setMouseTracking(True) self.opengl_widget.setMouseTracking(True)
# Enables us to handle key press events (used for checking
# for and handling terminating selections with ESC).
# Here we partially apply the key press handler with self to
# create a new function that only expects the event `keyPressEvent`
# expects. In this way, we've snuck the state of the opengl_widget
# into the function so that we can modify it as we please.
self.opengl_widget.keyPressEvent = partial(ogl_keypress_handler, self)
#----------------------------------------------- #-----------------------------------------------
# OpenGL Graphics Handlers are set # OpenGL Graphics Handlers are set
# here and defined in clusterview.opengl_widget. # here and defined in clusterview.opengl_widget.
@ -68,24 +78,32 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
set_drawing_mode(self.__mode) set_drawing_mode(self.__mode)
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor)) self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor))
self.status_bar.showMessage("ADD MODE") self.status_bar.showMessage("ADD MODE")
clear_selection()
self.opengl_widget.update()
def __edit_points(self): def __edit_points(self):
self.__mode = Mode.EDIT self.__mode = Mode.EDIT
set_drawing_mode(self.__mode) set_drawing_mode(self.__mode)
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor)) self.opengl_widget.setCursor(QCursor(Qt.CursorShape.CrossCursor))
self.status_bar.showMessage("EDIT MODE") self.status_bar.showMessage("EDIT MODE")
clear_selection()
self.opengl_widget.update()
def __delete_points(self): def __delete_points(self):
self.__mode = Mode.DELETE self.__mode = Mode.DELETE
set_drawing_mode(self.__mode) set_drawing_mode(self.__mode)
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) self.opengl_widget.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
self.status_bar.showMessage("DELETE MODE") self.status_bar.showMessage("DELETE MODE")
clear_selection()
self.opengl_widget.update()
def __move_points(self): def __move_points(self):
self.__mode = Mode.MOVE self.__mode = Mode.MOVE
set_drawing_mode(self.__mode) set_drawing_mode(self.__mode)
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.SizeAllCursor)) self.opengl_widget.setCursor(QCursor(Qt.CursorShape.SizeAllCursor))
self.status_bar.showMessage("MOVE MODE") self.status_bar.showMessage("MOVE MODE")
clear_selection()
self.opengl_widget.update()
@handle_exceptions @handle_exceptions
def __solve_launcher(self): def __solve_launcher(self):

Loading…
Cancel
Save