Removed some debugging code, moved examples
This commit is contained in:
parent
3d84aefbc4
commit
11897061d1
@ -234,11 +234,11 @@ class GraphicsView(QtGui.QGraphicsView):
|
|||||||
|
|
||||||
def mousePressEvent(self, ev):
|
def mousePressEvent(self, ev):
|
||||||
QtGui.QGraphicsView.mousePressEvent(self, ev)
|
QtGui.QGraphicsView.mousePressEvent(self, ev)
|
||||||
print "Press over:"
|
#print "Press over:"
|
||||||
for i in self.items(ev.pos()):
|
#for i in self.items(ev.pos()):
|
||||||
print i.zValue(), int(i.acceptedMouseButtons()), i, i.scenePos()
|
#print i.zValue(), int(i.acceptedMouseButtons()), i, i.scenePos()
|
||||||
print "Event accepted:", ev.isAccepted()
|
#print "Event accepted:", ev.isAccepted()
|
||||||
print "Grabber:", self.scene().mouseGrabberItem()
|
#print "Grabber:", self.scene().mouseGrabberItem()
|
||||||
if not self.mouseEnabled:
|
if not self.mouseEnabled:
|
||||||
return
|
return
|
||||||
self.lastMousePos = Point(ev.pos())
|
self.lastMousePos = Point(ev.pos())
|
||||||
|
@ -13,7 +13,7 @@ try:
|
|||||||
from metaarray import *
|
from metaarray import *
|
||||||
HAVE_METAARRAY = True
|
HAVE_METAARRAY = True
|
||||||
except:
|
except:
|
||||||
raise
|
#raise
|
||||||
HAVE_METAARRAY = False
|
HAVE_METAARRAY = False
|
||||||
|
|
||||||
|
|
||||||
|
49
examples/test_ImageItem.py
Normal file
49
examples/test_ImageItem.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
|
from pyqtgraph.GraphicsView import *
|
||||||
|
from pyqtgraph.graphicsItems import *
|
||||||
|
from numpy import random
|
||||||
|
from PyQt4 import QtCore, QtGui
|
||||||
|
from scipy.ndimage import *
|
||||||
|
|
||||||
|
app = QtGui.QApplication([])
|
||||||
|
|
||||||
|
## Create window with GraphicsView widget
|
||||||
|
win = QtGui.QMainWindow()
|
||||||
|
view = GraphicsView()
|
||||||
|
win.setCentralWidget(view)
|
||||||
|
win.show()
|
||||||
|
|
||||||
|
## Allow mouse scale/pan
|
||||||
|
view.enableMouse()
|
||||||
|
|
||||||
|
## ..But lock the aspect ratio
|
||||||
|
view.setAspectLocked(True)
|
||||||
|
|
||||||
|
## Create image item
|
||||||
|
img = ImageItem()
|
||||||
|
view.scene().addItem(img)
|
||||||
|
|
||||||
|
## Set initial view bounds
|
||||||
|
view.setRange(QtCore.QRectF(0, 0, 200, 200))
|
||||||
|
|
||||||
|
def updateData():
|
||||||
|
global img
|
||||||
|
## Create random image
|
||||||
|
data = random.random((200, 200))
|
||||||
|
|
||||||
|
## Display the data
|
||||||
|
img.updateImage(data)
|
||||||
|
|
||||||
|
|
||||||
|
# update image data every 20ms (or so)
|
||||||
|
t = QtCore.QTimer()
|
||||||
|
QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData)
|
||||||
|
t.start(20)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.exec_()
|
@ -1,21 +1,30 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
from ImageView import *
|
from pyqtgraph.ImageView import *
|
||||||
from numpy import random
|
from numpy import random
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
from scipy.ndimage import *
|
from scipy.ndimage import *
|
||||||
|
|
||||||
app = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
|
|
||||||
|
## Create window with ImageView widget
|
||||||
win = QtGui.QMainWindow()
|
win = QtGui.QMainWindow()
|
||||||
imv = ImageView()
|
imv = ImageView()
|
||||||
win.setCentralWidget(imv)
|
win.setCentralWidget(imv)
|
||||||
win.show()
|
win.show()
|
||||||
|
|
||||||
|
## Create random 3D data set
|
||||||
img = gaussian_filter(random.random((200, 200)), (5, 5)) * 5
|
img = gaussian_filter(random.random((200, 200)), (5, 5)) * 5
|
||||||
data = random.random((100, 200, 200))
|
data = random.random((100, 200, 200))
|
||||||
data += img
|
data += img
|
||||||
|
|
||||||
for i in range(data.shape[0]):
|
for i in range(data.shape[0]):
|
||||||
data[i] += exp(-(2.*i)/data.shape[0])
|
data[i] += exp(-(2.*i)/data.shape[0])
|
||||||
data += 10
|
data += 10
|
||||||
imv.setImage(data)
|
|
||||||
|
## Display the data
|
||||||
|
imv.setImage(data)
|
||||||
|
|
||||||
|
app.exec_()
|
@ -1,12 +1,19 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
from scipy import random
|
from scipy import random
|
||||||
from numpy import linspace
|
from numpy import linspace
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from MultiPlotWidget import *
|
from pyqtgraph.MultiPlotWidget import *
|
||||||
from metaarray import *
|
try:
|
||||||
|
from metaarray import *
|
||||||
|
except:
|
||||||
|
print "MultiPlot is only used with MetaArray for now (and you do not have the metaarray module)"
|
||||||
|
exit()
|
||||||
|
|
||||||
app = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
mw = QtGui.QMainWindow()
|
mw = QtGui.QMainWindow()
|
||||||
pw = MultiPlotWidget()
|
pw = MultiPlotWidget()
|
||||||
@ -15,3 +22,5 @@ mw.show()
|
|||||||
|
|
||||||
ma = MetaArray(random.random((3, 1000)), info=[{'name': 'Signal', 'cols': [{'name': 'Col1'}, {'name': 'Col2'}, {'name': 'Col3'}]}, {'name': 'Time', 'vals': linspace(0., 1., 1000)}])
|
ma = MetaArray(random.random((3, 1000)), info=[{'name': 'Signal', 'cols': [{'name': 'Col1'}, {'name': 'Col2'}, {'name': 'Col3'}]}, {'name': 'Time', 'vals': linspace(0., 1., 1000)}])
|
||||||
pw.plot(ma)
|
pw.plot(ma)
|
||||||
|
|
||||||
|
app.exec_()
|
@ -1,10 +1,13 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
from scipy import random
|
from scipy import random
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from PlotWidget import *
|
from pyqtgraph.PlotWidget import *
|
||||||
from graphicsItems import *
|
from pyqtgraph.graphicsItems import *
|
||||||
|
|
||||||
|
|
||||||
app = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
@ -77,4 +80,4 @@ for i in range(0, 5):
|
|||||||
yd, xd = rand(10000)
|
yd, xd = rand(10000)
|
||||||
pw2.plot(yd*(j+1), xd, params={'iter': i, 'val': j})
|
pw2.plot(yd*(j+1), xd, params={'iter': i, 'val': j})
|
||||||
|
|
||||||
#app.exec_()
|
app.exec_()
|
@ -1,13 +1,17 @@
|
|||||||
#!/usr/bin/python -i
|
#!/usr/bin/python -i
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
from scipy import zeros
|
from scipy import zeros
|
||||||
from graphicsWindows import *
|
from pyqtgraph.graphicsWindows import *
|
||||||
from graphicsItems import *
|
from pyqtgraph.graphicsItems import *
|
||||||
from widgets import *
|
from pyqtgraph.widgets import *
|
||||||
from PlotWidget import *
|
from pyqtgraph.PlotWidget import *
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
qapp = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
|
|
||||||
#i = PlotWindow(array([0,1,2,1,2]), parent=None, title='')
|
#i = PlotWindow(array([0,1,2,1,2]), parent=None, title='')
|
||||||
|
|
||||||
@ -85,4 +89,5 @@ mlroi.connect(QtCore.SIGNAL('regionChanged'), lambda: updateImg(mlroi))
|
|||||||
|
|
||||||
v.setRange(QtCore.QRect(-2, -2, 220, 220))
|
v.setRange(QtCore.QRect(-2, -2, 220, 220))
|
||||||
|
|
||||||
w.show()
|
w.show()
|
||||||
|
app.exec_()
|
@ -1,11 +1,13 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
## Add path to library (just for examples; you do not need this)
|
||||||
|
import sys, os
|
||||||
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
from scipy import random
|
from scipy import random
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
from GraphicsView import *
|
from pyqtgraph.GraphicsView import *
|
||||||
from graphicsItems import *
|
from pyqtgraph.graphicsItems import *
|
||||||
|
|
||||||
|
|
||||||
app = QtGui.QApplication([])
|
app = QtGui.QApplication([])
|
||||||
mw = QtGui.QMainWindow()
|
mw = QtGui.QMainWindow()
|
||||||
@ -19,7 +21,6 @@ mw.resize(800, 600)
|
|||||||
|
|
||||||
gv = GraphicsView(cw)
|
gv = GraphicsView(cw)
|
||||||
gv.enableMouse(False)
|
gv.enableMouse(False)
|
||||||
#w1 = QtGui.QGraphicsWidget()
|
|
||||||
l = QtGui.QGraphicsGridLayout()
|
l = QtGui.QGraphicsGridLayout()
|
||||||
l.setHorizontalSpacing(0)
|
l.setHorizontalSpacing(0)
|
||||||
l.setVerticalSpacing(0)
|
l.setVerticalSpacing(0)
|
||||||
@ -27,46 +28,23 @@ l.setVerticalSpacing(0)
|
|||||||
|
|
||||||
vb = ViewBox()
|
vb = ViewBox()
|
||||||
p1 = PlotCurveItem()
|
p1 = PlotCurveItem()
|
||||||
#gv.scene().addItem(vb)
|
|
||||||
vb.addItem(p1)
|
vb.addItem(p1)
|
||||||
vl.addWidget(gv)
|
vl.addWidget(gv)
|
||||||
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1))
|
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1))
|
||||||
rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100)))
|
rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100)))
|
||||||
vb.addItem(rect)
|
vb.addItem(rect)
|
||||||
|
|
||||||
l.addItem(vb, 0, 2)
|
l.addItem(vb, 0, 1)
|
||||||
gv.centralWidget.setLayout(l)
|
gv.centralWidget.setLayout(l)
|
||||||
|
|
||||||
|
|
||||||
xScale = ScaleItem(orientation='bottom', linkView=vb)
|
xScale = ScaleItem(orientation='bottom', linkView=vb)
|
||||||
l.addItem(xScale, 1, 2)
|
l.addItem(xScale, 1, 1)
|
||||||
yScale = ScaleItem(orientation='left', linkView=vb)
|
yScale = ScaleItem(orientation='left', linkView=vb)
|
||||||
l.addItem(yScale, 0, 1)
|
l.addItem(yScale, 0, 0)
|
||||||
|
|
||||||
xLabel = LabelItem(u"<span style='color: #ff0000; font-weight: bold'>X</span> <i>Axis</i> <span style='font-size: 6pt'>(μV)</span>", html=True, color='CCC')
|
xScale.setLabel(text=u"<span style='color: #ff0000; font-weight: bold'>X</span> <i>Axis</i>", units="s")
|
||||||
l.setRowFixedHeight(2, 20)
|
yScale.setLabel('Y Axis', units='V')
|
||||||
l.setRowFixedHeight(1, 40)
|
|
||||||
l.addItem(xLabel, 2, 2)
|
|
||||||
yLabel = LabelItem("Y Axis", color=QtGui.QColor(200, 200, 200))
|
|
||||||
yLabel.setAngle(90)
|
|
||||||
l.setColumnFixedWidth(0, 20)
|
|
||||||
l.setColumnFixedWidth(1, 60)
|
|
||||||
l.addItem(yLabel, 0, 0)
|
|
||||||
|
|
||||||
|
|
||||||
#grid = GridItem(gv)
|
|
||||||
#vb.addItem(grid)
|
|
||||||
|
|
||||||
#gv.scene().addItem(w1)
|
|
||||||
#w1.setGeometry(0, 0, 1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
#c1 = Qwt.QwtPlotCurve()
|
|
||||||
#c1.setData(range(len(data)), data)
|
|
||||||
#c1.attach(p1)
|
|
||||||
#c2 = PlotCurve()
|
|
||||||
#c2.setData([1,2,3,4,5,6,7,8], [1,2,10,4,3,2,4,1])
|
|
||||||
#c2.attach(p2)
|
|
||||||
|
|
||||||
def rand(n):
|
def rand(n):
|
||||||
data = random.random(n)
|
data = random.random(n)
|
||||||
@ -74,23 +52,14 @@ def rand(n):
|
|||||||
data[int(n*0.18)] += 2
|
data[int(n*0.18)] += 2
|
||||||
data[int(n*0.1):int(n*0.13)] *= 5
|
data[int(n*0.1):int(n*0.13)] *= 5
|
||||||
data[int(n*0.18)] *= 20
|
data[int(n*0.18)] *= 20
|
||||||
#c1.setData(range(len(data)), data)
|
|
||||||
return data, arange(n, n+len(data)) / float(n)
|
return data, arange(n, n+len(data)) / float(n)
|
||||||
|
|
||||||
|
|
||||||
def updateData():
|
def updateData():
|
||||||
yd, xd = rand(10000)
|
yd, xd = rand(10000)
|
||||||
p1.updateData(yd, x=xd)
|
p1.updateData(yd, x=xd)
|
||||||
|
|
||||||
#vb.setRange(p1.boundingRect())
|
|
||||||
#p1.plot(yd, x=xd, clear=True)
|
|
||||||
|
|
||||||
yd, xd = rand(10000)
|
yd, xd = rand(10000)
|
||||||
#p2.plot(yd * 1000, x=xd)
|
|
||||||
#for i in [1,2]:
|
|
||||||
#for j in range(3):
|
|
||||||
#yd, xd = rand(1000)
|
|
||||||
#p3.plot(yd * 100000 * i, x=xd, params={'repetitions': j, 'scale': i})
|
|
||||||
updateData()
|
updateData()
|
||||||
vb.autoRange()
|
vb.autoRange()
|
||||||
|
|
||||||
@ -98,3 +67,4 @@ t = QtCore.QTimer()
|
|||||||
QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData)
|
QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData)
|
||||||
t.start(50)
|
t.start(50)
|
||||||
|
|
||||||
|
app.exec_()
|
@ -631,14 +631,14 @@ class Handle(QtGui.QGraphicsItem):
|
|||||||
return self.bounds
|
return self.bounds
|
||||||
|
|
||||||
def mousePressEvent(self, ev):
|
def mousePressEvent(self, ev):
|
||||||
print "handle press"
|
#print "handle press"
|
||||||
if ev.button() != QtCore.Qt.LeftButton:
|
if ev.button() != QtCore.Qt.LeftButton:
|
||||||
ev.ignore()
|
ev.ignore()
|
||||||
return
|
return
|
||||||
self.cursorOffset = self.scenePos() - ev.scenePos()
|
self.cursorOffset = self.scenePos() - ev.scenePos()
|
||||||
for r in self.roi:
|
for r in self.roi:
|
||||||
r[0].pointPressEvent(r[1], ev)
|
r[0].pointPressEvent(r[1], ev)
|
||||||
print " accepted."
|
#print " accepted."
|
||||||
ev.accept()
|
ev.accept()
|
||||||
|
|
||||||
def mouseReleaseEvent(self, ev):
|
def mouseReleaseEvent(self, ev):
|
||||||
|
Loading…
Reference in New Issue
Block a user