Browse Source

Make ESC leave modes properly

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
a57e7581e8
  1. 12
      clusterview/mode_handlers.py
  2. 10
      clusterview/opengl_widget.py
  3. 3
      main_window.py

12
clusterview/mode_handlers.py

@ -1,6 +1,7 @@
from enum import Enum
from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtGui import QCursor
from .exceptions import ExceededWindowBoundsError
from .mode import Mode
@ -156,12 +157,12 @@ def ogl_keypress_handler(ctx, event):
reset_move_bbs()
refresh_point_list(ctx)
elif ctx.mode in [Mode.ADD, Mode.EDIT, Mode.DELETE, Mode.OFF]:
# Just clear selections
PointManager.point_set.clear_selection()
elif ctx.mode is not Mode.OFF:
ctx.mode = Mode.OFF
# Also change the mouse back to normal
ctx.opengl_widget.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
ctx.status_bar.showMessage("")
ctx.opengl_widget.update()
@ -182,9 +183,6 @@ def __handle_move_points(ctx, event):
__handle_info_updates(ctx, event)
# Necessary to capture keyboard events
ctx.opengl_widget.setFocusPolicy(Qt.StrongFocus)
# If we release the mouse, we want to quickly alert drag mode.
if (event.button() == Qt.LeftButton and
event.type() == QEvent.MouseButtonRelease):

10
clusterview/opengl_widget.py

@ -161,9 +161,17 @@ def paint_gl():
on the current mode to determine what action to
perform on the current event.
"""
if(__current_context.mode is Mode.OFF and
not PointManager.point_set.empty()):
# We want to redraw on any change to Mode.OFF so points are preserved -
# without this, any switch to Mode.OFF will cause a blank screen to
# render.
draw_points(PointManager.point_set, Color.GREY)
if (__current_context.mode in [Mode.ADD, Mode.EDIT,
Mode.MOVE, Mode.DELETE] and
__current_event is None):
__current_event is None and PointManager.point_set.empty()):
return
if (__current_context.mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and

3
main_window.py

@ -44,6 +44,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Enables mouse tracking on the viewport so mouseMoveEvents are
# tracked and fired properly.
self.opengl_widget.setMouseTracking(True)
# Enable keyboard input capture on the OpenGL Widget
self.opengl_widget.setFocusPolicy(Qt.StrongFocus)
# Here we partially apply the key press handler with self to
# create a new function that only expects the event `keyPressEvent`

Loading…
Cancel
Save