Browse Source

Remove extra mode setting garbage, stick to using contexts to the main window.

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

1
clusterview/mode_handlers.py

@ -142,7 +142,6 @@ def ogl_keypress_handler(ctx, event):
@param ctx A handle to the window context. @param ctx A handle to the window context.
@param event The event associated with this handler. @param event The event associated with this handler.
""" """
global __current_mode
global __left_click_flag global __left_click_flag
global __last_mouse_pos global __last_mouse_pos

46
clusterview/opengl_widget.py

@ -53,9 +53,9 @@ __move_bb_bottom_right = None
# Below functions have to mark these as `global` so # Below functions have to mark these as `global` so
# the interpreter knows that the variables are not # the interpreter knows that the variables are not
# function local. # function local.
__current_mode = None
__current_event = None
__current_context = None __current_context = None
__current_event = None
def set_drawing_context(ctx): def set_drawing_context(ctx):
""" """
@ -66,29 +66,6 @@ def set_drawing_context(ctx):
__current_context = ctx __current_context = ctx
def set_drawing_mode(mode):
"""
State management function. It is useful to look at the
different drawing modes as modes in a state machine.
Calling this function when a mode changes allows the
OpenGL functions to take the correct drawing action
on the OpenGL Widget.
@param mode The current mode.
"""
global __current_context
global __current_mode
if __current_context is None:
raise InvalidStateError("Drawing context must be set before setting " +
"drawing mode")
if not isinstance(mode, Mode):
raise ValueError("Mode in set_drawing_mode must be of type Mode")
__current_mode = mode
def set_drawing_event(event): def set_drawing_event(event):
""" """
State machine event management function. State machine event management function.
@ -168,8 +145,8 @@ def resize_gl(w, h):
global __WIDTH global __WIDTH
global __HEIGHT global __HEIGHT
__WIDTH = __current_context.width() __WIDTH = __current_context.opengl_widget.width()
__HEIGHT = __current_context.height() __HEIGHT = __current_context.opengl_widget.height()
def viewport_width(): def viewport_width():
return __WIDTH return __WIDTH
@ -184,24 +161,25 @@ def paint_gl():
on the current mode to determine what action to on the current mode to determine what action to
perform on the current event. perform on the current event.
""" """
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.MOVE, Mode.DELETE] and if (__current_context.mode in [Mode.ADD, Mode.EDIT,
Mode.MOVE, Mode.DELETE] and
__current_event is None): __current_event is None):
return return
if (__current_mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and if (__current_context.mode in [Mode.ADD, Mode.EDIT, Mode.DELETE] and
PointManager.point_set.empty()): PointManager.point_set.empty()):
return return
if (__current_mode is Mode.ADD or if (__current_context.mode is Mode.ADD or
__current_mode is Mode.DELETE or __current_context.mode is Mode.DELETE or
__current_mode is Mode.LOADED): __current_context.mode is Mode.LOADED):
draw_points(PointManager.point_set, Color.GREY) draw_points(PointManager.point_set, Color.GREY)
elif __current_mode is Mode.EDIT: elif __current_context.mode is Mode.EDIT:
raise NotImplementedError("Drawing for EDIT not implemented.") raise NotImplementedError("Drawing for EDIT not implemented.")
elif __current_mode is Mode.MOVE: elif __current_context.mode is Mode.MOVE:
# We have to repeatedly draw the points while we are showing the # We have to repeatedly draw the points while we are showing the
# move box. # move box.
if not PointManager.point_set.empty(): if not PointManager.point_set.empty():

10
main_window.py

@ -13,11 +13,12 @@ from clusterview.mode_handlers import (MODE_HANDLER_MAP, ogl_keypress_handler,
refresh_point_list) refresh_point_list)
from clusterview.opengl_widget import (clear_selection, initialize_gl, from clusterview.opengl_widget import (clear_selection, initialize_gl,
mouse_leave, paint_gl, resize_gl, mouse_leave, paint_gl, resize_gl,
set_drawing_mode, set_drawing_context) set_drawing_context)
from clusterview.point_manager import PointManager from clusterview.point_manager import PointManager
from clusterview.point_list_widget import item_click_handler from clusterview.point_list_widget import item_click_handler
from clusterview_ui import Ui_MainWindow from clusterview_ui import Ui_MainWindow
class MainWindow(QMainWindow, Ui_MainWindow): class MainWindow(QMainWindow, Ui_MainWindow):
""" """
A wrapper class for handling creating a window based A wrapper class for handling creating a window based
@ -38,7 +39,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# If we allow resizing of the window, the context must be updated # If we allow resizing of the window, the context must be updated
# each resize so that coordinates are converted from screen (x, y) # each resize so that coordinates are converted from screen (x, y)
# to OpenGL coordinates properly. # to OpenGL coordinates properly.
set_drawing_context(self.opengl_widget) set_drawing_context(self)
# Enables mouse tracking on the viewport so mouseMoveEvents are # Enables mouse tracking on the viewport so mouseMoveEvents are
# tracked and fired properly. # tracked and fired properly.
@ -100,7 +101,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def __add_points(self): def __add_points(self):
self.__mode = Mode.ADD self.__mode = Mode.ADD
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() clear_selection()
@ -108,7 +108,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def __edit_points(self): def __edit_points(self):
self.__mode = Mode.EDIT self.__mode = Mode.EDIT
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() clear_selection()
@ -116,7 +115,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def __delete_points(self): def __delete_points(self):
self.__mode = Mode.DELETE self.__mode = Mode.DELETE
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() clear_selection()
@ -124,7 +122,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def __move_points(self): def __move_points(self):
self.__mode = Mode.MOVE self.__mode = Mode.MOVE
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 - PRESS ESC OR SWITCH MODES TO "+ self.status_bar.showMessage("MOVE MODE - PRESS ESC OR SWITCH MODES TO "+
"CANCEL SELECTION") "CANCEL SELECTION")
@ -153,7 +150,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
"", "",
"JSON files (*.json)") "JSON files (*.json)")
if ofile: if ofile:
set_drawing_mode(Mode.LOADED)
self.__mode = Mode.LOADED self.__mode = Mode.LOADED
PointManager.load(ofile) PointManager.load(ofile)

Loading…
Cancel
Save