From 8a6640c4190b0f40b2794495160f2458d6e3a80c Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Mon, 19 Jul 2021 04:52:49 +0800 Subject: [PATCH] treat self.opts as private. provide accessors --- examples/GLPainterItem.py | 5 +++-- pyqtgraph/opengl/GLViewWidget.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/GLPainterItem.py b/examples/GLPainterItem.py index 3b3678ea..683e4dc5 100644 --- a/examples/GLPainterItem.py +++ b/examples/GLPainterItem.py @@ -48,9 +48,10 @@ class GLPainterItem(pg.opengl.GLGraphicsItem.GLGraphicsItem): painter.drawText(rect, af.AlignBottom | af.AlignLeft, 'BL') painter.drawText(rect, af.AlignBottom | af.AlignRight, 'BR') - opts = self.view().opts + opts = self.view().getCameraPosition() + opts['fov'] = self.view().fov() lines = [] - center = opts['center'] + center = opts['pos'] lines.append(f"center : ({center.x():.1f}, {center.y():.1f}, {center.z():.1f})") for key in ['distance', 'fov', 'elevation', 'azimuth']: lines.append(f"{key} : {opts[key]:.1f}") diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index 723b288b..97aa1fda 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -308,6 +308,22 @@ class GLViewWidget(QtWidgets.QOpenGLWidget): self.update() + def getCameraPosition(self): + opts = { 'pos': self.opts['center'], + 'distance' : self.opts['distance'] } + if self.opts['rotationMethod'] == "quaternion": + opts['rotation'] = self.opts['rotation'] + else: + opts['elevation'] = self.opts['elevation'] + opts['azimuth'] = self.opts['azimuth'] + return opts + + def setFov(self, fov): + self.opts['fov'] = fov + + def fov(self): + return self.opts['fov'] + def cameraPosition(self): """Return current position of camera based on center, dist, elevation, and azimuth""" center = self.opts['center']