Browse Source

Get ESC working properly

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
ae502d3121
  1. 23
      clusterview/mode_handlers.py
  2. 23
      main_window.py

23
clusterview/mode_handlers.py

@ -116,23 +116,30 @@ 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.
It primarily exists to allow the user to cancel selection.
Also allows users to escape from modes.
@param ctx A handle to the window context.
@param event The event associated with this handler.
"""
global __current_mode
global __left_click_flag
global __mouse_start
if (__left_click_flag is not __ClickFlag.NONE
and event.key() == Qt.Key_Escape):
if event.key() == Qt.Key_Escape:
if ctx.mode is Mode.MOVE:
if __left_click_flag is not __ClickFlag.NONE:
__mouse_start = None
__mouse_start = None
__left_click_flag = __ClickFlag.NONE
__point_set.clear_selection()
reset_move_bbs()
elif ctx.mode is not Mode.OFF:
ctx.mode = Mode.OFF
__left_click_flag = __ClickFlag.NONE
__point_set.clear_selection()
reset_move_bbs()
ctx.opengl_widget.update()

23
main_window.py

@ -38,8 +38,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# tracked and fired properly.
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
@ -73,6 +71,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# Mode changers - these will be used to signal the action in the
# OpenGL Widget.
#-----------------------------------------------------------------
def __off_mode(self):
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
self.status_bar.showMessage("")
clear_selection()
self.opengl_widget.update()
def __add_points(self):
self.__mode = Mode.ADD
set_drawing_mode(self.__mode)
@ -105,6 +109,18 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
clear_selection()
self.opengl_widget.update()
@property
def mode(self):
"""
Function designed to be used from a context
to get the current mode.
"""
return self.__mode
@mode.setter
def mode(self, mode):
self.__mode = mode
@handle_exceptions
def __solve_launcher(self):
"""
@ -130,3 +146,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# them to modify on screen widgets such as the QOpenGLWidget and
# QListWidget.
MODE_HANDLER_MAP[self.__mode](self, event)
else:
# Go back to the base state
self.__off_mode()

Loading…
Cancel
Save