|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
from enum import Enum |
|
|
|
|
import random |
|
|
|
|
|
|
|
|
|
from PyQt5.QtCore import QEvent, Qt |
|
|
|
|
from PyQt5.QtGui import QCursor |
|
|
|
@ -54,6 +54,12 @@ __last_mouse_pos = None
|
|
|
|
|
# Used to implement mouse dragging when clicked |
|
|
|
|
__left_click_down = False |
|
|
|
|
|
|
|
|
|
# TODO: WHEN THE GROUPING ENDS AND THE USER CANCELS THE CENTROID COUNT |
|
|
|
|
# SHOULD BE ZEROED AND REMAINING COLORS SHOULD BE REPOPULATED. |
|
|
|
|
# Count of centroids for comparison with the spin widget |
|
|
|
|
__centroid_count = 0 |
|
|
|
|
__remaining_colors = [c for c in Color if c not in [Color.BLUE, Color.GREY]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_point_list(ctx): |
|
|
|
|
""" |
|
|
|
@ -294,6 +300,55 @@ def __handle_info_updates(ctx, event):
|
|
|
|
|
ctx.mouse_position_label.setText(f"{event.x(), event.y()}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __handle_choose_centroids(ctx, event): |
|
|
|
|
""" |
|
|
|
|
Similar to move in terms of selecting points, however this |
|
|
|
|
function assigns a random color up to the maximum number |
|
|
|
|
of centroids, and after the maximum number has been selected it will |
|
|
|
|
enable the group button. |
|
|
|
|
""" |
|
|
|
|
global __centroid_count |
|
|
|
|
global __remaining_colors |
|
|
|
|
|
|
|
|
|
__handle_info_updates(ctx, event) |
|
|
|
|
|
|
|
|
|
if __centroid_count == ctx.number_of_centroids.value: |
|
|
|
|
# We have specified the number of centroids required |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if (event.button() == Qt.LeftButton and |
|
|
|
|
event.type() == QEvent.MouseButtonPress): |
|
|
|
|
|
|
|
|
|
point = None |
|
|
|
|
|
|
|
|
|
for test_point in PointManager.point_set.points: |
|
|
|
|
if test_point.hit(event.x(), event.y()): |
|
|
|
|
point = test_point |
|
|
|
|
|
|
|
|
|
if point is None: |
|
|
|
|
# No point was found on the click, do nothing |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
if point in PointManager.centroids: |
|
|
|
|
# Centroids must be unique |
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
__centroid_count += 1 |
|
|
|
|
|
|
|
|
|
color = random.choice(__remaining_colors) |
|
|
|
|
__remaining_colors.remove(color) |
|
|
|
|
|
|
|
|
|
point.color = color |
|
|
|
|
|
|
|
|
|
# Recolor the point and restash the point in centroids |
|
|
|
|
PointManager.centroids.append(point) |
|
|
|
|
|
|
|
|
|
if __centroid_count == ctx.number_of_centroids.value: |
|
|
|
|
ctx.group_button.setEnabled(True) |
|
|
|
|
|
|
|
|
|
ctx.opengl_widget.update() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Simple dispatcher to make it easy to dispatch the right mode |
|
|
|
|
# function when the OpenGL window is acted on. |
|
|
|
|
MODE_HANDLER_MAP = { |
|
|
|
@ -302,5 +357,6 @@ MODE_HANDLER_MAP = {
|
|
|
|
|
Mode.ADD: __handle_add_point, |
|
|
|
|
Mode.EDIT: __handle_edit_point, |
|
|
|
|
Mode.MOVE: __handle_move_points, |
|
|
|
|
Mode.DELETE: __handle_delete_point |
|
|
|
|
Mode.DELETE: __handle_delete_point, |
|
|
|
|
Mode.CHOOSE_CENTROIDS: __handle_choose_centroids |
|
|
|
|
} |
|
|
|
|