From fd6cc955e218d1666da9da19eb1979370c6693fd Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sun, 16 Mar 2014 13:45:26 -0400 Subject: [PATCH] Fixed GLGridItem.setSize, added setSpacing --- CHANGELOG | 1 + pyqtgraph/opengl/items/GLGridItem.py | 38 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 11db18ac..b9e56d51 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -76,6 +76,7 @@ pyqtgraph-0.9.9 [unreleased] - Allow images with NaN in ImageView - MeshData can generate edges from face-indexed vertexes - Fixed multiprocess deadlocks on windows + - Fixed GLGridItem.setSize pyqtgraph-0.9.8 2013-11-24 diff --git a/pyqtgraph/opengl/items/GLGridItem.py b/pyqtgraph/opengl/items/GLGridItem.py index 2c4642c8..a8d1fb7a 100644 --- a/pyqtgraph/opengl/items/GLGridItem.py +++ b/pyqtgraph/opengl/items/GLGridItem.py @@ -1,3 +1,5 @@ +import numpy as np + from OpenGL.GL import * from .. GLGraphicsItem import GLGraphicsItem from ... import QtGui @@ -16,8 +18,9 @@ class GLGridItem(GLGraphicsItem): self.setGLOptions(glOptions) self.antialias = antialias if size is None: - size = QtGui.QVector3D(1,1,1) + size = QtGui.QVector3D(20,20,1) self.setSize(size=size) + self.setSpacing(1, 1, 1) def setSize(self, x=None, y=None, z=None, size=None): """ @@ -33,8 +36,22 @@ class GLGridItem(GLGraphicsItem): def size(self): return self.__size[:] - - + + def setSpacing(self, x=None, y=None, z=None, spacing=None): + """ + Set the spacing between grid lines. + Arguments can be x,y,z or spacing=QVector3D(). + """ + if spacing is not None: + x = spacing.x() + y = spacing.y() + z = spacing.z() + self.__spacing = [x,y,z] + self.update() + + def spacing(self): + return self.__spacing[:] + def paint(self): self.setupGLState() @@ -47,12 +64,15 @@ class GLGridItem(GLGraphicsItem): glBegin( GL_LINES ) x,y,z = self.size() + xs,ys,zs = self.spacing() + xvals = np.arange(-x/2., x/2. + xs*0.001, xs) + yvals = np.arange(-y/2., y/2. + ys*0.001, ys) glColor4f(1, 1, 1, .3) - for x in range(-10, 11): - glVertex3f(x, -10, 0) - glVertex3f(x, 10, 0) - for y in range(-10, 11): - glVertex3f(-10, y, 0) - glVertex3f( 10, y, 0) + for x in xvals: + glVertex3f(x, yvals[0], 0) + glVertex3f(x, yvals[-1], 0) + for y in yvals: + glVertex3f(xvals[0], y, 0) + glVertex3f(xvals[-1], y, 0) glEnd()