
    e6                     `    d dl mZ d dl mZ d dlmZmZ ddlmZ ddlmZ dgZ	 G d de      Z
y	)
   )debug)	functions)QtCoreQtGui   )GraphicsObject)InfiniteLineLinearRegionItemc                      e Zd ZdZ ej
                  e      Z ej
                  e      ZdZ	dZ
e	de
dddddiZ	 	 	 ddZd Zd	 Zd
 Zd Zd Zd ZddZd ZddZd Zd Zd Zd dZd Zd Zd Zd Zd Zd Zd Z d Z!y)!r
   ae  
    **Bases:** :class:`GraphicsObject <pyqtgraph.GraphicsObject>`
    
    Used for marking a horizontal or vertical region in plots.
    The region can be dragged and is bounded by lines which can be dragged individually.
    
    ===============================  =============================================================================
    **Signals:**
    sigRegionChangeFinished(self)    Emitted when the user has finished dragging the region (or one of its lines)
                                     and when the region is changed programatically.
    sigRegionChanged(self)           Emitted while the user is dragging the region (or one of its lines)
                                     and when the region is changed programatically.
    ===============================  =============================================================================
        r   vertical
horizontalNc                    t        j                  |        || _        d| _        d| _        d| _        |	| _        |
| _        || _        d| _	        d| _
        t        |||	||      }|dt        j                  fv rt        t        j                   d|d         fddi|t        t        j                   d|d         fddi|g| _        t$        j&                  j)                  dd      }| j"                  d   j+                  |d	       | j"                  d   j+                  |d	       no|d
t        j,                  fv rPt        t        j                   |d   d      fddi|t        t        j                   |d   d      fddi|g| _        nt/        d      | j"                  D ]8  }|j1                  |        |j2                  j5                  | j6                         : | j"                  d   j8                  j5                  | j:                         | j"                  d   j8                  j5                  | j<                         |+t%        j>                  t%        j@                  dddd            }| jC                  |       |[| jD                  jG                         }|jI                  tK        |jM                         dz  d             tO        jP                  |      }| jS                  |       | jU                  |       y)aJ
  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 'vertical' or 'horizontal'
                        The default is 'vertical', indicating that the region is bounded
                        by vertical lines.
        brush           Defines the brush that fills the region. Can be any arguments that
                        are valid for :func:`mkBrush <pyqtgraph.mkBrush>`. Default is
                        transparent blue.
        pen             The pen to use when drawing the lines that bound the region.
        hoverBrush      The brush to use when the mouse is hovering over the region.
        hoverPen        The pen to use when the mouse is hovering over the region.
        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
        span            Optional [min, max] giving the range over the view to draw
                        the region. For example, with a vertical line, use
                        ``span=(0.5, 1)`` to draw only on the top half of the
                        view.
        swapMode        Sets the behavior of the region when the lines are moved such that
                        their order reverses:

                          * "block" means the user cannot drag one line past the other
                          * "push" causes both lines to be moved if one would cross the other
                          * "sort" means that lines may trade places, but the output of
                            getRegion always gives the line positions in ascending order.
                          * None means that no attempt is made to handle swapped line
                            positions.

                        The default is "sort".
        clipItem        An item whose bounds will be used to limit the region bounds.
                        This is useful when a LinearRegionItem is added on top of an
                        :class:`~pyqtgraph.ImageItem` or
                        :class:`~pyqtgraph.PlotDataItem` and the visual region should
                        not extend beyond its range. This overrides ``bounds``.
        ==============  =====================================================================
        FN)movableboundsspanpenhoverPenr   r   angler   Tr   Z   z/Orientation must be 'vertical' or 'horizontal'.   2   r   )+r   __init__orientationblockLineSignalmovingmouseHoveringr   swapModeclipItem_boundingRectCache_clipItemBoundsCachedictr
   
Horizontalr	   r   QPointFlinesr   
QTransform	fromScalesetTransformVertical	ExceptionsetParentItemsigPositionChangeFinishedconnectlineMoveFinishedsigPositionChanged_line0Moved_line1MovedQBrushQColorsetBrushbrushcolorsetAlphaminalphafnmkBrushsetHoverBrush
setMovable)selfvaluesr   r6   r   
hoverBrushr   r   r   r   r   r    lineKwdstrlcs                   J/usr/lib/python3/dist-packages/pyqtgraph/graphicsItems/LinearRegionItem.pyr   zLinearRegionItem.__init__$   s   X 	%&$"	  "&$(! 
 <)9)D)DEE V^^Avay9OOhOV^^Avay9OOhOQDJ !!++Ar2BJJqM&&r40JJqM&&r40Z)9)B)BCCV^^F1Iq9PPxPV^^F1Iq9PPxPRDJ MNN 	GAOOD!''//0E0EF	G 	

1((001A1AB

1((001A1AB=LLaC!<=Ee

  "AJJs1779q=#./AJ:&     c                     | j                   d   j                         | j                   d   j                         f}| j                  dk(  rt        |      t	        |      fS |S )z-Return the values at the edges of the region.r   r   sort)r&   valuer   r9   max)r?   rs     rF   	getRegionzLinearRegionItem.getRegion   sT     ZZ]  "DJJqM$7$7$9:==F"FCF##HrG   c                    | j                   d   j                         |d   k(  r$| j                   d   j                         |d   k(  ryd| _        | j                   d   j                  |d          d| _        | j                   d   j                  |d          | j	                  d       | j	                  d       | j                          y)a,  Set the values for the edges of the region.
        
        ==============   ==============================================
        **Arguments:**
        rgn              A list or tuple of the lower and upper values.
        ==============   ==============================================
        r   r   NTF)r&   rJ   r   setValue	lineMovedr/   )r?   rgns     rF   	setRegionzLinearRegionItem.setRegion   s     ::a= CF*tzz!}/B/B/DA/N#

1s1v&$

1s1v&qqrG   c                 Z    t        j                  |i || _        | j                  | _        y)zSet the brush that fills the region. Can have any arguments that are valid
        for :func:`mkBrush <pyqtgraph.mkBrush>`.
        N)r;   r<   r6   currentBrushr?   brkargss      rF   r5   zLinearRegionItem.setBrush   s%     ZZ-u-
 JJrG   c                 8    t        j                  |i || _        y)zSet the brush that fills the region when the mouse is hovering over.
        Can have any arguments that are valid
        for :func:`mkBrush <pyqtgraph.mkBrush>`.
        N)r;   r<   rA   rU   s      rF   r=   zLinearRegionItem.setHoverBrush   s    
 **b2E2rG   c                 `    | j                   | j                  d       | j                  |       y)a  Set ``(min, max)`` bounding values for the region.

        The current position is only affected it is outside the new bounds. See
        :func:`~pyqtgraph.LinearRegionItem.setRegion` to set the position of the region.

        Use ``(None, None)`` to disable bounds.
        N)r    setClipItem
