Beispiel #1
0
 def __init__(self, xvals=None, yrange=None, pen=None):
     
     if yrange is None:
         yrange = [0, 1]
     if xvals is None:
         xvals = []
         
     #bounds = QtCore.QRectF(0, yrange[0], 1, yrange[1]-yrange[0])
     UIGraphicsItem.__init__(self)#, bounds=bounds)
         
     if pen is None:
         pen = (200, 200, 200)
         
     self.path = QtGui.QGraphicsPathItem()
     
     self.ticks = []
     self.xvals = []
     #if view is None:
         #self.view = None
     #else:
         #self.view = weakref.ref(view)
     self.yrange = [0,1]
     self.setPen(pen)
     self.setYRange(yrange)
     self.setXVals(xvals)
Beispiel #2
0
    def __init__(self, xvals=None, yrange=None, pen=None):
        """
        ============= ===================================================================
        **Arguments**
        xvals         A list of x values (in data coordinates) at which to draw ticks.
        yrange        A list of [low, high] limits for the tick. 0 is the bottom of 
                      the view, 1 is the top. [0.8, 1] would draw ticks in the top 
                      fifth of the view.
        pen           The pen to use for drawing ticks. Default is grey. Can be specified
                      as any argument valid for :func:`mkPen<pyqtgraph.mkPen>`
        ============= ===================================================================
        """
        if yrange is None:
            yrange = [0, 1]
        if xvals is None:
            xvals = []

        #bounds = QtCore.QRectF(0, yrange[0], 1, yrange[1]-yrange[0])
        UIGraphicsItem.__init__(self)  #, bounds=bounds)

        if pen is None:
            pen = (200, 200, 200)

        self.path = QtGui.QGraphicsPathItem()

        self.ticks = []
        self.xvals = []
        #if view is None:
        #self.view = None
        #else:
        #self.view = weakref.ref(view)
        self.yrange = [0, 1]
        self.setPen(pen)
        self.setYRange(yrange)
        self.setXVals(xvals)
Beispiel #3
0
    def __init__(self, pos=None, angle=90, pen=None, movable=False, bounds=None):
        """
        Initialization options:
            pos      - Position of the line. This can be a QPointF or a single value for vertical/horizontal lines.
            angle    - Angle of line in degrees. 0 is horizontal, 90 is vertical.
            pen      - Pen to use when drawing line
            movable  - If True, the line can be dragged to a new position by the user
            bounds   - Optional [min, max] bounding values. Bounds are only valid if the line is vertical or horizontal.
        """
        
        UIGraphicsItem.__init__(self)
        
        if bounds is None:              ## allowed value boundaries for orthogonal lines
            self.maxRange = [None, None]
        else:
            self.maxRange = bounds
        self.moving = False
        self.setMovable(movable)
        self.mouseHovering = False
        self.p = [0, 0]
        self.setAngle(angle)
        if pos is None:
            pos = Point(0,0)
        self.setPos(pos)

        if pen is None:
            pen = (200, 200, 100)
        self.setPen(pen)
        self.currentPen = self.pen
Beispiel #4
0
 def setPos(self, pos):
     if type(pos) in [list, tuple]:
         newPos = pos
     elif isinstance(pos, QtCore.QPointF):
         newPos = [pos.x(), pos.y()]
     else:
         if self.angle == 90:
             newPos = [pos, 0]
         elif self.angle == 0:
             newPos = [0, pos]
         else:
             raise Exception("Must specify 2D coordinate for non-orthogonal lines.")
         
     ## check bounds (only works for orthogonal lines)
     if self.angle == 90:
         if self.maxRange[0] is not None:    
             newPos[0] = max(newPos[0], self.maxRange[0])
         if self.maxRange[1] is not None:
             newPos[0] = min(newPos[0], self.maxRange[1])
     elif self.angle == 0:
         if self.maxRange[0] is not None:
             newPos[1] = max(newPos[1], self.maxRange[0])
         if self.maxRange[1] is not None:
             newPos[1] = min(newPos[1], self.maxRange[1])
         
     if self.p != newPos:
         self.p = newPos
         UIGraphicsItem.setPos(self, Point(self.p))
         self.update()
         self.sigPositionChanged.emit(self)
