Browse Source

Correcting comparison, adding lighting, etc)

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
5e64c03aa7
  1. 4
      clusterview/exceptions.py
  2. 4
      clusterview/mode.py
  3. 33
      clusterview/opengl_widget.py
  4. 2
      main_window.py

4
clusterview/exceptions.py

@ -34,15 +34,13 @@ class InvalidMode(Exception):
An exception to specify an invalid mode has been provided. An exception to specify an invalid mode has been provided.
""" """
_exc = None
def __init__(self, mode): def __init__(self, mode):
""" """
Initializes the InvalidMode exception with a Initializes the InvalidMode exception with a
mode. mode.
""" """
if type(mode) != Mode: if not isinstance(mode, Mode):
raise ValueError("Mode argument to InvalidMode must be of "+ raise ValueError("Mode argument to InvalidMode must be of "+
" type mode") " type mode")

4
clusterview/mode.py

@ -30,12 +30,16 @@ def __handle_edit_point(ctx, event):
# attributes in the case of algorithms that require points to have # attributes in the case of algorithms that require points to have
# weights or something. # 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())) print("[EDIT] GOT POINT: ({}, {})".format(event.x(), event.y()))
def __handle_move_points(ctx, event): 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") print("[MOVE] Pressed - NOTE NEED DRAG EVENT")
def __handle_delete_point(ctx, 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())) print("[DELETE] GOT POINT: ({}, {})".format(event.x(), event.y()))

33
clusterview/opengl_widget.py

@ -10,12 +10,43 @@ here are imported as overrides to the OpenGL functions of
that widget. 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(): def initialize_gl():
""" """
Initializes the OpenGL context on the Window. 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 # Set white background
glClearColor(255, 255, 255, 0) 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")

2
main_window.py

@ -79,7 +79,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
""" """
Mode dispatcher for click actions on the OpenGL widget. Mode dispatcher for click actions on the OpenGL widget.
""" """
if self.__mode == Mode.OFF: if self.__mode is Mode.OFF:
raise InvalidMode(Mode.OFF) raise InvalidMode(Mode.OFF)
# Map from Mode -> function # Map from Mode -> function

Loading…
Cancel
Save