ArrowItem.py 1.73 KB
Newer Older
1 2
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph.functions as fn
3
import numpy as np
4
__all__ = ['ArrowItem']
5 6

class ArrowItem(QtGui.QGraphicsPathItem):
7 8 9 10 11 12 13 14
    """
    For displaying scale-invariant arrows.
    For arrows pointing to a location on a curve, see CurveArrow
    
    """
    
    
    def __init__(self, **opts):
15
        QtGui.QGraphicsPathItem.__init__(self, opts.get('parent', None))
16 17 18 19
        if 'size' in opts:
            opts['headLen'] = opts['size']
        if 'width' in opts:
            opts['headWidth'] = opts['width']
20 21
        defOpts = {
            'pxMode': True,
Luke Campagnola's avatar
Luke Campagnola committed
22
            'angle': -150,   ## If the angle is 0, the arrow points left
23
            'pos': (0,0),
24
            'headLen': 20,
25
            'tipAngle': 25,
26 27 28
            'baseAngle': 0,
            'tailLen': None,
            'tailWidth': 3,
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
            'pen': (200,200,200),
            'brush': (50,50,200),
        }
        defOpts.update(opts)
        
        self.setStyle(**defOpts)
        
        self.setPen(fn.mkPen(defOpts['pen']))
        self.setBrush(fn.mkBrush(defOpts['brush']))
        
        self.rotate(self.opts['angle'])
        self.moveBy(*self.opts['pos'])
    
    def setStyle(self, **opts):
        self.opts = opts
        
45 46 47
        opt = {k:self.opts[k] for k in ['headLen', 'tipAngle', 'baseAngle', 'tailLen', 'tailWidth']}
        self.path = fn.makeArrowPath(**opt)
        self.setPath(self.path)
48 49 50 51 52 53 54 55
        
        if opts['pxMode']:
            self.setFlags(self.flags() | self.ItemIgnoresTransformations)
        else:
            self.setFlags(self.flags() & ~self.ItemIgnoresTransformations)
        
    def paint(self, p, *args):
        p.setRenderHint(QtGui.QPainter.Antialiasing)
56
        QtGui.QGraphicsPathItem.paint(self, p, *args)