simplify calls needed to initialize items

This commit is contained in:
KIU Shueng Chuan 2021-07-03 15:53:17 +08:00
parent e76328ab0e
commit e9ee11f010
2 changed files with 11 additions and 9 deletions

View File

@ -228,10 +228,11 @@ class GLGraphicsItem(QtCore.QObject):
view, as it may be obscured or outside of the current view area."""
return self.__visible
def setInitialized(self, init=True):
self.__initialized = init
def initialize(self):
self.initializeGL()
self.__initialized = True
def initialized(self):
def isInitialized(self):
return self.__initialized
def initializeGL(self):
@ -240,7 +241,7 @@ class GLGraphicsItem(QtCore.QObject):
The widget's GL context is made current before this method is called.
(So this would be an appropriate time to generate lists, upload textures, etc.)
"""
self.setInitialized()
pass
def setupGLState(self):
"""

View File

@ -102,8 +102,7 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
if self.isValid():
self.makeCurrent()
try:
item.initializeGL()
item.setInitialized()
item.initialize()
except:
self.checkOpenGLVersion('Error while adding item %s to GLViewWidget.' % str(item))
@ -129,10 +128,12 @@ class GLViewWidget(QtWidgets.QOpenGLWidget):
self.update()
def initializeGL(self):
"""
Initialize items that were not initialized during addItem().
"""
for item in self.items:
if not item.initialized():
item.initializeGL()
item.setInitialized()
if not item.isInitialized():
item.initialize()
def setBackgroundColor(self, *args, **kwds):
"""