Beispiel #5
0
 def __init__(self, xvals=None, yrange=None, pen=None):
     """
     ============= ===================================================================
     **Arguments**
     xvals         A list of x values (in data coordinates) at which to draw ticks.
     yrange        A list of [low, high] limits for the tick. 0 is the bottom of 
                   the view, 1 is the top. [0.8, 1] would draw ticks in the top 
                   fifth of the view.
     pen           The pen to use for drawing ticks. Default is grey. Can be specified
                   as any argument valid for :func:`mkPen<pyqtgraph.mkPen>`
     ============= ===================================================================
     """
     if yrange is None:
         yrange = [0, 1]
     if xvals is None:
         xvals = []
         
     #bounds = QtCore.QRectF(0, yrange[0], 1, yrange[1]-yrange[0])
     UIGraphicsItem.__init__(self)#, bounds=bounds)
         
     if pen is None:
         pen = (200, 200, 200)
         
     self.path = QtGui.QGraphicsPathItem()
     
     self.ticks = []
     self.xvals = []
     #if view is None:
         #self.view = None
     #else:
         #self.view = weakref.ref(view)
     self.yrange = [0,1]
     self.setPen(pen)
     self.setYRange(yrange)
     self.setXVals(xvals)
Beispiel #6
0
 def __init__(self, values=[0,1], orientation=None, brush=None, movable=True, bounds=None):
     UIGraphicsItem.__init__(self)
     if orientation is None:
         orientation = LinearRegionItem.Vertical
     self.orientation = orientation
     self.bounds = QtCore.QRectF()
     self.blockLineSignal = False
     self.moving = False
     self.mouseHovering = False
     
     if orientation == LinearRegionItem.Horizontal:
         self.lines = [
             InfiniteLine(QtCore.QPointF(0, values[0]), 0, movable=movable, bounds=bounds), 
             InfiniteLine(QtCore.QPointF(0, values[1]), 0, movable=movable, bounds=bounds)]
     elif orientation == LinearRegionItem.Vertical:
         self.lines = [
             InfiniteLine(QtCore.QPointF(values[1], 0), 90, movable=movable, bounds=bounds), 
             InfiniteLine(QtCore.QPointF(values[0], 0), 90, movable=movable, bounds=bounds)]
     else:
         raise Exception('Orientation must be one of LinearRegionItem.Vertical or LinearRegionItem.Horizontal')
     
     
     for l in self.lines:
         l.setParentItem(self)
         l.sigPositionChangeFinished.connect(self.lineMoveFinished)
         l.sigPositionChanged.connect(self.lineMoved)
         
     if brush is None:
         brush = QtGui.QBrush(QtGui.QColor(0, 0, 255, 50))
     self.setBrush(brush)
     
     self.setMovable(movable)
Beispiel #7
0
 def setPos(self, pos):
     
     if type(pos) in [list, tuple]:
         newPos = pos
     elif isinstance(pos, QtCore.QPointF):
         newPos = [pos.x(), pos.y()]
     else:
         if self.angle == 90:
             newPos = [pos, 0]
         elif self.angle == 0:
             newPos = [0, pos]
         else:
             raise Exception("Must specify 2D coordinate for non-orthogonal lines.")
         
     ## check bounds (only works for orthogonal lines)
     if self.angle == 90:
         if self.maxRange[0] is not None:    
             newPos[0] = max(newPos[0], self.maxRange[0])
         if self.maxRange[1] is not None:
             newPos[0] = min(newPos[0], self.maxRange[1])
     elif self.angle == 0:
         if self.maxRange[0] is not None:
             newPos[1] = max(newPos[1], self.maxRange[0])
         if self.maxRange[1] is not None:
             newPos[1] = min(newPos[1], self.maxRange[1])
         
     if self.p != newPos:
         self.p = newPos
         UIGraphicsItem.setPos(self, Point(self.p))
         self.update()
         self.sigPositionChanged.emit(self)
Beispiel #8
0
    def __init__(self, pos=None, angle=90, pen=None, movable=False, bounds=None):
        """
        ============= ==================================================================
        **Arguments**
        pos           Position of the line. This can be a QPointF or a single value for
                      vertical/horizontal lines.
        angle         Angle of line in degrees. 0 is horizontal, 90 is vertical.
        pen           Pen to use when drawing line. Can be any arguments that are valid 
                      for :func:`mkPen <pyqtgraph.mkPen>`. Default pen is transparent 
                      yellow.
        movable       If True, the line can be dragged to a new position by the user.
        bounds        Optional [min, max] bounding values. Bounds are only valid if the
                      line is vertical or horizontal.
        ============= ==================================================================
        """
        
        UIGraphicsItem.__init__(self)
        
        if bounds is None:              ## allowed value boundaries for orthogonal lines
            self.maxRange = [None, None]
        else:
            self.maxRange = bounds
        self.moving = False
        self.setMovable(movable)
        self.mouseHovering = False
        self.p = [0, 0]
        self.setAngle(angle)
        if pos is None:
            pos = Point(0,0)
        self.setPos(pos)

        if pen is None:
            pen = (200, 200, 100)
        self.setPen(pen)
        self.currentPen = self.pen
Beispiel #9
0
    def paint(self, p, *args):
        UIGraphicsItem.paint(self, p, *args)

        br = self.boundingRect()
        h = br.height()
        br.setY(br.y() + self.yrange[0] * h)
        br.setHeight(h - (1.0 - self.yrange[1]) * h)
        p.translate(0, br.y())
        p.scale(1.0, br.height())
        p.setPen(self.pen)
        p.drawPath(self.path)
Beispiel #10
0
 def paint(self, p, *args):
     UIGraphicsItem.paint(self, p, *args)
     
     br = self.boundingRect()
     h = br.height()
     br.setY(br.y() + self.yrange[0] * h)
     br.setHeight(h - (1.0-self.yrange[1]) * h)
     p.translate(0, br.y())
     p.scale(1.0, br.height())
     p.setPen(self.pen)
     p.drawPath(self.path)
Beispiel #11
0
 def __init__(self, values=[0,1], orientation=None, brush=None, movable=True, bounds=None):
     """Create a new LinearRegionItem.
     
     ============= =====================================================================
     **Arguments**
     values        A list of the positions of the lines in the region. These are not 
                   limits; limits can be set by specifying bounds.
     orientation   Options are LinearRegionItem.Vertical or LinearRegionItem.Horizontal.
                   If not specified it will be vertical.
     brush         Defines the brush that fills the region. Can be any arguments that 
                   are valid for :func:`mkBrush <pyqtgraph.mkBrush>`. Default is 
                   transparent blue.
     movable       If True, the region and individual lines are movable by the user; if 
                   False, they are static.
     bounds        Optional [min, max] bounding values for the region
     ============= =====================================================================
     """
     
     UIGraphicsItem.__init__(self)
     if orientation is None:
         orientation = LinearRegionItem.Vertical
     self.orientation = orientation
     self.bounds = QtCore.QRectF()
     self.blockLineSignal = False
     self.moving = False
     self.mouseHovering = False
     
     if orientation == LinearRegionItem.Horizontal:
         self.lines = [
             InfiniteLine(QtCore.QPointF(0, values[0]), 0, movable=movable, bounds=bounds), 
             InfiniteLine(QtCore.QPointF(0, values[1]), 0, movable=movable, bounds=bounds)]
     elif orientation == LinearRegionItem.Vertical:
         self.lines = [
             InfiniteLine(QtCore.QPointF(values[1], 0), 90, movable=movable, bounds=bounds), 
             InfiniteLine(QtCore.QPointF(values[0], 0), 90, movable=movable, bounds=bounds)]
     else:
         raise Exception('Orientation must be one of LinearRegionItem.Vertical or LinearRegionItem.Horizontal')
     
     
     for l in self.lines:
         l.setParentItem(self)
         l.sigPositionChangeFinished.connect(self.lineMoveFinished)
         l.sigPositionChanged.connect(self.lineMoved)
         
     if brush is None:
         brush = QtGui.QBrush(QtGui.QColor(0, 0, 255, 50))
     self.setBrush(brush)
     
     self.setMovable(movable)
Beispiel #12
0
 def boundingRect(self):
     br = UIGraphicsItem.boundingRect(self)
     rng = self.getRegion()
     if self.orientation == LinearRegionItem.Vertical:
         br.setLeft(rng[0])
         br.setRight(rng[1])
     else:
         br.setTop(rng[0])
         br.setBottom(rng[1])
     return br.normalized()
Beispiel #13
0
 def boundingRect(self):
     br = UIGraphicsItem.boundingRect(self)
     rng = self.getRegion()
     if self.orientation == LinearRegionItem.Vertical:
         br.setLeft(rng[0])
         br.setRight(rng[1])
     else:
         br.setTop(rng[0])
         br.setBottom(rng[1])
     return br.normalized()
Beispiel #14
0
 def boundingRect(self):
     br = UIGraphicsItem.boundingRect(self)
     
     ## add a 4-pixel radius around the line for mouse interaction.
     
     #print "line bounds:", self, br
     dt = self.deviceTransform()
     if dt is None:
         return QtCore.QRectF()
     lineDir = Point(dt.map(Point(1, 0)) - dt.map(Point(0,0)))  ## direction of line in pixel-space
     orthoDir = Point(lineDir[1], -lineDir[0])  ## orthogonal to line in pixel-space
     try:
         norm = orthoDir.norm()  ## direction of one pixel orthogonal to line
     except ZeroDivisionError:
         return br
     
     dti = dt.inverted()[0]
     px = Point(dti.map(norm)-dti.map(Point(0,0)))  ## orthogonal pixel mapped back to item coords
     px = px[1]  ## project to y-direction
     
     br.setBottom(-px*4)
     br.setTop(px*4)
     return br.normalized()
