Merged testing code from Kratz

Numerous fixes for python 3 compatibility
This commit is contained in:
Luke Campagnola 2012-12-05 00:25:45 -05:00
commit 3de5719011
63 changed files with 366 additions and 193 deletions

4
Qt.py
View File

@ -42,7 +42,7 @@ else:
versionReq = [4, 7]
QtVersion = PySide.QtCore.__version__ if USE_PYSIDE else QtCore.QT_VERSION_STR
m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and map(int, m.groups()) < versionReq:
print map(int, m.groups())
if m is not None and list(map(int, m.groups())) < versionReq:
print(map(int, m.groups()))
raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion))

View File

@ -22,7 +22,7 @@ if sys.version_info[0] < 2 or (sys.version_info[0] == 2 and sys.version_info[1]
from . import python2_3
## install workarounds for numpy bugs
import numpy_fix
from . import numpy_fix
## in general openGL is poorly supported with Qt+GraphicsView.
## we only enable it where the performance benefit is critical.
@ -111,7 +111,7 @@ if not hasattr(sys, 'frozen'): ## If we are frozen, there's a good chance we don
## Import almost everything to make it available from a single namespace
## don't import the more complex systems--canvas, parametertree, flowchart, dockarea
## these must be imported separately.
import frozenSupport
from . import frozenSupport
def importModules(path, globals, locals, excludes=()):
"""Import all modules residing within *path*, return a dict of name: module pairs.

View File

@ -1,8 +1,8 @@
MeshData
========
.. autoclass:: pyqtgraph.opengl.MeshData.MeshData
.. autoclass:: pyqtgraph.opengl.MeshData
:members:
.. automethod:: pyqtgraph.opengl.MeshData.MeshData.__init__
.. automethod:: pyqtgraph.opengl.MeshData.__init__

View File

@ -48,6 +48,7 @@ anim = a.makeAnimation(loop=-1)
anim.start()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -15,6 +15,7 @@ pg.show(data, title="Simplest possible image example")
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()

View File

@ -25,6 +25,7 @@ btn.sigColorChanging.connect(change)
btn.sigColorChanged.connect(done)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -23,6 +23,7 @@ c = pyqtgraph.console.ConsoleWidget(namespace=namespace, text=text)
c.show()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
## Add path to library (just for examples; you do not need this)
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
import initExample
import numpy as np
import scipy
@ -52,5 +50,7 @@ imv1.setLevels(-0.003, 0.003)
update()
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -30,6 +30,7 @@ tree.resize(600,600)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -36,6 +36,7 @@ img.setDrawKernel(kern, mask=kern, center=(1,1), mode='add')
img.setLevels([0, 10])
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -97,6 +97,7 @@ fc.connectTerminals(fNode.Out, fc.dataOut)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -43,5 +43,7 @@ ax = gl.GLAxisItem()
w.addItem(ax)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -47,7 +47,7 @@ data = np.abs(np.fromfunction(psi, (50,50,100)))
print("Generating isosurface..")
verts = pg.isosurface(data, data.max()/4.)
md = gl.MeshData.MeshData(vertexes=verts)
md = gl.MeshData(vertexes=verts)
colors = np.ones((md.faceCount(), 4), dtype=float)
colors[:,3] = 0.2
@ -68,5 +68,7 @@ m2.translate(-25, -25, -50)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -129,5 +129,7 @@ w.addItem(m3)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -102,5 +102,7 @@ t.start(50)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -94,5 +94,7 @@ timer.timeout.connect(update)
timer.start(30)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -24,5 +24,7 @@ ax2.setParentItem(b)
b.translate(1,1,1)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -59,5 +59,7 @@ ax = gl.GLAxisItem()
w.addItem(ax)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -104,5 +104,7 @@ w.addItem(m6)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -23,5 +23,7 @@ mw.setCentralItem(ge)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -40,9 +40,10 @@ l.addWidget(label, 1, 1)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -74,5 +74,7 @@ p5.plot([1,3,2,4,3,5])
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -61,5 +61,7 @@ vb.addItem(g)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -45,5 +45,7 @@ w.setImageItem(img)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -54,5 +54,7 @@ def updateData():
updateData()
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -43,5 +43,7 @@ data[:,50:60,50:60] += sig
imv.setImage(data, xvals=np.linspace(1., 3., data.shape[0]))
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -47,6 +47,7 @@ timer.start(30)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -17,6 +17,7 @@ c2 = plt.plot([2,1,4,3], pen='g', fillLevel=0, fillBrush=(255,255,255,30), name=
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -27,6 +27,8 @@ ma = MetaArray(random.random((3, 1000)), info=[{'name': 'Signal', 'cols': [{'nam
pw.plot(ma)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -42,7 +42,8 @@ timer.start(50)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -50,5 +50,7 @@ timer.start(0)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -80,6 +80,7 @@ pw3.addItem(line)
line.setBounds([0,200])
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -92,7 +92,7 @@ p9.sigXRangeChanged.connect(updateRegion)
updatePlot()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -143,6 +143,7 @@ v4.autoRange()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -124,5 +124,7 @@ t.start(50)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -14,6 +14,7 @@ plt.plot([1,4,2,3,6,2,3,4,2,3], pen='g')
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -89,6 +89,8 @@ s4.sigClicked.connect(clicked)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -58,5 +58,7 @@ timer.start(0)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -100,6 +100,7 @@ layout.addWidget(changedLabel, 2, 1)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -44,6 +44,7 @@ b1 = QtGui.QPushButton("Button")
w.setItemWidget(i1, 1, b1)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -151,6 +151,7 @@ timer.start(0)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -96,5 +96,7 @@ t.timeout.connect(updateData)
t.start(50)
## Start Qt event loop unless running in interactive mode.
if sys.flags.interactive != 1:
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -1,4 +1,4 @@
import sys, os
import sys, os, subprocess, time
## make sure this pyqtgraph is importable before any others
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
@ -151,5 +151,82 @@ def run():
app.exec_()
def buildFileList(examples, files=None):
if files == None:
files = []
for key, val in examples.items():
#item = QtGui.QTreeWidgetItem([key])
if isinstance(val, basestring):
#item.file = val
files.append((key,val))
else:
buildFileList(val, files)
return files
def testFile(name, f, exe, lib):
global path
fn = os.path.join(path,f)
#print "starting process: ", fn
sys.stdout.write(name)
sys.stdout.flush()
code = """
try:
%s
import %s
print("test complete")
import pyqtgraph as pg
while True: ## run a little event loop
pg.QtGui.QApplication.processEvents()
time.sleep(0.01)
except:
print("test failed")
raise
""" % ("import %s" % lib if lib != '' else "", os.path.splitext(os.path.split(fn)[1])[0])
#print code
process = subprocess.Popen(['%s -i' % (exe)], shell=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
process.stdin.write(code.encode('UTF-8'))
#process.stdin.close()
output = ''
fail = False
while True:
c = process.stdout.read(1).decode()
output += c
#sys.stdout.write(c)
#sys.stdout.flush()
if output.endswith('test complete'):
break
if output.endswith('test failed'):
fail = True
break
time.sleep(1)
process.terminate()
res = process.communicate()
#if 'exception' in res[1].lower() or 'error' in res[1].lower():
if fail:
print('.' * (50-len(name)) + 'FAILED')
print(res[0].decode())
print(res[1].decode())
else:
print('.' * (50-len(name)) + 'passed')
if __name__ == '__main__':
run()
if '--test' in sys.argv[1:]:
files = buildFileList(examples)
if '--pyside' in sys.argv[1:]:
lib = 'PySide'
elif '--pyqt' in sys.argv[1:]:
lib = 'PyQt4'
else:
lib = ''
exe = sys.executable
print("Running tests:", lib, sys.executable)
for f in files:
testFile(f[0], f[1], exe, lib)
else:
run()

View File

@ -72,6 +72,7 @@ proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -15,11 +15,35 @@ import time
class DateAxis(pg.AxisItem):
def tickStrings(self, values, scale, spacing):
strns = []
rng = max(values)-min(values)
#if rng < 120:
# return pg.AxisItem.tickStrings(self, values, scale, spacing)
if rng < 3600*24:
string = '%H:%M:%S'
label1 = '%b %d -'
label2 = ' %b %d, %Y'
elif rng >= 3600*24 and rng < 3600*24*30:
string = '%d'
label1 = '%b - '
label2 = '%b, %Y'
elif rng >= 3600*24*30 and rng < 3600*24*30*24:
string = '%b'
label1 = '%Y -'
label2 = ' %Y'
elif rng >=3600*24*30*24:
string = '%Y'
label1 = ''
label2 = ''
for x in values:
try:
strns.append(time.strftime('%b %Y', time.localtime(x)))
strns.append(time.strftime(string, time.localtime(x)))
except ValueError: ## Windows can't handle dates before 1970
strns.append('')
try:
label = time.strftime(label1, time.localtime(min(values)))+time.strftime(label2, time.localtime(max(values)))
except ValueError:
label = ''
#self.setLabel(text=label)
return strns
class CustomViewBox(pg.ViewBox):
@ -53,6 +77,7 @@ r = pg.PolyLineROI([(0,0), (10, 10)])
pw.addItem(r)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -111,6 +111,7 @@ win.show()
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -33,6 +33,7 @@ y = pg.pseudoScatter(vals, spacing=0.15)
plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5, symbolPen=(255,255,255,200), symbolBrush=(0,0,255,150))
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -53,6 +53,7 @@ timer.timeout.connect(update)
timer.start(50)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -42,7 +42,8 @@ p3.setLabel('left', "Label to test offset")
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -33,6 +33,7 @@ p3.plot(x, y)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
app.exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -151,6 +151,7 @@ p.restoreState(s)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -6,6 +6,7 @@ from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -49,6 +49,7 @@ timer.start(10)
## Start Qt event loop unless running in interactive mode or using pyside.
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

View File

@ -782,7 +782,7 @@ def makeARGB(data, lut=None, levels=None, scale=None, useRGBA=False):
if levels.shape != (data.shape[-1], 2):
raise Exception('levels must have shape (data.shape[-1], 2)')
else:
print levels
print(levels)
raise Exception("levels argument must be 1D or 2D.")
#levels = np.array(levels)
#if levels.shape == (2,):
@ -1592,4 +1592,4 @@ def pseudoScatter(data, spacing=None, shuffle=True):
yvals[i] = y
return yvals[np.argsort(inds)] ## un-shuffle values before returning
return yvals[np.argsort(inds)] ## un-shuffle values before returning

View File

@ -80,12 +80,12 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
height = 0
width = 0
print "-------"
#print("-------")
for sample, label in self.items:
height += max(sample.height(), label.height()) + 3
width = max(width, sample.width()+label.width())
print width, height
print width, height
#print(width, height)
#print width, height
self.setGeometry(0, 0, width+25, height)
def boundingRect(self):

View File

@ -1215,7 +1215,7 @@ class ViewBox(GraphicsWidget):
if ViewBox is None: ## can happen as python is shutting down
return
## Called with ID and name of view (the view itself is no longer available)
for v in ViewBox.AllViews.iterkeys():
for v in ViewBox.AllViews.keys():
if id(v) == vid:
ViewBox.AllViews.pop(v)
break

View File

@ -452,42 +452,42 @@ class MeshData(object):
def sphere(rows, cols, radius=1.0, offset=True):
"""
Return a MeshData instance with vertexes and faces computed
for a spherical surface.
"""
verts = np.empty((rows+1, cols, 3), dtype=float)
## compute vertexes
phi = (np.arange(rows+1) * np.pi / rows).reshape(rows+1, 1)
s = radius * np.sin(phi)
verts[...,2] = radius * np.cos(phi)
th = ((np.arange(cols) * 2 * np.pi / cols).reshape(1, cols))
if offset:
th = th + ((np.pi / cols) * np.arange(rows+1).reshape(rows+1,1)) ## rotate each row by 1/2 column
verts[...,0] = s * np.cos(th)
verts[...,1] = s * np.sin(th)
verts = verts.reshape((rows+1)*cols, 3)[cols-1:-(cols-1)] ## remove redundant vertexes from top and bottom
## compute faces
faces = np.empty((rows*cols*2, 3), dtype=np.uint)
rowtemplate1 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 0]])) % cols) + np.array([[0, 0, cols]])
rowtemplate2 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 1]])) % cols) + np.array([[cols, 0, cols]])
for row in range(rows):
start = row * cols * 2
faces[start:start+cols] = rowtemplate1 + row * cols
faces[start+cols:start+(cols*2)] = rowtemplate2 + row * cols
faces = faces[cols:-cols] ## cut off zero-area triangles at top and bottom
## adjust for redundant vertexes that were removed from top and bottom
vmin = cols-1
faces[faces<vmin] = vmin
faces -= vmin
vmax = verts.shape[0]-1
faces[faces>vmax] = vmax
return MeshData(vertexes=verts, faces=faces)
@staticmethod
def sphere(rows, cols, radius=1.0, offset=True):
"""
Return a MeshData instance with vertexes and faces computed
for a spherical surface.
"""
verts = np.empty((rows+1, cols, 3), dtype=float)
## compute vertexes
phi = (np.arange(rows+1) * np.pi / rows).reshape(rows+1, 1)
s = radius * np.sin(phi)
verts[...,2] = radius * np.cos(phi)
th = ((np.arange(cols) * 2 * np.pi / cols).reshape(1, cols))
if offset:
th = th + ((np.pi / cols) * np.arange(rows+1).reshape(rows+1,1)) ## rotate each row by 1/2 column
verts[...,0] = s * np.cos(th)
verts[...,1] = s * np.sin(th)
verts = verts.reshape((rows+1)*cols, 3)[cols-1:-(cols-1)] ## remove redundant vertexes from top and bottom
## compute faces
faces = np.empty((rows*cols*2, 3), dtype=np.uint)
rowtemplate1 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 0]])) % cols) + np.array([[0, 0, cols]])
rowtemplate2 = ((np.arange(cols).reshape(cols, 1) + np.array([[0, 1, 1]])) % cols) + np.array([[cols, 0, cols]])
for row in range(rows):
start = row * cols * 2
faces[start:start+cols] = rowtemplate1 + row * cols
faces[start+cols:start+(cols*2)] = rowtemplate2 + row * cols
faces = faces[cols:-cols] ## cut off zero-area triangles at top and bottom
## adjust for redundant vertexes that were removed from top and bottom
vmin = cols-1
faces[faces<vmin] = vmin
faces -= vmin
vmax = verts.shape[0]-1
faces[faces>vmax] = vmax
return MeshData(vertexes=verts, faces=faces)

View File

@ -25,6 +25,6 @@ importAll('items', globals(), locals())
\
from MeshData import MeshData
## for backward compatibility:
MeshData.MeshData = MeshData
#MeshData.MeshData = MeshData ## breaks autodoc.
import shaders

View File

@ -6,7 +6,10 @@ Provides support for frozen environments as well.
import os, sys, pickle
from ..functions import makeQImage
from ..Qt import QtGui
import pixmapData
if sys.version_info[0] == 2:
from . import pixmapData_2 as pixmapData
else:
from . import pixmapData_3 as pixmapData
def getPixmap(name):
@ -16,7 +19,7 @@ def getPixmap(name):
"""
key = name+'.png'
data = pixmapData.pixmapData[key]
if isinstance(data, basestring):
if isinstance(data, basestring) or isinstance(data, bytes):
pixmapData.pixmapData[key] = pickle.loads(data)
arr = pixmapData.pixmapData[key]
return QtGui.QPixmap(makeQImage(arr, alpha=True))

View File

@ -1,18 +1,19 @@
import numpy as np
from PyQt4 import QtGui
import os, pickle
import os, pickle, sys
path = os.path.split(__file__)[0]
path = os.path.abspath(os.path.split(__file__)[0])
pixmaps = {}
for f in os.listdir(path):
if not f.endswith('.png'):
continue
print f
print(f)
img = QtGui.QImage(os.path.join(path, f))
ptr = img.bits()
ptr.setsize(img.byteCount())
arr = np.asarray(ptr).reshape(img.height(), img.width(), 4).transpose(1,0,2)
pixmaps[f] = pickle.dumps(arr)
fh = open(os.path.join(path, 'pixmapData.py'), 'w')
ver = sys.version_info[0]
fh = open(os.path.join(path, 'pixmapData_%d.py' %ver), 'w')
fh.write("import numpy as np; pixmapData=%s" % repr(pixmaps))

File diff suppressed because one or more lines are too long

1
pixmaps/pixmapData_2.py Normal file

File diff suppressed because one or more lines are too long

1
pixmaps/pixmapData_3.py Normal file

File diff suppressed because one or more lines are too long