From 3eeffd3b1dc187234bf3c4a467fc03381aa85077 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Sat, 13 Jul 2013 16:42:36 -0400 Subject: [PATCH] GLLinePLotItem accepts array of colors (thanks Felix!) --- README.txt | 1 + pyqtgraph/opengl/items/GLLinePlotItem.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index d209ef01..85e2b24a 100644 --- a/README.txt +++ b/README.txt @@ -12,6 +12,7 @@ Contributors: Christian Gavin Michael Cristopher Hogg Ulrich Leutner + Felix Schill Requirements: PyQt 4.7+ or PySide diff --git a/pyqtgraph/opengl/items/GLLinePlotItem.py b/pyqtgraph/opengl/items/GLLinePlotItem.py index bb5ce2f6..75d48c86 100644 --- a/pyqtgraph/opengl/items/GLLinePlotItem.py +++ b/pyqtgraph/opengl/items/GLLinePlotItem.py @@ -30,8 +30,9 @@ class GLLinePlotItem(GLGraphicsItem): Arguments: ------------------------------------------------------------------------ pos (N,3) array of floats specifying point locations. - color tuple of floats (0.0-1.0) specifying - a color for the entire item. + color (N,4) array of floats (0.0-1.0) or + tuple of floats specifying + a single color for the entire item. width float specifying line width antialias enables smooth line drawing ==================== ================================================== @@ -71,9 +72,18 @@ class GLLinePlotItem(GLGraphicsItem): self.setupGLState() glEnableClientState(GL_VERTEX_ARRAY) + try: glVertexPointerf(self.pos) - glColor4f(*self.color) + + if isinstance(self.color, np.ndarray): + glEnableClientState(GL_COLOR_ARRAY) + glColorPointerf(self.color) + else: + if isinstance(self.color, QtGui.QColor): + glColor4f(*fn.glColor(self.color)) + else: + glColor4f(*self.color) glLineWidth(self.width) #glPointSize(self.width) @@ -85,6 +95,7 @@ class GLLinePlotItem(GLGraphicsItem): glDrawArrays(GL_LINE_STRIP, 0, self.pos.size / self.pos.shape[-1]) finally: + glDisableClientState(GL_COLOR_ARRAY) glDisableClientState(GL_VERTEX_ARRAY)