Browse Source

Grouping and coloring

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

24
clusterview/mode_handlers.py

@ -3,6 +3,7 @@ import random
from PyQt5.QtCore import QEvent, Qt from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
from .algorithms import Algorithms
from .colors import Color from .colors import Color
from .exceptions import ExceededWindowBoundsError from .exceptions import ExceededWindowBoundsError
from .mode import Mode from .mode import Mode
@ -343,12 +344,33 @@ def __handle_choose_centroids(ctx, event):
# Recolor the point and restash the point in centroids # Recolor the point and restash the point in centroids
PointManager.centroids.append(point) PointManager.centroids.append(point)
if __centroid_count == ctx.number_of_centroids.value: if __centroid_count == ctx.number_of_centroids.value():
# Prevent the user from changing the centroids
ctx.number_of_centroids.setEnabled(False)
ctx.choose_centroids_button.setEnabled(False)
ctx.group_button.setEnabled(True) ctx.group_button.setEnabled(True)
ctx.opengl_widget.update() ctx.opengl_widget.update()
def group(ctx):
"""
Group handler. Basically just a wrapper around the distance
grouping algorithm that recolors points.
This is one of the only functions that operates only on a button click
and as a result is made public since the dispatcher is not needed.
"""
groups = Algorithms.euclidean_grouping(PointManager.centroids,
PointManager.point_set)
for centroid_group in groups:
for point in centroid_group.points:
point.color = centroid_group.centroid.color
ctx.opengl_widget.update()
# Simple dispatcher to make it easy to dispatch the right mode # Simple dispatcher to make it easy to dispatch the right mode
# function when the OpenGL window is acted on. # function when the OpenGL window is acted on.
MODE_HANDLER_MAP = { MODE_HANDLER_MAP = {

27
main_window.py

@ -7,7 +7,8 @@ from PyQt5.QtWidgets import QFileDialog, QMainWindow
from clusterview.exceptions import handle_exceptions from clusterview.exceptions import handle_exceptions
from clusterview.colors import Color from clusterview.colors import Color
from clusterview.mode import Mode from clusterview.mode import Mode
from clusterview.mode_handlers import (MODE_HANDLER_MAP, ogl_keypress_handler, from clusterview.mode_handlers import (group, 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,
@ -66,6 +67,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self)) self))
self.choose_centroids_button.clicked.connect(self.__choose_centroids) self.choose_centroids_button.clicked.connect(self.__choose_centroids)
self.group_button.clicked.connect(self.__group)
# ----------------------------------------------- # -----------------------------------------------
# OpenGL Graphics Handlers are set # OpenGL Graphics Handlers are set
@ -83,7 +85,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.action_edit_points.triggered.connect(self.__edit_points) self.action_edit_points.triggered.connect(self.__edit_points)
self.action_delete_points.triggered.connect(self.__delete_points) self.action_delete_points.triggered.connect(self.__delete_points)
self.action_move_points.triggered.connect(self.__move_points) 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.action_save_point_configuration.triggered.connect(
self.__save_points_file) self.__save_points_file)
@ -104,6 +105,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# OpenGL Widget. # OpenGL Widget.
# ----------------------------------------------------------------- # -----------------------------------------------------------------
def __off_mode(self): def __off_mode(self):
self.__mode = Mode.OFF
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.ArrowCursor)) self.opengl_widget.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
self.status_bar.showMessage("") self.status_bar.showMessage("")
clear_selection() clear_selection()
@ -147,6 +149,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
clear_selection() clear_selection()
self.opengl_widget.update() self.opengl_widget.update()
def __group(self):
self.__mode = Mode.GROUP
self.opengl_widget.setCursor(QCursor(Qt.CursorShape.ArrowCursor))
self.status_bar.showMessage("GROUPING")
clear_selection()
group(self)
self.__off_mode()
self.opengl_widget.update()
@property @property
def mode(self): def mode(self):
""" """
@ -187,17 +199,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
PointManager.save(file_name) PointManager.save(file_name)
@handle_exceptions @handle_exceptions
def __solve_launcher(self):
"""
Launched the solve menu. This function will call into a subclass
of the solve dialog widget from the UI.
TODO: Write the subclass once you know the parameters for the
solve window.
"""
print("LAUNCHING SOLVE DIALOG...")
@handle_exceptions
def __ogl_click_dispatcher(self, event): def __ogl_click_dispatcher(self, event):
""" """
Mode dispatcher for click actions on the OpenGL widget. Mode dispatcher for click actions on the OpenGL widget.

Loading…
Cancel
Save