From 051dfe0d31b2855b3b6ae9f2f9518448f61b16d7 Mon Sep 17 00:00:00 2001 From: vladimir-kraus Date: Fri, 18 Nov 2016 14:55:39 +0100 Subject: [PATCH 1/4] added method clear() to GLViewWidget --- pyqtgraph/opengl/GLViewWidget.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index e0fee046..83876ae9 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -15,7 +15,6 @@ class GLViewWidget(QtOpenGL.QGLWidget): - Rotation/scale controls - Axis/grid display - Export options - """ def __init__(self, parent=None): @@ -61,10 +60,21 @@ class GLViewWidget(QtOpenGL.QGLWidget): self.update() def removeItem(self, item): + """ + Remove the item from the scene. + """ self.items.remove(item) item._setView(None) self.update() - + + def clear(self): + """ + Remove all items from the scene. + """ + for item in self.items: + item._setView(None) + self.items = [] + self.update() def initializeGL(self): self.resizeGL(self.width(), self.height()) @@ -230,8 +240,6 @@ class GLViewWidget(QtOpenGL.QGLWidget): self.opts['azimuth'] = azimuth self.update() - - def cameraPosition(self): """Return current position of camera based on center, dist, elevation, and azimuth""" center = self.opts['center'] @@ -322,7 +330,6 @@ class GLViewWidget(QtOpenGL.QGLWidget): #self.paintGL(region=region) #self.swapBuffers() - def wheelEvent(self, ev): delta = 0 if not USE_PYQT5: @@ -386,8 +393,6 @@ class GLViewWidget(QtOpenGL.QGLWidget): else: raise - - def readQImage(self): """ Read the current buffer pixels out as a QImage. @@ -411,7 +416,6 @@ class GLViewWidget(QtOpenGL.QGLWidget): img = fn.makeQImage(pixels, transpose=False) return img - def renderToArray(self, size, format=GL_BGRA, type=GL_UNSIGNED_BYTE, textureSize=1024, padding=256): w,h = map(int, size) @@ -466,6 +470,4 @@ class GLViewWidget(QtOpenGL.QGLWidget): glfbo.glDeleteFramebuffers([fb]) return output - - - + \ No newline at end of file From 30864df76d03c17faee83d7b78cfe43c3b2114f6 Mon Sep 17 00:00:00 2001 From: vladimir-kraus Date: Fri, 18 Nov 2016 15:03:19 +0100 Subject: [PATCH 2/4] added method reset() to GLViewWidget to initialize or reset the current state --- pyqtgraph/opengl/GLViewWidget.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index 83876ae9..c6f03f38 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -28,6 +28,20 @@ class GLViewWidget(QtOpenGL.QGLWidget): self.setFocusPolicy(QtCore.Qt.ClickFocus) + self.reset() + self.items = [] + + self.noRepeatKeys = [QtCore.Qt.Key_Right, QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Down, QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown] + self.keysPressed = {} + self.keyTimer = QtCore.QTimer() + self.keyTimer.timeout.connect(self.evalKeyState) + + self.makeCurrent() + + def reset(self): + """ + Initialize the widget state or reset the current state to the original state. + """ self.opts = { 'center': Vector(0,0,0), ## will always appear at the center of the widget 'distance': 10.0, ## distance of camera from center @@ -37,14 +51,7 @@ class GLViewWidget(QtOpenGL.QGLWidget): ## (rotation around z-axis 0 points along x-axis) 'viewport': None, ## glViewport params; None == whole widget } - self.setBackgroundColor('k') - self.items = [] - self.noRepeatKeys = [QtCore.Qt.Key_Right, QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Down, QtCore.Qt.Key_PageUp, QtCore.Qt.Key_PageDown] - self.keysPressed = {} - self.keyTimer = QtCore.QTimer() - self.keyTimer.timeout.connect(self.evalKeyState) - - self.makeCurrent() + self.setBackgroundColor('k') def addItem(self, item): self.items.append(item) From 668973bd4484907cb9fcec39b341d9c622f8b16e Mon Sep 17 00:00:00 2001 From: vladimir-kraus Date: Fri, 4 Aug 2017 11:32:21 +0200 Subject: [PATCH 3/4] raising AttributeError in __getattr__ instead of NameError is the correct way of handling non-existent attributes; otherwise for example hasattr(obj, attribute) would raise NameError instead of returning False if the attribute does not exist --- pyqtgraph/graphicsWindows.py | 2 +- pyqtgraph/widgets/PlotWidget.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/graphicsWindows.py b/pyqtgraph/graphicsWindows.py index 1aa3f3f4..331bb659 100644 --- a/pyqtgraph/graphicsWindows.py +++ b/pyqtgraph/graphicsWindows.py @@ -48,7 +48,7 @@ class TabWindow(QtGui.QMainWindow): if hasattr(self.cw, attr): return getattr(self.cw, attr) else: - raise NameError(attr) + raise AttributeError(attr) class PlotWindow(PlotWidget): diff --git a/pyqtgraph/widgets/PlotWidget.py b/pyqtgraph/widgets/PlotWidget.py index 964307ae..6e10b13a 100644 --- a/pyqtgraph/widgets/PlotWidget.py +++ b/pyqtgraph/widgets/PlotWidget.py @@ -76,7 +76,7 @@ class PlotWidget(GraphicsView): m = getattr(self.plotItem, attr) if hasattr(m, '__call__'): return m - raise NameError(attr) + raise AttributeError(attr) def viewRangeChanged(self, view, range): #self.emit(QtCore.SIGNAL('viewChanged'), *args) From b9a0fac815dd669fa40ecc0651028952b3bfccaa Mon Sep 17 00:00:00 2001 From: Ogi Moore Date: Thu, 11 Jun 2020 21:32:12 -0700 Subject: [PATCH 4/4] devicePixelRatio is only accessible in __init__ --- pyqtgraph/opengl/GLViewWidget.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index a0ae663f..8345ae3c 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -31,7 +31,9 @@ class GLViewWidget(QtOpenGL.QGLWidget): QtOpenGL.QGLWidget.__init__(self, parent, ShareWidget) self.setFocusPolicy(QtCore.Qt.ClickFocus) - + self.opts = { + 'devicePixelRatio': devicePixelRatio + } self.reset() self.items = [] @@ -46,16 +48,13 @@ class GLViewWidget(QtOpenGL.QGLWidget): """ Initialize the widget state or reset the current state to the original state. """ - self.opts = { - 'center': Vector(0,0,0), ## will always appear at the center of the widget - 'distance': 10.0, ## distance of camera from center - 'fov': 60, ## horizontal field of view in degrees - 'elevation': 30, ## camera's angle of elevation in degrees - 'azimuth': 45, ## camera's azimuthal angle in degrees - ## (rotation around z-axis 0 points along x-axis) - 'viewport': None, ## glViewport params; None == whole widget - 'devicePixelRatio': devicePixelRatio, - } + self.opts['center'] = Vector(0,0,0) ## will always appear at the center of the widget + self.opts['distance'] = 10.0 ## distance of camera from center + self.opts['fov'] = 60 ## horizontal field of view in degrees + self.opts['elevation'] = 30 ## camera's angle of elevation in degrees + self.opts['azimuth'] = 45 ## camera's azimuthal angle in degrees + ## (rotation around z-axis 0 points along x-axis) + self.opts['viewport'] = None ## glViewport params; None == whole widget self.setBackgroundColor('k') def addItem(self, item): @@ -528,4 +527,4 @@ class GLViewWidget(QtOpenGL.QGLWidget): glfbo.glDeleteFramebuffers([fb]) return output - \ No newline at end of file +