Fixed GLGridItem.setSize, added setSpacing

This commit is contained in:
Luke Campagnola 2014-03-16 13:45:26 -04:00
parent 5f7e4dc644
commit fd6cc955e2
2 changed files with 30 additions and 9 deletions

View File

@ -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

View File

@ -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):
"""
@ -34,6 +37,20 @@ 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()