From 76978c2c27df6c2ad07def9170b4fe2bc7acd644 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Wed, 7 Aug 2019 21:45:16 -0700 Subject: [PATCH] Succesfully initalize openGL context on the opengl_widget --- CONTRIBUTING.md | 11 +++++++++++ clusterview/opengl_widget.py | 21 +++++++++++++++++++++ main_window.py | 9 ++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 clusterview/opengl_widget.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cc1793e..519e2b6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,3 +66,14 @@ The imports must be organized as follows: # Modules local to the current module last ``` +Additionally, each imported module will be alphabetized by the module name +inside of the `import X` (X being the module name) or the `from X import Y` +(X being the module name). + +If you are importing more than one thing from a module, alphabetize those as well + +`from x import foo, bar, baz` + +should be + +`from x import bar, baz, foo`. diff --git a/clusterview/opengl_widget.py b/clusterview/opengl_widget.py new file mode 100644 index 0000000..8092b33 --- /dev/null +++ b/clusterview/opengl_widget.py @@ -0,0 +1,21 @@ +""" +This module defines functions that need to be overwritten +in order for OpenGL to work with the main window. This +module is named the same as the actual widget in order +to make namespacing consistent. + +To be clear, the actual widget is defined in the UI +generated code - `clusterview_ui.py`. The functions +here are imported as overrides to the OpenGL functions of +that widget. +""" + +from OpenGL.GL import glClearColor, glEnable + +def initialize_gl(): + """ + Initializes the OpenGL context on the Window. + """ + + # Set white background + glClearColor(255, 255, 255, 0) diff --git a/main_window.py b/main_window.py index 3a7df5f..256d2bc 100644 --- a/main_window.py +++ b/main_window.py @@ -5,9 +5,10 @@ from PyQt5.QtCore import Qt from PyQt5.QtGui import QCursor from PyQt5 import QtWidgets, uic -from clusterview_ui import Ui_MainWindow from clusterview.exceptions import handle_exceptions, InvalidMode from clusterview.mode import Mode, MODE_MAP +from clusterview.opengl_widget import initialize_gl +from clusterview_ui import Ui_MainWindow class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): """ @@ -22,6 +23,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): super(MainWindow, self).__init__(parent) self.setupUi(self) + #----------------------------------------------- + # OpenGL Graphics Handlers are set + # here and defined in clusterview.opengl_widget. + #----------------------------------------------- + self.opengl_widget.initializeGL = initialize_gl + # ------------------------------------- # UI Handlers # -------------------------------------