From 5e64c03aa7b52691c4fc59df30cb1dd7d76feb8e Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Wed, 7 Aug 2019 21:59:05 -0700 Subject: [PATCH] Correcting comparison, adding lighting, etc) --- clusterview/exceptions.py | 4 +--- clusterview/mode.py | 4 ++++ clusterview/opengl_widget.py | 33 ++++++++++++++++++++++++++++++++- main_window.py | 2 +- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/clusterview/exceptions.py b/clusterview/exceptions.py index bd18e46..13d3b3b 100644 --- a/clusterview/exceptions.py +++ b/clusterview/exceptions.py @@ -34,15 +34,13 @@ class InvalidMode(Exception): An exception to specify an invalid mode has been provided. """ - _exc = None - def __init__(self, mode): """ Initializes the InvalidMode exception with a mode. """ - if type(mode) != Mode: + if not isinstance(mode, Mode): raise ValueError("Mode argument to InvalidMode must be of "+ " type mode") diff --git a/clusterview/mode.py b/clusterview/mode.py index 163b871..b948a1a 100644 --- a/clusterview/mode.py +++ b/clusterview/mode.py @@ -30,12 +30,16 @@ def __handle_edit_point(ctx, event): # attributes in the case of algorithms that require points to have # weights or something. # + # Should move the associated point in the list to the new location if + # applicable. print("[EDIT] GOT POINT: ({}, {})".format(event.x(), event.y())) def __handle_move_points(ctx, event): + # TODO: Should move the associated points in the list to the new location. print("[MOVE] Pressed - NOTE NEED DRAG EVENT") def __handle_delete_point(ctx, event): + # TODO: Needs to also delete the point from the list. print("[DELETE] GOT POINT: ({}, {})".format(event.x(), event.y())) diff --git a/clusterview/opengl_widget.py b/clusterview/opengl_widget.py index 8092b33..781e983 100644 --- a/clusterview/opengl_widget.py +++ b/clusterview/opengl_widget.py @@ -10,12 +10,43 @@ here are imported as overrides to the OpenGL functions of that widget. """ -from OpenGL.GL import glClearColor, glEnable +from enum import Enum + +from OpenGL.GL import glClearColor, glEnable, GL_LIGHT0, GL_LIGHTING + +class Color(Enum): + BLUE = 0 + +# A simple map from Color -> RGBA 4-Tuple +COLOR_TO_RGBA = { + Color.BLUE: (0, 128, 255, 255) +} def initialize_gl(): """ Initializes the OpenGL context on the Window. """ + # Since we aren't using shaders lighting needs to be + # enabled. + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); # Set white background glClearColor(255, 255, 255, 0) + + +def draw_point(x, y, color): + """ + Simple point drawing function. + + Given a coordinate (x, y), and a Color enum this + function will draw the given point with the given + color. + + @param x The x-coordinate. + @param y The y-coordinate. + @param color The Color Enum. + """ + + if not isinstance(color, Color): + raise ValueError("Color must exist in the Color enumeration") diff --git a/main_window.py b/main_window.py index 256d2bc..86b2eb9 100644 --- a/main_window.py +++ b/main_window.py @@ -79,7 +79,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """ Mode dispatcher for click actions on the OpenGL widget. """ - if self.__mode == Mode.OFF: + if self.__mode is Mode.OFF: raise InvalidMode(Mode.OFF) # Map from Mode -> function