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

View File

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