From f2d09911029ea3ee649978eb6416fa771369ab2f Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Thu, 4 Jul 2013 05:52:16 +0800 Subject: [PATCH 1/3] Minor fixes for py3k --- examples/__main__.py | 13 ++++++------- pyqtgraph/Point.py | 2 +- pyqtgraph/functions.py | 7 ++++--- pyqtgraph/multiprocess/remoteproxy.py | 6 +++--- pyqtgraph/opengl/GLViewWidget.py | 4 ++-- pyqtgraph/opengl/__init__.py | 4 ++-- pyqtgraph/opengl/items/GLLinePlotItem.py | 2 +- pyqtgraph/opengl/items/GLScatterPlotItem.py | 2 +- pyqtgraph/opengl/items/GLSurfacePlotItem.py | 4 ++-- pyqtgraph/opengl/shaders.py | 4 ++-- pyqtgraph/widgets/RemoteGraphicsView.py | 2 +- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/__main__.py b/examples/__main__.py index 2ecc810d..4aa23e8e 100644 --- a/examples/__main__.py +++ b/examples/__main__.py @@ -1,13 +1,12 @@ import sys, os, subprocess, time -try: - from . import initExample -except ValueError: - #__package__ = os.path.split(os.path.dirname(__file__))[-1] - sys.excepthook(*sys.exc_info()) - print("examples/ can not be executed as a script; please run 'python -m examples' instead.") - sys.exit(1) +if __name__ == "__main__" and (__package__ is None or __package__==''): + parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + sys.path.insert(0, parent_dir) + import examples + __package__ = "examples" +from . import initExample from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE if USE_PYSIDE: diff --git a/pyqtgraph/Point.py b/pyqtgraph/Point.py index 682f19f7..4d04f01c 100644 --- a/pyqtgraph/Point.py +++ b/pyqtgraph/Point.py @@ -152,4 +152,4 @@ class Point(QtCore.QPointF): return Point(self) def toQPoint(self): - return QtCore.QPoint(*self) \ No newline at end of file + return QtCore.QPoint(*self) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 5a78616d..1c179995 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -5,6 +5,7 @@ Copyright 2010 Luke Campagnola Distributed under MIT/X11 license. See license.txt for more infomation. """ +from __future__ import division from .python2_3 import asUnicode Colors = { 'b': (0,0,255,255), @@ -1864,9 +1865,9 @@ def isosurface(data, level): for i in [0,1,2]: vim = vertexInds[:,3] == i vi = vertexInds[vim, :3] - viFlat = (vi * (np.array(data.strides[:3]) / data.itemsize)[np.newaxis,:]).sum(axis=1) + viFlat = (vi * (np.array(data.strides[:3]) // data.itemsize)[np.newaxis,:]).sum(axis=1) v1 = dataFlat[viFlat] - v2 = dataFlat[viFlat + data.strides[i]/data.itemsize] + v2 = dataFlat[viFlat + data.strides[i]//data.itemsize] vertexes[vim,i] += (level-v1) / (v2-v1) ### compute the set of vertex indexes for each face. @@ -1892,7 +1893,7 @@ def isosurface(data, level): #p = debug.Profiler('isosurface', disabled=False) ## this helps speed up an indexing operation later on - cs = np.array(cutEdges.strides)/cutEdges.itemsize + cs = np.array(cutEdges.strides)//cutEdges.itemsize cutEdges = cutEdges.flatten() ## this, strangely, does not seem to help. diff --git a/pyqtgraph/multiprocess/remoteproxy.py b/pyqtgraph/multiprocess/remoteproxy.py index f33ebc83..7622b6e7 100644 --- a/pyqtgraph/multiprocess/remoteproxy.py +++ b/pyqtgraph/multiprocess/remoteproxy.py @@ -932,9 +932,9 @@ class ObjectProxy(object): def __ilshift__(self, *args): return self._getSpecialAttr('__ilshift__')(*args, _callSync='off') - def __eq__(self, *args): - return self._getSpecialAttr('__eq__')(*args) - + #def __eq__(self, *args): + # return self._getSpecialAttr('__eq__')(*args) + def __ne__(self, *args): return self._getSpecialAttr('__ne__')(*args) diff --git a/pyqtgraph/opengl/GLViewWidget.py b/pyqtgraph/opengl/GLViewWidget.py index 12984c86..1cd3a047 100644 --- a/pyqtgraph/opengl/GLViewWidget.py +++ b/pyqtgraph/opengl/GLViewWidget.py @@ -139,7 +139,7 @@ class GLViewWidget(QtOpenGL.QGLWidget): else: items = item.childItems() items.append(item) - items.sort(lambda a,b: cmp(a.depthValue(), b.depthValue())) + items.sort(key=lambda x: x.depthValue()) for i in items: if not i.visible(): continue @@ -154,7 +154,7 @@ class GLViewWidget(QtOpenGL.QGLWidget): ver = glGetString(GL_VERSION) if ver is not None: ver = ver.split()[0] - if int(ver.split('.')[0]) < 2: + if int(ver.split(b'.')[0]) < 2: print(msg + " The original exception is printed above; however, pyqtgraph requires OpenGL version 2.0 or greater for many of its 3D features and your OpenGL version is %s. Installing updated display drivers may resolve this issue." % ver) else: print(msg) diff --git a/pyqtgraph/opengl/__init__.py b/pyqtgraph/opengl/__init__.py index 199c372c..5345e187 100644 --- a/pyqtgraph/opengl/__init__.py +++ b/pyqtgraph/opengl/__init__.py @@ -23,8 +23,8 @@ from pyqtgraph import importAll importAll('items', globals(), locals()) \ -from MeshData import MeshData +from .MeshData import MeshData ## for backward compatibility: #MeshData.MeshData = MeshData ## breaks autodoc. -import shaders +from . import shaders diff --git a/pyqtgraph/opengl/items/GLLinePlotItem.py b/pyqtgraph/opengl/items/GLLinePlotItem.py index bb5ce2f6..888af664 100644 --- a/pyqtgraph/opengl/items/GLLinePlotItem.py +++ b/pyqtgraph/opengl/items/GLLinePlotItem.py @@ -83,7 +83,7 @@ class GLLinePlotItem(GLGraphicsItem): glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - glDrawArrays(GL_LINE_STRIP, 0, self.pos.size / self.pos.shape[-1]) + glDrawArrays(GL_LINE_STRIP, 0, int(self.pos.size / self.pos.shape[-1])) finally: glDisableClientState(GL_VERTEX_ARRAY) diff --git a/pyqtgraph/opengl/items/GLScatterPlotItem.py b/pyqtgraph/opengl/items/GLScatterPlotItem.py index e9bbde64..b02a9dda 100644 --- a/pyqtgraph/opengl/items/GLScatterPlotItem.py +++ b/pyqtgraph/opengl/items/GLScatterPlotItem.py @@ -146,7 +146,7 @@ class GLScatterPlotItem(GLGraphicsItem): else: glNormal3f(self.size, 0, 0) ## vertex shader uses norm.x to determine point size #glPointSize(self.size) - glDrawArrays(GL_POINTS, 0, pos.size / pos.shape[-1]) + glDrawArrays(GL_POINTS, 0, int(pos.size / pos.shape[-1])) finally: glDisableClientState(GL_NORMAL_ARRAY) glDisableClientState(GL_VERTEX_ARRAY) diff --git a/pyqtgraph/opengl/items/GLSurfacePlotItem.py b/pyqtgraph/opengl/items/GLSurfacePlotItem.py index 46c54fc2..88d50fac 100644 --- a/pyqtgraph/opengl/items/GLSurfacePlotItem.py +++ b/pyqtgraph/opengl/items/GLSurfacePlotItem.py @@ -1,5 +1,5 @@ from OpenGL.GL import * -from GLMeshItem import GLMeshItem +from .GLMeshItem import GLMeshItem from .. MeshData import MeshData from pyqtgraph.Qt import QtGui import pyqtgraph as pg @@ -136,4 +136,4 @@ class GLSurfacePlotItem(GLMeshItem): start = row * cols * 2 faces[start:start+cols] = rowtemplate1 + row * (cols+1) faces[start+cols:start+(cols*2)] = rowtemplate2 + row * (cols+1) - self._faces = faces \ No newline at end of file + self._faces = faces diff --git a/pyqtgraph/opengl/shaders.py b/pyqtgraph/opengl/shaders.py index b1652850..e8ca28d9 100644 --- a/pyqtgraph/opengl/shaders.py +++ b/pyqtgraph/opengl/shaders.py @@ -354,7 +354,7 @@ class ShaderProgram(object): def uniform(self, name): """Return the location integer for a uniform variable in this program""" - return glGetUniformLocation(self.program(), name) + return glGetUniformLocation(self.program(), bytes(name,'utf_8')) #def uniformBlockInfo(self, blockName): #blockIndex = glGetUniformBlockIndex(self.program(), blockName) @@ -390,4 +390,4 @@ class HeightColorShader(ShaderProgram): ## bind buffer to the same binding point glBindBufferBase(GL_UNIFORM_BUFFER, bindPoint, buf) -initShaders() \ No newline at end of file +initShaders() diff --git a/pyqtgraph/widgets/RemoteGraphicsView.py b/pyqtgraph/widgets/RemoteGraphicsView.py index d1a21e97..80f0fb4b 100644 --- a/pyqtgraph/widgets/RemoteGraphicsView.py +++ b/pyqtgraph/widgets/RemoteGraphicsView.py @@ -128,7 +128,7 @@ class Renderer(GraphicsView): self.shm = mmap.mmap(-1, mmap.PAGESIZE, self.shmtag) # use anonymous mmap on windows else: self.shmFile = tempfile.NamedTemporaryFile(prefix='pyqtgraph_shmem_') - self.shmFile.write('\x00' * mmap.PAGESIZE) + self.shmFile.write(b'\x00' * (mmap.PAGESIZE+1)) fd = self.shmFile.fileno() self.shm = mmap.mmap(fd, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_WRITE) atexit.register(self.close) From c0eec1862cf238e86fd6bb592dee937651eba1c9 Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Fri, 5 Jul 2013 00:08:41 +0800 Subject: [PATCH 2/3] revert mess create by git-bzr From dfa2c8a502c93d464238b58aa3feb24582212ab3 Mon Sep 17 00:00:00 2001 From: Guillaume Poulin Date: Thu, 5 Sep 2013 04:37:41 +0800 Subject: [PATCH 3/3] solve some issue with opengl and python3 --- pyqtgraph/opengl/shaders.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/opengl/shaders.py b/pyqtgraph/opengl/shaders.py index 515de33a..8f0d6e1b 100644 --- a/pyqtgraph/opengl/shaders.py +++ b/pyqtgraph/opengl/shaders.py @@ -1,4 +1,7 @@ -import OpenGL +try: + from OpenGL import NullFunctionError +except ImportError: + from OpenGL.error import NullFunctionError from OpenGL.GL import * from OpenGL.GL import shaders import re @@ -219,7 +222,7 @@ class Shader(object): if self.compiled is None: try: self.compiled = shaders.compileShader(self.code, self.shaderType) - except OpenGL.NullFunctionError: + except NullFunctionError: raise Exception("This OpenGL implementation does not support shader programs; many features on pyqtgraph will not work.") except RuntimeError as exc: ## Format compile errors a bit more nicely @@ -227,9 +230,12 @@ class Shader(object): err, code, typ = exc.args if not err.startswith('Shader compile failure'): raise - code = code[0].split('\n') + code = code[0].decode('utf_8').split('\n') err, c, msgs = err.partition(':') err = err + '\n' + msgs = re.sub('b\'','',msgs) + msgs = re.sub('\'$','',msgs) + msgs = re.sub('\\\\n','\n',msgs) msgs = msgs.split('\n') errNums = [()] * len(code) for i, msg in enumerate(msgs): @@ -357,7 +363,7 @@ class ShaderProgram(object): def uniform(self, name): """Return the location integer for a uniform variable in this program""" - return glGetUniformLocation(self.program(), bytes(name,'utf_8')) + return glGetUniformLocation(self.program(), name.encode('utf_8')) #def uniformBlockInfo(self, blockName): #blockIndex = glGetUniformBlockIndex(self.program(), blockName)