
    e7                     z    g d Z ddlZddlmZ ddlmZ ddlmZ  G d de      Z G d	 d
e      Z	 G d de      Z
y))MouseDragEventMouseClickEvent
HoverEvent    N)perf_counter   )Point)QtCorec                       e Zd ZdZddZd Zd Zd Zd Zd Z	dd	Z
dd
Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zy)r   z
    Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their mouseDragEvent() method when the item is being mouse-dragged. 
    
    c                 >   || _         || _        d| _        d | _        i | _        i | _        t        j                  j                  j                  t        j                  j                  j                  t        j                  j                  j                  fD ]>  }|j                  |      | j                  |<   |j                  |      | j
                  |<   @ |j                         | _        |j!                         | _        |+|j                         | _        |j!                         | _        n*|j                         | _        |j!                         | _        |j)                         | _        |j-                         | _        |j1                         | _        d | _        y NF)startfinishacceptedcurrentItem_buttonDownScenePos_buttonDownScreenPosr	   QtMouseButton
LeftButtonMiddleButtonRightButtonbuttonDownScenePosbuttonDownScreenPosscenePos	_scenePos	screenPos
_screenPos_lastScenePos_lastScreenPosbuttons_buttonsbutton_button	modifiers
_modifiersacceptedItem)self	moveEvent
pressEvent	lastEventr   r   btns          E/usr/lib/python3/dist-packages/pyqtgraph/GraphicsScene/mouseEvents.py__init__zMouseDragEvent.__init__   sT   
#% $&!II))44fii6K6K6X6XZ`ZcZcZoZoZ{Z{| 	PC,5,H,H,MD$$S)-6-J-J3-OD%%c*	P #++-#--/!+!4!4!6D","6"6"8D!*!3!3!5D"+"5"5"7D!))+!((*#--/     c                 4    d| _         | j                  | _        yz{An item should call this method if it can handle the event. This will prevent the event being delivered to any other items.TNr   r   r&   r'   s    r,   acceptzMouseDragEvent.accept)        ,,r.   c                     d| _         yzxAn item should call this method if it cannot handle the event. This will allow the event to be delivered to other items.FNr   r2   s    r,   ignorezMouseDragEvent.ignore.   	    r.   c                     | j                   S Nr7   r2   s    r,   
isAcceptedzMouseDragEvent.isAccepted2       }}r.   c                 ,    t        | j                        S z/Return the current scene position of the mouse.r   r   r2   s    r,   r   zMouseDragEvent.scenePos5       T^^$$r.   c                 ,    t        | j                        S zLReturn the current screen position (pixels relative to widget) of the mouse.r   r   r2   s    r,   r   zMouseDragEvent.screenPos9       T__%%r.   Nc                 V    || j                         }t        | j                  |         S )z
        Return the scene position of the mouse at the time *btn* was pressed.
        If *btn* is omitted, then the button that initiated the drag is assumed.
        )r"   r   r   r'   r+   s     r,   r   z!MouseDragEvent.buttonDownScenePos=   s*    
 ;++-CT--c233r.   c                 V    || j                         }t        | j                  |         S )z
        Return the screen position (pixels relative to widget) of the mouse at the time *btn* was pressed.
        If *btn* is omitted, then the button that initiated the drag is assumed.
        )r"   r   r   rG   s     r,   r   z"MouseDragEvent.buttonDownScreenPosF   s*    
 ;++-CT..s344r.   c                 ,    t        | j                        S )zY
        Return the scene position of the mouse immediately prior to this event.
        r   r   r2   s    r,   lastScenePoszMouseDragEvent.lastScenePosO   s     T''((r.   c                 ,    t        | j                        S )zZ
        Return the screen position of the mouse immediately prior to this event.
        r   r   r2   s    r,   lastScreenPoszMouseDragEvent.lastScreenPosU   s     T(())r.   c                     | j                   S z
        Return the buttons currently pressed on the mouse.
        (see QGraphicsSceneMouseEvent::buttons in the Qt documentation)
        r!   r2   s    r,   r    zMouseDragEvent.buttons[       
 }}r.   c                     | j                   S )zReturn the button that initiated the drag (may be different from the buttons currently pressed)
        (see QGraphicsSceneMouseEvent::button in the Qt documentation)
        
        r#   r2   s    r,   r"   zMouseDragEvent.buttonb   s    
 ||r.   c                 ^    t        | j                  j                  | j                              S z
        Return the current position of the mouse in the coordinate system of the item
        that the event was delivered to.
        r   r   mapFromScener   r2   s    r,   poszMouseDragEvent.posi   $    
 T%%224>>BCCr.   c                 ^    t        | j                  j                  | j                              S z
        Return the previous position of the mouse in the coordinate system of the item
        that the event was delivered to.
        r   r   rX   r   r2   s    r,   lastPoszMouseDragEvent.lastPosp   &    
 T%%2243E3EFGGr.   c                     || j                         }t        | j                  j                  | j                  |               S )z
        Return the position of the mouse at the time the drag was initiated
        in the coordinate system of the item that the event was delivered to.
        )r"   r   r   rX   r   rG   s     r,   buttonDownPoszMouseDragEvent.buttonDownPosw   s;    
 ;++-CT%%2243K3KC3PQRRr.   c                     | j                   S )zCReturns True if this event is the first since a drag was initiated.)r   r2   s    r,   isStartzMouseDragEvent.isStart       zzr.   c                     | j                   S )zReturns False if this is the last event in a drag. Note that this
        event will have the same position as the previous one.)r   r2   s    r,   isFinishzMouseDragEvent.isFinish   s     {{r.   c                    | j                   | j                  }| j                  }n | j                         }| j	                         }d|j                         |j                         |j                         |j                         t        | j                               t        | j                               t        | j                               fz  S )Nz?<MouseDragEvent (%g,%g)->(%g,%g) buttons=%s start=%s finish=%s>)r   r   r   r^   rY   xystrr    rc   rf   r'   lpps      r,   __repr__zMouseDragEvent.__repr__   s    ###BAB
