Commit 397a1c8a authored by Luke Campagnola's avatar Luke Campagnola
Browse files

bugfixes

parent 4aeaf619
......@@ -226,14 +226,15 @@ class GraphicsView(QtGui.QGraphicsView):
def wheelEvent(self, ev):
QtGui.QGraphicsView.wheelEvent(self, ev)
if not self.mouseEnabled:
return
QtGui.QGraphicsView.wheelEvent(self, ev)
sc = 1.001 ** ev.delta()
#self.scale *= sc
#self.updateMatrix()
self.scale(sc, sc)
def setAspectLocked(self, s):
self.aspectLocked = s
......@@ -311,13 +312,11 @@ class GraphicsView(QtGui.QGraphicsView):
#self.currentItem = None
def mouseMoveEvent(self, ev):
#if self.lastMousePos is None:
#self.lastMousePos = Point(ev.pos())
#delta = Point(ev.pos()) - self.lastMousePos
#if abs(delta[0]) > 100 or abs(delta[1]) > 100: ## Weird bug generating extra events..
#return
#self.lastMousePos = Point(ev.pos())
#print "move", delta
if self.lastMousePos is None:
self.lastMousePos = Point(ev.pos())
delta = Point(ev.pos()) - self.lastMousePos
self.lastMousePos = Point(ev.pos())
QtGui.QGraphicsView.mouseMoveEvent(self, ev)
if not self.mouseEnabled:
return
......@@ -327,8 +326,6 @@ class GraphicsView(QtGui.QGraphicsView):
if self.clickAccepted: ## Ignore event if an item in the scene has already claimed it.
return
if ev.buttons() == QtCore.Qt.RightButton:
delta = Point(clip(delta[0], -50, 50), clip(-delta[1], -50, 50))
......@@ -338,7 +335,6 @@ class GraphicsView(QtGui.QGraphicsView):
self.scale(scale[0], scale[1], center=self.mapToScene(self.mousePressPos))
self.emit(QtCore.SIGNAL('regionChanged(QRectF)'), self.range)
elif ev.buttons() in [QtCore.Qt.MidButton, QtCore.Qt.LeftButton]: ## Allow panning by left or mid button.
tr = -delta / self.currentScale
......
......@@ -953,7 +953,7 @@ class PlotItem(QtGui.QGraphicsWidget):
if arr.ndim != 1:
raise Exception("Array must be 1D to plot (shape is %s)" % arr.shape)
if x is None:
x = np.arange(arr.shape[0])
x = arange(arr.shape[0])
if x.ndim != 1:
raise Exception("X array must be 1D to plot (shape is %s)" % x.shape)
c = PlotCurveItem(arr, x=x)
......
......@@ -5,7 +5,6 @@ import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from scipy import random
from numpy import array, arange
from PyQt4 import QtGui, QtCore
from pyqtgraph.PlotWidget import *
from pyqtgraph.graphicsItems import *
......@@ -91,4 +90,4 @@ for i in range(0, 5):
yd, xd = rand(10000)
pw2.plot(y=yd*(j+1), x=xd, params={'iter': i, 'val': j})
app.exec_()
#app.exec_()
......@@ -1458,10 +1458,8 @@ class ScaleItem(QtGui.QGraphicsWidget):
else:
xs = bounds.width() / dif
tickPositions = set() # remembers positions of previously drawn ticks
## draw ticks and text
## draw three different intervals, long ticks first
for i in reversed([i1, i1+1, i1+2]):
for i in [i1, i1+1, i1+2]: ## draw three different intervals
if i > len(intervals):
continue
## spacing for this interval
......@@ -1505,11 +1503,7 @@ class ScaleItem(QtGui.QGraphicsWidget):
if p1[1-axis] < 0:
continue
p.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100, a)))
# draw tick only if there is none
tickPos = p1[1-axis]
if tickPos not in tickPositions:
p.drawLine(Point(p1), Point(p2))
tickPositions.add(tickPos)
p.drawLine(Point(p1), Point(p2))
if i == textLevel:
if abs(v) < .001 or abs(v) >= 10000:
vstr = "%g" % (v * self.scale)
......@@ -1734,16 +1728,7 @@ class ViewBox(QtGui.QGraphicsWidget):
#self.replot(autoRange=False)
#self.updateMatrix()
def wheelEvent(self, ev):
mask = np.array(self.mouseEnabled, dtype=np.float)
degree = ev.delta() / 8.0;
dif = np.array([degree, degree])
s = ((mask * 0.02) + 1) ** dif
center = Point(self.childGroup.transform().inverted()[0].map(ev.pos()))
self.scaleBy(s, center)
self.emit(QtCore.SIGNAL('rangeChangedManually'), self.mouseEnabled)
ev.accept()
def mouseMoveEvent(self, ev):
QtGui.QGraphicsWidget.mouseMoveEvent(self, ev)
pos = np.array([ev.pos().x(), ev.pos().y()])
......
......@@ -53,6 +53,7 @@ class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
self.setPos(pos)
self.rotate(-angle * 180. / np.pi)
self.setZValue(10)
self.isMoving = False
self.handleSize = 5
self.invertible = invertible
......@@ -208,15 +209,23 @@ class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
if ev.button() == QtCore.Qt.LeftButton:
self.setSelected(True)
if self.translatable:
self.isMoving = True
self.preMoveState = self.getState()
self.cursorOffset = self.scenePos() - ev.scenePos()
self.emit(QtCore.SIGNAL('regionChangeStarted'), self)
ev.accept()
elif ev.button() == QtCore.Qt.RightButton:
if self.isMoving:
ev.accept()
self.cancelMove()
else:
ev.ignore()
else:
ev.ignore()
def mouseMoveEvent(self, ev):
#print "mouse move", ev.pos()
if self.translatable:
if self.translatable and self.isMoving and ev.buttons() == QtCore.Qt.LeftButton:
snap = None
if self.translateSnap or (ev.modifiers() & QtCore.Qt.ControlModifier):
snap = Point(self.snapSize, self.snapSize)
......@@ -226,18 +235,25 @@ class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
def mouseReleaseEvent(self, ev):
if self.translatable:
self.isMoving = False
self.emit(QtCore.SIGNAL('regionChangeFinished'), self)
def cancelMove(self):
self.isMoving = False
self.setState(self.preMoveState)
def pointPressEvent(self, pt, ev):
#print "press"
self.isMoving = True
self.preMoveState = self.getState()
self.emit(QtCore.SIGNAL('regionChangeStarted'), self)
#self.pressPos = self.mapFromScene(ev.scenePos())
#self.pressHandlePos = self.handles[pt]['item'].pos()
def pointReleaseEvent(self, pt, ev):
#print "release"
self.isMoving = False
self.emit(QtCore.SIGNAL('regionChangeFinished'), self)
def stateCopy(self):
......@@ -718,6 +734,16 @@ class ROI(QtGui.QGraphicsItem, QObjectWorkaround):
class Handle(QtGui.QGraphicsItem):
types = { ## defines number of sides, start angle for each handle type
't': (4, np.pi/4),
'f': (4, np.pi/4),
's': (4, 0),
'r': (12, 0),
'sr': (12, 0),
'rf': (12, 0),
}
def __init__(self, radius, typ=None, pen=QtGui.QPen(QtGui.QColor(200, 200, 220)), parent=None):
#print " create item with parent", parent
self.bounds = QtCore.QRectF(-1e-10, -1e-10, 2e-10, 2e-10)
......@@ -731,27 +757,8 @@ class Handle(QtGui.QGraphicsItem):
self.pen = pen
self.pen.setWidth(0)
self.pen.setCosmetic(True)
if typ == 't':
self.sides = 4
self.startAng = np.pi/4
elif typ == 'f':
self.sides = 4
self.startAng = np.pi/4
elif typ == 's':
self.sides = 4
self.startAng = 0
elif typ == 'r':
self.sides = 12
self.startAng = 0
elif typ == 'sr':
self.sides = 12
self.startAng = 0
elif typ == 'rf':
self.sides = 12
self.startAng = 0
else:
self.sides = 4
self.startAng = np.pi/4
self.isMoving = False
self.sides, self.startAng = self.types[typ]
def connectROI(self, roi, i):
self.roi.append((roi, i))
......@@ -761,24 +768,37 @@ class Handle(QtGui.QGraphicsItem):
def mousePressEvent(self, ev):
#print "handle press"
if ev.button() != QtCore.Qt.LeftButton:
if ev.button() == QtCore.Qt.LeftButton:
self.isMoving = True
self.cursorOffset = self.scenePos() - ev.scenePos()
for r in self.roi:
r[0].pointPressEvent(r[1], ev)
#print " accepted."
ev.accept()
elif ev.button() == QtCore.Qt.RightButton:
if self.isMoving:
self.isMoving = False ## prevents any further motion
for r in self.roi:
r[0].cancelMove()
ev.accept()
else:
ev.ignore()
else:
ev.ignore()
return
self.cursorOffset = self.scenePos() - ev.scenePos()
for r in self.roi:
r[0].pointPressEvent(r[1], ev)
#print " accepted."
ev.accept()
def mouseReleaseEvent(self, ev):
#print "release"
for r in self.roi:
r[0].pointReleaseEvent(r[1], ev)
if ev.button() == QtCore.Qt.LeftButton:
self.isMoving = False
for r in self.roi:
r[0].pointReleaseEvent(r[1], ev)
def mouseMoveEvent(self, ev):
#print "handle mouseMove", ev.pos()
pos = ev.scenePos() + self.cursorOffset
self.movePoint(pos, ev.modifiers())
if self.isMoving and ev.buttons() == QtCore.Qt.LeftButton:
pos = ev.scenePos() + self.cursorOffset
self.movePoint(pos, ev.modifiers())
def movePoint(self, pos, modifiers=QtCore.Qt.KeyboardModifier()):
for r in self.roi:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment