minor fixes
This commit is contained in:
parent
e78693631b
commit
060d2479f9
@ -138,7 +138,7 @@ label4 = w4.addLabel(text, row=0, col=0)
|
|||||||
v4 = w4.addViewBox(row=1, col=0, lockAspect=True)
|
v4 = w4.addViewBox(row=1, col=0, lockAspect=True)
|
||||||
g = pg.GridItem()
|
g = pg.GridItem()
|
||||||
v4.addItem(g)
|
v4.addItem(g)
|
||||||
r4 = pg.ROI([0,0], [100,100], removable=True)
|
r4 = pg.ROI([0,0], [100,100], resizable=False, removable=True)
|
||||||
r4.addRotateHandle([1,0], [0.5, 0.5])
|
r4.addRotateHandle([1,0], [0.5, 0.5])
|
||||||
r4.addRotateHandle([0,1], [0.5, 0.5])
|
r4.addRotateHandle([0,1], [0.5, 0.5])
|
||||||
img4 = pg.ImageItem(arr)
|
img4 = pg.ImageItem(arr)
|
||||||
|
@ -42,9 +42,7 @@ class ROI(GraphicsObject):
|
|||||||
rotate/translate/scale handles.
|
rotate/translate/scale handles.
|
||||||
ROIs can be customized to have a variety of shapes (by subclassing or using
|
ROIs can be customized to have a variety of shapes (by subclassing or using
|
||||||
any of the built-in subclasses) and any combination of draggable handles
|
any of the built-in subclasses) and any combination of draggable handles
|
||||||
that allow the user to manipulate the ROI.
|
that allow the user to manipulate the ROI.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
================ ===========================================================
|
================ ===========================================================
|
||||||
**Arguments**
|
**Arguments**
|
||||||
@ -78,8 +76,6 @@ class ROI(GraphicsObject):
|
|||||||
inside the ROI. Default is True.
|
inside the ROI. Default is True.
|
||||||
rotatable (bool) If True, the ROI can be rotated by mouse drag + ALT
|
rotatable (bool) If True, the ROI can be rotated by mouse drag + ALT
|
||||||
resizable (bool) If True, the ROI can be resized by mouse drag + SHIFT
|
resizable (bool) If True, the ROI can be resized by mouse drag + SHIFT
|
||||||
lockAspect (bool) If True, the aspect ratio of the ROI is locked during
|
|
||||||
mouse interaction.
|
|
||||||
removable (bool) If True, the ROI will be given a context menu with
|
removable (bool) If True, the ROI will be given a context menu with
|
||||||
an option to remove the ROI. The ROI emits
|
an option to remove the ROI. The ROI emits
|
||||||
sigRemoveRequested when this menu action is selected.
|
sigRemoveRequested when this menu action is selected.
|
||||||
@ -120,7 +116,7 @@ class ROI(GraphicsObject):
|
|||||||
def __init__(self, pos, size=Point(1, 1), angle=0.0, invertible=False, maxBounds=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,
|
snapSize=1.0, scaleSnap=False, translateSnap=False, rotateSnap=False,
|
||||||
parent=None, pen=None, movable=True, rotatable=True, resizable=True,
|
parent=None, pen=None, movable=True, rotatable=True, resizable=True,
|
||||||
lockAspect=False, removable=False):
|
removable=False):
|
||||||
GraphicsObject.__init__(self, parent)
|
GraphicsObject.__init__(self, parent)
|
||||||
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
|
self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
|
||||||
pos = Point(pos)
|
pos = Point(pos)
|
||||||
@ -129,7 +125,6 @@ class ROI(GraphicsObject):
|
|||||||
self.translatable = movable
|
self.translatable = movable
|
||||||
self.rotatable = rotatable
|
self.rotatable = rotatable
|
||||||
self.resizable = resizable
|
self.resizable = resizable
|
||||||
self.lockAspect = lockAspect
|
|
||||||
self.removable = removable
|
self.removable = removable
|
||||||
self.menu = None
|
self.menu = None
|
||||||
|
|
||||||
@ -281,9 +276,15 @@ class ROI(GraphicsObject):
|
|||||||
if update not in (True, False):
|
if update not in (True, False):
|
||||||
raise TypeError("update argument must be bool")
|
raise TypeError("update argument must be bool")
|
||||||
size = Point(size)
|
size = Point(size)
|
||||||
|
if snap:
|
||||||
|
size[0] = round(size[0] / self.scaleSnapSize) * self.scaleSnapSize
|
||||||
|
size[1] = round(size[1] / self.scaleSnapSize) * self.scaleSnapSize
|
||||||
|
|
||||||
if centerLocal is not None:
|
if centerLocal is not None:
|
||||||
center = Point(centerLocal) / self.state['size']
|
oldSize = Point(self.state['size'])
|
||||||
|
oldSize[0] = 1 if oldSize[0] == 0 else oldSize[0]
|
||||||
|
oldSize[1] = 1 if oldSize[1] == 0 else oldSize[1]
|
||||||
|
center = Point(centerLocal) / oldSize
|
||||||
|
|
||||||
if center is not None:
|
if center is not None:
|
||||||
center = Point(center)
|
center = Point(center)
|
||||||
@ -826,8 +827,8 @@ class ROI(GraphicsObject):
|
|||||||
|
|
||||||
## snap
|
## snap
|
||||||
if self.scaleSnap or (modifiers & QtCore.Qt.ControlModifier):
|
if self.scaleSnap or (modifiers & QtCore.Qt.ControlModifier):
|
||||||
lp1[0] = round(lp1[0] / self.snapSize) * self.snapSize
|
lp1[0] = round(lp1[0] / self.scaleSnapSize) * self.scaleSnapSize
|
||||||
lp1[1] = round(lp1[1] / self.snapSize) * self.snapSize
|
lp1[1] = round(lp1[1] / self.scaleSnapSize) * self.scaleSnapSize
|
||||||
|
|
||||||
## preserve aspect ratio (this can override snapping)
|
## preserve aspect ratio (this can override snapping)
|
||||||
if h['lockAspect'] or (modifiers & QtCore.Qt.AltModifier):
|
if h['lockAspect'] or (modifiers & QtCore.Qt.AltModifier):
|
||||||
@ -1441,6 +1442,8 @@ class MouseDragHandler(object):
|
|||||||
self.translateModifier = QtCore.Qt.NoModifier
|
self.translateModifier = QtCore.Qt.NoModifier
|
||||||
self.rotateModifier = QtCore.Qt.AltModifier
|
self.rotateModifier = QtCore.Qt.AltModifier
|
||||||
self.scaleModifier = QtCore.Qt.ShiftModifier
|
self.scaleModifier = QtCore.Qt.ShiftModifier
|
||||||
|
self.rotateSpeed = 0.7
|
||||||
|
self.scaleSpeed = 1.01
|
||||||
|
|
||||||
def mouseDragEvent(self, ev):
|
def mouseDragEvent(self, ev):
|
||||||
roi = self.roi
|
roi = self.roi
|
||||||
@ -1485,10 +1488,11 @@ class MouseDragHandler(object):
|
|||||||
newPos = pos + self.cursorOffset
|
newPos = pos + self.cursorOffset
|
||||||
roi.translate(newPos - roi.pos(), snap=snap, finish=False)
|
roi.translate(newPos - roi.pos(), snap=snap, finish=False)
|
||||||
elif self.dragMode == 'rotate':
|
elif self.dragMode == 'rotate':
|
||||||
diff = (ev.scenePos() - ev.buttonDownScenePos()).y()
|
diff = self.rotateSpeed * (ev.scenePos() - ev.buttonDownScenePos()).x()
|
||||||
roi.setAngle(self.startState['angle'] + diff, centerLocal=ev.buttonDownPos(), snap=snap, finish=False)
|
angle = self.startState['angle'] - diff
|
||||||
|
roi.setAngle(angle, centerLocal=ev.buttonDownPos(), snap=snap, finish=False)
|
||||||
elif self.dragMode == 'scale':
|
elif self.dragMode == 'scale':
|
||||||
diff = 1.01 ** -(ev.scenePos() - ev.buttonDownScenePos()).y()
|
diff = self.scaleSpeed ** -(ev.scenePos() - ev.buttonDownScenePos()).y()
|
||||||
roi.setSize(Point(self.startState['size']) * diff, centerLocal=ev.buttonDownPos(), snap=snap, finish=False)
|
roi.setSize(Point(self.startState['size']) * diff, centerLocal=ev.buttonDownPos(), snap=snap, finish=False)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user