APTVTXTXTZ\^\`\`\bdedgdgdiklknknkpruvz  wC  wC  wE  sF  HK  LP  LX  LX  LZ  H[  ]`  ae  an  an  ap  ]q  Tr  r  	rr.   c                     | j                   S )zReturn any keyboard modifiers currently pressed.
        (see QGraphicsSceneMouseEvent::modifiers in the Qt documentation)
        
        r%   r2   s    r,   r$   zMouseDragEvent.modifiers   s    
 r.   )FFr;   )__name__
__module____qualname____doc__r-   r3   r8   r<   r   r   r   r   rK   rN   r    r"   rY   r^   ra   rc   rf   rn   r$    r.   r,   r   r   
   sj    !.-
%&45)*DHS
rr.   r   c                   f    e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zy)r   z
    Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their mouseClickEvent() method when the item is clicked. 
    
    
    c                 ,   d| _         d | _        || _        |j                         | _        |j                         | _        |j                         | _        |j                         | _
        |j                         | _        t               | _        d | _        y r   )r   r   _doubler   r   r   r   r"   r#   r    r!   r$   r%   r   _timer&   )r'   r)   doubles      r,   r-   zMouseClickEvent.__init__   sy    #,,.$..0!((*"**,$..0!^
 r.   c                 4    d| _         | j                  | _        yr0   r1   r2   s    r,   r3   zMouseClickEvent.accept   r4   r.   c                     d| _         yr6   r7   r2   s    r,   r8   zMouseClickEvent.ignore   r9   r.   c                     | j                   S r;   r7   r2   s    r,   r<   zMouseClickEvent.isAccepted   r=   r.   c                 ,    t        | j                        S r?   r@   r2   s    r,   r   zMouseClickEvent.scenePos   rA   r.   c                 ,    t        | j                        S rC   rD   r2   s    r,   r   zMouseClickEvent.screenPos   rE   r.   c                     | j                   S rP   rQ   r2   s    r,   r    zMouseClickEvent.buttons   rR   r.   c                     | j                   S )zReturn the mouse button that generated the click event.
        (see QGraphicsSceneMouseEvent::button in the Qt documentation)
        rT   r2   s    r,   r"   zMouseClickEvent.button   s     ||r.   c                     | j                   S )z&Return True if this is a double-click.)rx   r2   s    r,   rz   zMouseClickEvent.double   s    ||r.   c                 ^    t        | j                  j                  | j                              S rV   rW   r2   s    r,   rY   zMouseClickEvent.pos   rZ   r.   c                 ^    t        | j                  j                  | j                              S r\   r]   r2   s    r,   r^   zMouseClickEvent.lastPos   r_   r.   c                     | j                   S zReturn any keyboard modifiers currently pressed.
        (see QGraphicsSceneMouseEvent::modifiers in the Qt documentation)        
        rp   r2   s    r,   r$   zMouseClickEvent.modifiers        r.   c                    	 | j                   | j                  }n| j                         }d|j                         |j	                         t        | j                               fz  S #  dt        | j                               z  cY S xY w)Nz#<MouseClickEvent (%g,%g) button=%s>z<MouseClickEvent button=%s>)r   r   rY   rh   ri   rj   r"   )r'   rm   s     r,   rn   zMouseClickEvent.__repr__   so    	H'NNHHJ8ACCE1335#dkkmJ\;]]]	H0C4FGGs   A#A& &Bc                     | j                   S r;   )ry   r2   s    r,   timezMouseClickEvent.time   s    zzr.   N)F)rq   rr   rs   rt   r-   r3   r8   r<   r   r   r    r"   rz   rY   r^   r$   rn   r   ru   r.   r,   r   r      sP    