_setBounds)r?   r   s     rF   	setBoundszLinearRegionItem.setBounds   s(     ==$T"rG   c                 H    | j                   D ]  }|j                  |        y N)r&   r\   )r?   r   lines      rF   r[   zLinearRegionItem._setBounds   s#     JJ 	#DNN6"	#rG   c                 x    | j                   D ]  }|j                  |        || _        | j                  |       y)znSet lines to be movable by the user, or not. If lines are movable, they will 
        also accept HoverEvents.N)r&   r>   r   setAcceptHoverEvents)r?   mr_   s      rF   r>   zLinearRegionItem.setMovable   s8     JJ 	DOOA	!!!$rG   c                     | j                   ||fk(  ry ||f| _         | j                  D ]  }|j                  ||        | j                          y r^   )r   r&   setSpanupdate)r?   mnmxr_   s       rF   rd   zLinearRegionItem.setSpan   sJ    99R H	JJ 	!DLLR 	!rG   c                 l    || _         d| _        || j                  d       || j                          yy)z_Set an item to which the region is bounded.

        If ``None``, bounds are disabled.
        N)NN)r    r"   r[   _updateClipItemBounds)r?   items     rF   rZ   zLinearRegionItem.setClipItem   s;    
 $(!<OOL)&&( rG   c                 <   | j                   j                         }|y |j                  | j                   f      }|| j                  k(  sd |v ry || _        | j                  dt
        j                  fv r| j                  |d          y | j                  |d          y )N)itemsr   r   r   )r    
getViewBoxchildrenBoundsr"   r   r
   r$   r[   )r?   item_vbitem_boundss      rF   ri   z&LinearRegionItem._updateClipItemBounds   s    --**,?,,DMM3C,D$333t{7J$/!.>.I.IJJOOKN+OOKN+rG   c                    t        j                  | j                               }| j                  | j	                          | j                         }| j                  dt        j                  fv r|j                  |d          |j                  |d          |j                         }|j                  |j                         || j                  d   z  z          |j                  |j                         || j                  d   z  z          n|j                  |d          |j                  |d          |j!                         }|j                  |j#                         || j                  d   z  z          |j                  |j#                         || j                  d   z  z          |j%                         }| j&                  |k7  r|| _        | j)                          |S )Nr   r   r   )r   QRectFviewRectr    ri   rM   r   r
   r*   setLeftsetRightheight	setBottomtopr   setTopwidthleft
normalizedr!   prepareGeometryChange)r?   rV   rnglengths       rF   boundingRectzLinearRegionItem.boundingRect   sj   ]]4==?+==$&&(nn
,<,E,EFFJJs1vKKAYY[FLLFTYYq\$99:IIbffh$))A,!667IIc!fLLQ XXZFKK	FTYYq\$99:JJrwwy6DIIaL#889]]_""b(&(D#&&(	rG   c                     t        j                         }|j                  | j                         |j	                  t        j                  d              |j                  | j                                y r^   )	r   Profilerr5   rT   setPenr;   mkPendrawRectr   )r?   pargsprofilers       rF   paintzLinearRegionItem.paint  sI    >>#	

4$$%	$ 	

4$$&'rG   c                 \    || j                   | j                     k(  r| j                         S y r^   )_orientation_axisr   rM   )r?   axisfrac
orthoRanges       rF   
dataBoundszLinearRegionItem.dataBounds  s+    4))$*:*:;;>>##rG   c                    | j                   ry | j                  d   j                         | j                  d   j                         kD  r| j                  dk(  r=| j                  |   j	                  | j                  d|z
     j                                nK| j                  dk(  r<| j                  d|z
     j	                  | j                  |   j                                | j                          | j                  j                  |        y )Nr   r   blockpush)r   r&   rJ   r   rO   r}   sigRegionChangedemit)r?   is     rF   rP   zLinearRegionItem.lineMoved  s     ::a= 4::a=#6#6#88}}'

1&&tzz!A#'<'<'>?&(

1Q3((A)<)<)>?""$""4(rG   c                 &    | j                  d       y )Nr   rP   r?   s    rF   r1   zLinearRegionItem._line0Moved)      qrG   c                 &    | j                  d       y )Nr   r   r   s    rF   r2   zLinearRegionItem._line1Moved,  r   rG   c                 :    | j                   j                  |        y r^   )sigRegionChangeFinishedr   r   s    rF   r/   z!LinearRegionItem.lineMoveFinished/  s    $$))$/rG   c                    | j                   r5|j                         t        j                  j                  j
                  k7  ry |j                          |j                         rt|j                         }| j                  D cg c]  }|j                         |z
   c}| _        | j                  D cg c]  }|j                          c}| _        d| _        | j                  sy | j                  d   j                  d       t        | j                        D ]4  \  }}|j!                  | j                  |   |j                         z          6 | j                  d   j                  d       | j#                          |j%                         r#d| _        | j&                  j)                  |        y | j*                  j)                  |        y c c}w c c}w )NTr   F)r   buttonr   QtMouseButton
LeftButtonacceptisStartbuttonDownPosr&   poscursorOffsetsstartPositionsr   blockSignals	enumeratesetPosr}   isFinishr   r   r   )r?   evbdprD   r   s        rF   mouseDragEventzLinearRegionItem.mouseDragEvent2  sO   ||ryy{fii.C.C.N.NN
		::<""$C9=!DA!%%'C-!DD48JJ"?q1557"?DDK{{

1""4(djj) 	7DAqHHT''*RVVX56	7

1""5)""$;;=DK((--d3!!&&t,# "E"?s   G1Gc                    | j                   r|j                         t        j                  j                  j
                  k(  r|j                          t        | j                        D ]#  \  }}|j                  | j                  |          % d| _         | j                  j                  |        | j                  j                  |        y y y )NF)r   r   r   r   r   RightButtonr   r   r&   r   r   r   r   r   )r?   r   r   rD   s       rF   mouseClickEventz LinearRegionItem.mouseClickEventL  s    ;;299;&))*?*?*K*KKIIK!$**- 11,,Q/01DK!!&&t,((--d3 L;rG   c                     | j                   rU|j                         sE|j                  t        j                  j
                  j                        r| j                  d       y | j                  d       y )NTF)r   isExitacceptDragsr   r   r   r   setMouseHover)r?   r   s     rF   
hoverEventzLinearRegionItem.hoverEventU  sH    <<"..AVAVAaAa2bt$u%rG   c                     | j                   |k(  ry || _         |r| j                  | _        n| j                  | _        | j	                          y r^   )r   rA   rT   r6   re   )r?   hovers     rF   r   zLinearRegionItem.setMouseHover[  s?    &" $D $

DrG   )r   r   r   NNNNTNr   rI   N)Tr^   )g      ?N)"__name__
__module____qualname____doc__r   Signalobjectr   r   r*   r$   r   r   rM   rR   r5   r=   r\   r[   r>   rd   rZ   ri   r   r   r   rP   r1   r2   r/   r   r   r   r    rG   rF   r
   r
   	   s     ,fmmF3$v}}V,HJ!AAa	
 OSFJ8<d!L &'3
 #%
),"8()0-44&	rG   N) r   r   r;   r   r   r   r   r	   __all__r
   r   rG   rF   <module>r      s*       * &
[~ [rG   