minor updates / fixes

This commit is contained in:
Luke Campagnola 2010-07-25 00:33:26 -04:00
parent 2ca08c69ce
commit 39cf791fba
4 changed files with 70 additions and 49 deletions

View File

@ -9,12 +9,11 @@ from pyqtgraph.graphicsWindows import *
from pyqtgraph.graphicsItems import *
from pyqtgraph.widgets import *
from pyqtgraph.PlotWidget import *
from pyqtgraph.functions import mkPen
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication([])
#i = PlotWindow(array([0,1,2,1,2]), parent=None, title='')
class Win(QtGui.QMainWindow):
pass
@ -26,12 +25,8 @@ v.enableMouse(True)
v.autoPixelScale = False
w.setCentralWidget(v)
#s = QtGui.QGraphicsScene()
#v.setScene(s)
s = v.scene()
#p = Plot(array([0,2,1,3,4]), copy=False)
#s.addItem(p)
v.setRange(QtCore.QRect(-2, -2, 220, 220))
arr = ones((100, 100), dtype=float)
arr[45:55, 45:55] = 0
@ -56,41 +51,57 @@ s.addItem(im4)
im4.moveBy(110, 130)
im4.setZValue(10)
pi1 = PlotItem()
s.addItem(pi1)
pi1.scale(0.5, 0.5)
pi1.setGeometry(0, 170, 300, 100)
#g = Grid(view=v, bounds=QtCore.QRectF(0.1, 0.1, 0.8, 0.8))
#g = Grid(view=v)
#s.addItem(g)
lastRoi = None
#wid = RectROI([0, 0], [2, 2], maxBounds=QtCore.QRectF(-1, -1, 5, 5))
roi = TestROI([0, 0], [20, 20], maxBounds=QtCore.QRectF(-10, -10, 230, 140))
s.addItem(roi)
roi2 = LineROI([0, 0], [20, 20], width=5)
s.addItem(roi2)
mlroi = MultiLineROI([[0, 50], [50, 60], [60, 30]], width=5)
s.addItem(mlroi)
elroi = EllipseROI([110, 10], [30, 20])
s.addItem(elroi)
croi = CircleROI([110, 50], [20, 20])
s.addItem(croi)
troi = PolygonROI([[0,0], [1,0], [0,1]])
s.addItem(troi)
def updateRoi(roi):
global im1, im2, im3, im4, arr, lastRoi
if roi is None:
return
lastRoi = roi
arr1 = roi.getArrayRegion(im1.image, img=im1)
im3.updateImage(arr1, autoRange=True)
arr2 = roi.getArrayRegion(im2.image, img=im2)
im4.updateImage(arr2, autoRange=True)
updateRoiPlot(roi, arr1)
def updateRoiPlot(roi, data=None):
if data is None:
data = roi.getArrayRegion(im1.image, img=im1)
if data is not None:
roi.curve.updateData(data.mean(axis=1))
#def updatePlot(roi)
def updateImg(roi):
global im1, im2, im3, im4, arr
arr1 = roi.getArrayRegion(arr, img=im1)
im3.updateImage(arr1, autoRange=True)
arr2 = roi.getArrayRegion(arr, img=im2)
im4.updateImage(arr2, autoRange=True)
rois = []
rois.append(TestROI([0, 0], [20, 20], maxBounds=QtCore.QRectF(-10, -10, 230, 140), pen=mkPen(0)))
rois.append(LineROI([0, 0], [20, 20], width=5, pen=mkPen(1)))
rois.append(MultiLineROI([[0, 50], [50, 60], [60, 30]], width=5, pen=mkPen(2)))
rois.append(EllipseROI([110, 10], [30, 20], pen=mkPen(3)))
rois.append(CircleROI([110, 50], [20, 20], pen=mkPen(4)))
rois.append(PolygonROI([[2,0], [2.1,0], [2,.1]], pen=mkPen(5)))
for r in rois:
s.addItem(r)
c = pi1.plot(pen=r.pen)
r.curve = c
r.connect(r, QtCore.SIGNAL('regionChanged'), updateRoi)
roi.connect(roi, QtCore.SIGNAL('regionChanged'), lambda: updateImg(roi))
roi2.connect(roi2, QtCore.SIGNAL('regionChanged'), lambda: updateImg(roi2))
croi.connect(croi, QtCore.SIGNAL('regionChanged'), lambda: updateImg(croi))
elroi.connect(elroi, QtCore.SIGNAL('regionChanged'), lambda: updateImg(elroi))
mlroi.connect(mlroi, QtCore.SIGNAL('regionChanged'), lambda: updateImg(mlroi))
v.setRange(QtCore.QRect(-2, -2, 220, 220))
def updateImage():
global im1, arr, lastRoi
r = abs(random.normal(loc=0, scale=(arr.max()-arr.min())*0.1, size=arr.shape))
im1.updateImage(arr + r)
updateRoi(lastRoi)
for r in rois:
updateRoiPlot(r)
t = QtCore.QTimer()
t.connect(t, QtCore.SIGNAL('timeout()'), updateImage)
t.start(50)
w.show()
app.exec_()