!-
%&DHHr.   r   c                   p    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)r   a  
    Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their hoverEvent() method when the mouse is hovering over the item.
    This event class both informs items that the mouse cursor is nearby and allows items to 
    communicate with one another about whether each item will accept *potential* mouse events. 
    
    It is common for multiple overlapping items to receive hover events and respond by changing 
    their appearance. This can be misleading to the user since, in general, only one item will
    respond to mouse events. To avoid this, items make calls to event.acceptClicks(button) 
    and/or acceptDrags(button).
    
    Each item may make multiple calls to acceptClicks/Drags, each time for a different button. 
    If the method returns True, then the item is guaranteed to be
    the recipient of the claimed event IF the user presses the specified mouse button before
    moving. If claimEvent returns False, then this item is guaranteed NOT to get the specified
    event (because another has already claimed it) and the item should change its appearance 
    accordingly.
    
    event.isEnter() returns True if the mouse has just entered the item's shape;
    event.isExit() returns True if the mouse has just left.
    c                    d| _         || _        d| _        t        j                         | _        t        j                         | _        d | _        ||j                         | _	        |j                         | _        |j                         | _        |j                         | _        |j!                         | _        |j%                         | _        y d| _        y )NFT)enter
acceptableexitweakrefWeakValueDictionary_HoverEvent__clickItems_HoverEvent__dragItemsr   r   r   r   r   rK   r   rN   r   r    r!   r$   r%   )r'   r(   r   s      r,   r-   zHoverEvent.__init__  s    
$	#779"668 &//1DN'113DO!*!7!7!9D"+"9"9";D%--/DM'113DODIr.   c                     | j                   S )z;Returns True if the mouse has just entered the item's shape)r   r2   s    r,   isEnterzHoverEvent.isEnter  rd   r.   c                     | j                   S )z:Returns True if the mouse has just exited the item's shape)r   r2   s    r,   isExitzHoverEvent.isExit   s    yyr.   c                 n    | j                   sy|| j                  vr| j                  | j                  |<   yy)aR  Inform the scene that the item (that the event was delivered to)
        would accept a mouse click event if the user were to click before
        moving the mouse again.
        
        Returns True if the request is successful, otherwise returns False (indicating
        that some other item would receive an incoming click).
        FT)r   r   r   r'   r"   s     r,   acceptClickszHoverEvent.acceptClicks$  s8     ***(,(8(8Df%r.   c                 n    | j                   sy|| j                  vr| j                  | j                  |<   yy)aS  Inform the scene that the item (that the event was delivered to)
        would accept a mouse drag event if the user were to drag before
        the next hover event.
        
        Returns True if the request is successful, otherwise returns False (indicating
        that some other item would receive an incoming drag event).
        FT)r   r   r   r   s     r,   acceptDragszHoverEvent.acceptDrags3  s8     )))'+'7'7DV$r.   c                 ,    t        | j                        S r?   r@   r2   s    r,   r   zHoverEvent.scenePosB  rA   r.   c                 ,    t        | j                        S )z0Return the current screen position of the mouse.rD   r2   s    r,   r   zHoverEvent.screenPosF  rE   r.   c                 ,    t        | j                        S )z0Return the previous scene position of the mouse.rJ   r2   s    r,   rK   zHoverEvent.lastScenePosJ  s    T''((r.   c                 ,    t        | j                        S )z1Return the previous screen position of the mouse.rM   r2   s    r,   rN   zHoverEvent.lastScreenPosN  s    T(())r.   c                     | j                   S rP   rQ   r2   s    r,   r    zHoverEvent.buttonsR  rR   r.   c                 ^    t        | j                  j                  | j                              S rV   rW   r2   s    r,   rY   zHoverEvent.posY  rZ   r.   c                 ^    t        | j                  j                  | j                              S r\   r]   r2   s    r,   r^   zHoverEvent.lastPos`  r_   r.   c                    | j                   ry| j                  | j                  }| j                  }n | j	                         }| j                         }d|j                         |j                         |j                         |j                         t        | j                               t        | j                               t        | j                               fz  S )Nz<HoverEvent exit=True>z9<HoverEvent (%g,%g)->(%g,%g) buttons=%s enter=%s exit=%s>)r   r   r   r   r^   rY   rh   ri   rj   r    r   r   rk   s      r,   rn   zHoverEvent.__repr__g  s    99+###BAB
AJbddfVXVZVZV\^_^a^a^cefehehejloptp|p|p~l  BE  FJ  FR  FR  FT  BU  WZ  [_  [f  [f  [h  Wi  Nj  j  	jr.   c                     | j                   S r   rp   r2   s    r,   r$   zHoverEvent.modifierss  r   r.   c                     | j                   S r;   )r   r2   s    r,   
clickItemszHoverEvent.clickItemsy  s       r.   c                     | j                   S r;   )r   r2   s    r,   	dragItemszHoverEvent.dragItems|  s    r.   N)rq   rr   rs   rt   r-   r   r   r   r   r   r   rK   rN   r    rY   r^   rn   r$   r   r   ru   r.   r,   r   r      sZ    ("%&)*DH
j! r.   r   )__all__r   r   r   r   r   r	   objectr   r   r   ru   r.   r,   <module>r      sB   
=    MV MbWf WvG  G r.   