Browse Source

Add loading and saving behavior to the screen

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
d69f50d1db
  1. 1
      clusterview/mode.py
  2. 6
      clusterview/mode_handlers.py
  3. 10
      clusterview/opengl_widget.py
  4. 40
      main_window.py

1
clusterview/mode.py

@ -12,3 +12,4 @@ class Mode(Enum):
EDIT = 2
MOVE = 3
DELETE = 4
LOADED = 5

6
clusterview/mode_handlers.py

@ -46,7 +46,7 @@ __left_click_flag = __ClickFlag.NONE
__mouse_start = None
def __refresh_point_list(ctx):
def refresh_point_list(ctx):
"""
Refreshes the point list display.
@ -93,7 +93,7 @@ def __handle_add_point(ctx, event):
# on the outside of the window. We will just ignore it.
return
__refresh_point_list(ctx)
refresh_point_list(ctx)
set_drawing_event(event)
@ -242,7 +242,7 @@ def __handle_delete_point(ctx, event):
PointManager.point_set.remove_point(event.x(), event.y())
__refresh_point_list(ctx)
refresh_point_list(ctx)
ctx.opengl_widget.update()
ctx.point_list_widget.update()

10
clusterview/opengl_widget.py

@ -182,12 +182,10 @@ def paint_gl():
PointManager.point_set.empty()):
return
if __current_mode is Mode.ADD or __current_mode is Mode.DELETE:
# Note that drawing the points doesn't require a bounding box or
# any special context, so delete just removes the element from
# the point set, which will be redrawn here. This action
# is the same as adding a point since we just draw what is in
# the point set.
if (__current_mode is Mode.ADD or
__current_mode is Mode.DELETE or
__current_mode is Mode.LOADED):
draw_points(PointManager.point_set, Color.GREY)
elif __current_mode is Mode.EDIT:

40
main_window.py

@ -2,20 +2,23 @@ from enum import Enum
from functools import partial
import os
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QCursor
from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QFileDialog, QMainWindow
from clusterview.exceptions import handle_exceptions, InvalidModeError
from clusterview.mode import Mode
from clusterview.mode_handlers import MODE_HANDLER_MAP, ogl_keypress_handler
from clusterview.mode_handlers import (MODE_HANDLER_MAP, ogl_keypress_handler,
refresh_point_list)
from clusterview.opengl_widget import (clear_selection, initialize_gl,
paint_gl, resize_gl,
set_drawing_mode, set_drawing_context)
from clusterview.point_manager import PointManager
from clusterview.point_list_widget import item_click_handler
from clusterview_ui import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
class MainWindow(QMainWindow, Ui_MainWindow):
"""
A wrapper class for handling creating a window based
on the `clusterview_ui.py` code generated from
@ -68,6 +71,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.action_move_points.triggered.connect(self.__move_points)
self.action_solve.triggered.connect(self.__solve_launcher)
self.action_save_point_configuration.triggered.connect(
self.__save_points_file)
self.action_load_point_configuration.triggered.connect(
self.__open_points_file)
# 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
@ -129,6 +138,29 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def mode(self, mode):
self.__mode = mode
def __open_points_file(self):
ofile, _ = QFileDialog.getOpenFileName(self,
"Open Point Configuration",
"",
"JSON files (*.json)")
if ofile:
set_drawing_mode(Mode.LOADED)
self.__mode = Mode.LOADED
PointManager.load(ofile)
self.opengl_widget.update()
refresh_point_list(self)
def __save_points_file(self):
file_name, _ = QFileDialog.getSaveFileName(self,
"Save Point Configuration",
"",
"JSON Files (*.json)")
if file_name:
PointManager.save(file_name)
@handle_exceptions
def __solve_launcher(self):
"""
@ -147,7 +179,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
Mode dispatcher for click actions on the OpenGL widget.
"""
if self.__mode is not Mode.OFF:
if self.__mode not in [Mode.OFF, Mode.LOADED]:
# Map from Mode -> function
# where the function is a handler for the
# OpenGL event. The context passed to these functions allows

Loading…
Cancel
Save