View File

@ -61,6 +61,8 @@ def mkColor(*args):
(r, g, b, a) = args[0]
else:
raise Exception(err)
if type(args[0]) == int:
return intColor(args[0])
else:
raise Exception(err)
elif len(args) == 3:

View File

@ -12,8 +12,11 @@ from PyQt4 import QtGui, QtCore
from ObjectWorkaround import *
#tryWorkaround(QtCore, QtGui)
from numpy import *
import scipy.weave as weave
from scipy.weave import converters
try:
import scipy.weave as weave
from scipy.weave import converters
except:
pass
from scipy.fftpack import fft
from scipy.signal import resample
import scipy.stats
@ -509,8 +512,6 @@ class PlotCurveItem(GraphicsObject):
elif data.ndim == 1:
y = data
if x.shape != y.shape:
raise Exception("X and Y arrays must be the same shape--got %s and %s." % (str(x.shape), str(y.shape)))
self.prepareGeometryChange()
if copy:
self.yData = y.copy()
@ -523,8 +524,11 @@ class PlotCurveItem(GraphicsObject):
self.xData = x
if x is None:
self.xData = arange(0, self.y.shape[0])
self.xData = arange(0, self.yData.shape[0])
if self.xData.shape != self.yData.shape:
raise Exception("X and Y arrays must be the same shape--got %s and %s." % (str(x.shape), str(y.shape)))
self.path = None
#self.specPath = None
self.xDisp = self.yDisp = None

View File

@ -33,7 +33,7 @@ def rectStr(r):
class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
def __init__(self, pos, size=Point(1, 1), angle=0.0, invertible=False, maxBounds=None, snapSize=1.0, scaleSnap=False, translateSnap=False, rotateSnap=False, parent=None):
def __init__(self, pos, size=Point(1, 1), angle=0.0, invertible=False, maxBounds=None, snapSize=1.0, scaleSnap=False, translateSnap=False, rotateSnap=False, parent=None, pen=None):
QObjectWorkaround.__init__(self)
QtGui.QGraphicsItem.__init__(self, parent)
pos = Point(pos)
@ -41,7 +41,10 @@ class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
self.aspectLocked = False
self.translatable = True
self.pen = QtGui.QPen(QtGui.QColor(255, 255, 255))
if pen is None:
self.pen = QtGui.QPen(QtGui.QColor(255, 255, 255))
else:
self.pen = pen
self.handlePen = QtGui.QPen(QtGui.QColor(150, 255, 255))
self.handles = []
self.state = {'pos': pos, 'size': size, 'angle': angle}
@ -755,14 +758,15 @@ class LineROI(ROI):
class MultiLineROI(QtGui.QGraphicsItem, QObjectWorkaround):
def __init__(self, points, width, **args):
def __init__(self, points, width, pen=None, **args):
QObjectWorkaround.__init__(self)
QtGui.QGraphicsItem.__init__(self)
self.pen = pen
self.roiArgs = args
if len(points) < 2:
raise Exception("Must start with at least 2 points")
self.lines = []
self.lines.append(ROI([0, 0], [1, 5], parent=self))
self.lines.append(ROI([0, 0], [1, 5], parent=self, pen=pen, **args))
self.lines[-1].addScaleHandle([0.5, 1], [0.5, 0.5])
h = self.lines[-1].addScaleRotateHandle([0, 0.5], [1, 0.5])
h.movePoint(points[0])
@ -770,7 +774,7 @@ class MultiLineROI(QtGui.QGraphicsItem, QObjectWorkaround):
for i in range(1, len(points)):
h = self.lines[-1].addScaleRotateHandle([1, 0.5], [0, 0.5])
if i < len(points)-1:
self.lines.append(ROI([0, 0], [1, 5], parent=self))
self.lines.append(ROI([0, 0], [1, 5], parent=self, pen=pen, **args))
self.lines[-1].addScaleRotateHandle([0, 0.5], [1, 0.5], item=h)
h.movePoint(points[i])
h.movePoint(points[i])
@ -857,8 +861,8 @@ class CircleROI(EllipseROI):
self.addScaleHandle([0.5*2.**-0.5 + 0.5, 0.5*2.**-0.5 + 0.5], [0.5, 0.5])
class PolygonROI(ROI):
def __init__(self, positions):
ROI.__init__(self, [0,0], [100,100])
def __init__(self, positions, **args):
ROI.__init__(self, [0,0], [100,100], **args)
for p in positions:
self.addFreeHandle(p)