Beispiel #15
0
 def boundingRect(self):
     br = UIGraphicsItem.boundingRect(self)
     
     ## add a 4-pixel radius around the line for mouse interaction.
     
     #print "line bounds:", self, br
     dt = self.deviceTransform()
     if dt is None:
         return QtCore.QRectF()
     lineDir = Point(dt.map(Point(1, 0)) - dt.map(Point(0,0)))  ## direction of line in pixel-space
     orthoDir = Point(lineDir[1], -lineDir[0])  ## orthogonal to line in pixel-space
     try:
         norm = orthoDir.norm()  ## direction of one pixel orthogonal to line
     except ZeroDivisionError:
         return br
     
     dti = dt.inverted()[0]
     px = Point(dti.map(norm)-dti.map(Point(0,0)))  ## orthogonal pixel mapped back to item coords
     px = px[1]  ## project to y-direction
     
     br.setBottom(-px*4)
     br.setTop(px*4)
     return br.normalized()
Beispiel #16
0
 def paint(self, p, *args):
     #prof = debug.Profiler('LinearRegionItem.paint')
     UIGraphicsItem.paint(self, p, *args)
     p.setBrush(self.currentBrush)
     p.drawRect(self.boundingRect())
Beispiel #17
0
 def paint(self, p, *args):
     #prof = debug.Profiler('LinearRegionItem.paint')
     UIGraphicsItem.paint(self, p, *args)
     p.setBrush(self.currentBrush)
     p.drawRect(self.boundingRect())
Beispiel #18
0
    def __init__(self,
                 values=[0, 1],
                 orientation=None,
                 brush=None,
                 movable=True,
                 bounds=None):
        """Create a new LinearRegionItem.
        
        ============= =====================================================================
        **Arguments**
        values        A list of the positions of the lines in the region. These are not 
                      limits; limits can be set by specifying bounds.
        orientation   Options are LinearRegionItem.Vertical or LinearRegionItem.Horizontal.
                      If not specified it will be vertical.
        brush         Defines the brush that fills the region. Can be any arguments that 
                      are valid for :func:`mkBrush <pyqtgraph.mkBrush>`. Default is 
                      transparent blue.
        movable       If True, the region and individual lines are movable by the user; if 
                      False, they are static.
        bounds        Optional [min, max] bounding values for the region
        ============= =====================================================================
        """

        UIGraphicsItem.__init__(self)
        if orientation is None:
            orientation = LinearRegionItem.Vertical
        self.orientation = orientation
        self.bounds = QtCore.QRectF()
        self.blockLineSignal = False
        self.moving = False
        self.mouseHovering = False

        if orientation == LinearRegionItem.Horizontal:
            self.lines = [
                InfiniteLine(QtCore.QPointF(0, values[0]),
                             0,
                             movable=movable,
                             bounds=bounds),
                InfiniteLine(QtCore.QPointF(0, values[1]),
                             0,
                             movable=movable,
                             bounds=bounds)
            ]
        elif orientation == LinearRegionItem.Vertical:
            self.lines = [
                InfiniteLine(QtCore.QPointF(values[1], 0),
                             90,
                             movable=movable,
                             bounds=bounds),
                InfiniteLine(QtCore.QPointF(values[0], 0),
                             90,
                             movable=movable,
                             bounds=bounds)
            ]
        else:
            raise Exception(
                'Orientation must be one of LinearRegionItem.Vertical or LinearRegionItem.Horizontal'
            )

        for l in self.lines:
            l.setParentItem(self)
            l.sigPositionChangeFinished.connect(self.lineMoveFinished)
            l.sigPositionChanged.connect(self.lineMoved)

        if brush is None:
            brush = QtGui.QBrush(QtGui.QColor(0, 0, 255, 50))
        self.setBrush(brush)

        self.setMovable(movable)
Beispiel #19
0
 def paint(self, p, *args):
     UIGraphicsItem.paint(self, p, *args)
     br = self.boundingRect()
     p.setPen(self.currentPen)
     p.drawLine(Point(br.right(), 0), Point(br.left(), 0))
Beispiel #20
0
 def paint(self, p, *args):
     UIGraphicsItem.paint(self, p, *args)
     br = self.boundingRect()
     p.setPen(self.currentPen)
     p.drawLine(Point(br.right(), 0), Point(br.left(), 0))