Browse Source

Succesfully initalize openGL context on the opengl_widget

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
76978c2c27
  1. 11
      CONTRIBUTING.md
  2. 21
      clusterview/opengl_widget.py
  3. 9
      main_window.py

11
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`.

21
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)

9
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
# -------------------------------------

Loading…
Cancel
Save