
    G@dS                         d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ  G d d	e          Z G d
 de          ZdS )a+  
Calltip widget used only to show signatures.

Adapted from IPython/frontend/qt/console/call_tip_widget.py of the
`IPython Project <https://github.com/ipython/ipython>`_.
Now located at qtconsole/call_tip_widget.py as part of the
`Jupyter QtConsole Project <https://github.com/jupyter/qtconsole>`_.
    )categoryN)QBasicTimerQCoreApplicationQEventQtQTimerSignal)QCursorQPalette)	QApplicationQFrameQLabel	QTextEditQPlainTextEditQStyleQStyleOptionFrameQStylePainterQToolTip)to_text_stringc                        e Zd ZdZ eee          Z ee          Zd fd	Z fdZ	d Z
d ZddZ fd	Zd
 Z fdZd Z fdZd Z xZS )ToolTipWidgetzF
    Shows tooltips that can be styled with the different themes.
    NFc                    t          t          |                               dt          j                   d| _        d| _        t          j                    | _	        || _
        d| _        t                      | _        || _        t          j        dk    r |                     t          j                   n,|                     t          j        t          j        z             | j                            d           |                     t          j                   |                     t          j                   |                     d           |                     t4          j                   |                     t4          j                   |                     t?          j                                | !                    t          j"                   | #                    d           | $                    tJ          j&                   | '                                }|(                    tR          j*        d|           }| +                    d|z              | j,        -                    | j.                   | j        j/        -                    | j0                   tc          j                    j2        -                    | j3                   dS )zN
        Shows tooltips that can be styled with the different themes.
        N darwini  F   )4superr   __init__r   ToolTipcompletion_doc_urlr   instanceapp
as_tooltiptipr   _timer_hide
_text_editsysplatformsetWindowFlagsSplashScreenFramelessWindowHintsetIntervalsetTextInteractionFlagsTextSelectableByMouseTextBrowserInteractionsetOpenExternalLinkssetForegroundRoler   ToolTipTextsetBackgroundRoleToolTipBase
setPaletter   palettesetAlignment	AlignLeft	setIndentsetFrameStyler   NoFramestylepixelMetricr   PM_ToolTipLabelFrameWidth	setMarginlinkHoveredconnect_update_hover_html_link_styletimeouthider   applicationStateChanged_should_hide)selfparentr#   r<   delta_margin	__class__s        6lib/python3.11/site-packages/spyder/widgets/calltip.pyr   zToolTipWidget.__init__,   s>    	mT""++D"*=== #	#,..$!88  <8##0000
R-C CDDD$$S)))$$R%=>>>$$R%>???!!%(((x3444x3444(**+++",'''q6>***

(()I)-t5 5q<'((( 	  !CDDD ((3337??	 	 	 	 	    c                 $   t          |           }t                      }|                    |            |                    t          j        |           |                                 t          t          |           	                    |           dS )z,Reimplemented to paint the background panel.N)
r   r   initFromdrawPrimitiver   PE_PanelTipLabelendr   r   
paintEventrG   eventpainteroptionrJ   s       rK   rR   zToolTipWidget.paintEventW   sw    %%"$$f5v>>>mT""--e44444rL   c                 ,   d}d}|| _         |r0t          j        t          t          j                             ||}}n||}}t          j                     |                                 }|                    ||          }| 	                    |           dS )z=Update style of labels that include rich text and html links.ztext-decoration:none;ztext-decoration:underline;N)
r    r   setOverrideCursorr
   r   PointingHandCursorrestoreOverrideCursortextreplacesetText)rG   urllinklink_hoverednew_textold_textr[   s          rK   rB   z+ToolTipWidget._update_hover_html_link_stylea   s    &3	 	1*723H+I+IJJJ!-thHH!%|hH.000yy{{<<(33XrL   c                 V   || _         |                     |           |                     |                                            |                                |                                 z
  }|                     |                                |           |                                  dS )zShow basic tip.T)	r$   r]   resizesizeHintyheightmovexshow)rG   pointr$   rf   s       rK   show_basic_tipzToolTipWidget.show_basic_tipv   s}    SDMMOO$$$GGII%		%''))Q		trL   c                 p   t          j                                                    t          j        k    rdS || _        |                     |           |                     |                                            || _	        d}| j
        }||                                }n|                    |          }| j                                                            |          }|                    |                                |z              |                                                                 }	|                                                                 }
d}d}|                                |	z   |                                |                                z   k    rw|                    |                                          }|                                |	z
  |k     r3d|                                z  |                                k     rd}nd}nd}|                                |
z   |                                |                                z   k    rw|                    |                                          }|                                |
z
  |k     r3d|                                z  |                                k     rd}nd}nd}t/          |||          }|                     |                      }|dk    rBt0          j        dk    rd	}nd
}|                    |                                |	z
  |z
             |dk    r-|                    |                                |
z
  |z
             |                     |           |                                 s|                                  dS )zT
        Attempts to show the specified tip at the current cursor location.
        Nr   bottomRight   topLeftntT)r   r!   applicationStater   ApplicationActiver$   r]   rd   re   r   r&   
cursorRectr"   desktopscreenGeometrysetYrf   sizerg   widthmapToGlobaltopRightri   getattrosnamesetXrh   	isVisiblerj   )rG   rk   r$   cursorr   padding	text_editcursor_rectscreen_rect
tip_height	tip_widthvertical
horizontalpoint_posadjusted_points                   rK   show_tipzToolTipWidget.show_tip   sB   
  ""33559MMMF SDMMOO$$$,O	>#..00KK#..v66Kh&&((77	BB

57799w&'''YY[[''))
IIKK%%''	
7799z!K$6$6$8$8;==??$JJJ**;+?+?+A+ABBF xxzzJ&00 uwwyy=;#5#5#7#777'HH$HH 7799y ;#4#4#6#6#HHH**;+?+?+A+ABBF xxzzI%//uwwyy=;#4#4#6#666!(JJ!'JJ#
kXXzz#BCC"..ssuu55uw$JJ~''))J6@AAAJJ~''))I5?@@@		%~~ 	IIKKKtrL   c                    t          j                     | j        rR| j                            dd          }| j                            dd          }| j                            ||           n| j                            | j                   t          t          |           
                    |           |                                  dS )R
        Reimplemented to hide it when focus goes out of the main window.
        r   r   	signatureN)r   rZ   r   getsig_completion_help_requestedemitsig_help_requestedr    r   r   mousePressEvent_hide)rG   rT   r   r   rJ   s       rK   r   zToolTipWidget.mousePressEvent   s     	*,,, 	4&**6266D+//R@@I.33D)DDDD#((333mT""225999

rL   c                 .    |                                   dS )r   NrD   rG   rT   s     rK   focusOutEventzToolTipWidget.focusOutEvent        			rL   c                     t          t          |                               |           |                                  dS )z0Override Qt method to hide the tooltip on leave.N)r   r   
leaveEventrD   rG   rT   rJ   s     rK   r   zToolTipWidget.leaveEvent   s2    mT""--e444		rL   c                 ^    t          j                     | j                                         dS )zHide method helper.N)r   rZ   r%   startrG   s    rK   r   zToolTipWidget._hide   s,    *,,,     rL   c                     t          t          |                                            | j                                         dS )z3Override Qt method to add timer and restore cursor.N)r   r   rD   r%   stop)rG   rJ   s    rK   rD   zToolTipWidget.hide   s:    mT""'')))rL   c                 R    |t           j        k    r|                                  dS dS zR
        This widget should hide itself if the application is not active.
        Nr   rw   rD   rG   states     rK   rF   zToolTipWidget._should_hide   +     B(((IIKKKKK )(rL   )NF)NN)__name__
__module____qualname____doc__r	   strr   r   r   rR   rB   rl   r   r   r   r   r   rD   rF   __classcell__rJ   s   @rK   r   r   $   s2         %+F3$4$4!) ) ) ) ) )V5 5 5 5 5  *  G G G GR          
! ! !
         
      rL   r   c                        e Zd ZdZd fd	Z fdZd Z fdZ fdZ fdZ	 fd	Z
 fd
Z fdZ fdZd Zd ZddZd Zd Zd Z xZS )CallTipWidgetzF Shows call tips by parsing the current text of Q[Plain]TextEdit.
    Fc                    t          |t          t          f          sJ t          t          |                               dt          j                   t          j	                    | _
        || _        || _        d| _        t                      | _        || _        d| _        t$          j        dk    r |                     t          j                   n,|                     t          j        t          j        z             |                     t          j                   |                     |                                                                           |                     t:          j                   |                     t:          j                    | !                    tE          j#                               | $                    t          j%                   | &                    d           | '                    tP          j)                   | *                    d| +                                ,                    tZ          j.        d|           z              t_          j	                    j0        1                    | j2                   dS )zf Create a call tip manager that is attached to the specified Qt
            text edit widget.
        Nr   r   )3
isinstancer   r   r   r   r   r   r   r   r!   r"   r#   hide_timer_onr$   r   _hide_timerr&   _start_positionr'   r(   r)   r*   r+   r-   r.   setFontdocumentdefaultFontr1   r   r2   r3   r4   r5   r   r6   r7   r8   r9   r:   r   r;   r?   r<   r=   r   r>   r   rE   rA   rF   )rG   r   r   r#   rJ   s       rK   r   zCallTipWidget.__init__   s    )i%@AAAAAmT""++D"*===#,..$*&==#! <8##0000
R-C CDDD$$R%=>>>Y''))5577888x3444x3444(**+++",'''q6>***q4::<<330$> > > 	? 	? 	? 	7??	 	 	 	 	rL   c                 :   || j         k    r|                                }|t          j        k    r|                                }| j                                         }| j                             |                                d          }|t          j	        t          j
        t          j        t          j        fv r|                                  n!|t          j        k    r|                                  dS |dk    r|                                  n|t          j        k    r|                                  n|t          j        k    rb| j                                        rH| j                            t+          j                              | k    r| j                                         nI|t          j        k    r|                                  n$|t          j        k    r|                                  t7          t8          |                               ||          S )zb Reimplemented to hide on certain key presses and on text edit focus
            changes.
        r   )offsetT))r&   typer   KeyPresskey
textCursorget_characterpositionr   	Key_Enter
Key_ReturnKey_DownKey_UprD   
Key_EscapeFocusOutEnterr   isActiver"   
topLevelAtr
   r   r   Leave_leave_event_hideWindowBlockedr   r   eventFilter)rG   objrT   etyper   r   	prev_charrJ   s          rK   r   zCallTipWidget.eventFilter#  s    $/!!JJLLE''iikk3355 O99&//:K:KAC : E E	2<;	3 3 3IIKKKKBM))IIKKK4#%%IIKKK&/))		&,&&$--// ,(%%gkmm44<<$))+++&,&&&&((((&...		]D))55c5AAArL   c                     |                                 | j                                         k    r/| j                                         |                                  dS dS )zE Reimplemented to hide the widget when the hide timer fires.
        N)timerIdr   r   rD   r   s     rK   
timerEventzCallTipWidget.timerEventH  sT     ==??d.668888!!###IIKKKKK 98rL   c                 X   t          t          |                               |           | j        r|                                  | j                                        rJ| j                            t          j
                              | k    r| j                                         dS dS dS )z1 Reimplemented to cancel the hide timer.
        N)r   r   
enterEventr#   rD   r   r   r"   r   r
   r   r   r   s     rK   r   zCallTipWidget.enterEventS  s     	mT""--e444? 	IIKKK%%'' 	$
(

gkmm
,
,
4
4!!#####	$ 	$
4
4rL   c                    t          t          |                               |           	 | j        j                            | j                   | j                            |            dS # t          t          f$ r Y dS w xY w)zG Reimplemented to disconnect signal handlers and event filter.
        N)
r   r   	hideEventr&   cursorPositionChanged
disconnect_cursor_position_changedremoveEventFilter	TypeErrorRuntimeErrorr   s     rK   r   zCallTipWidget.hideEvent^  s     	mT"",,U333	4O1<<-/ / /
 O--d33333 <( 	 	 	DD	s   $A+ +B ?B c                     t          t          |                               |           |                                  dS )z0 Reimplemented to start the hide timer.
        N)r   r   r   r   r   s     rK   r   zCallTipWidget.leaveEventk  s;     	mT""--e444     rL   c                     t          t          |                               |           |                                  d S )N)r   r   r   rD   r   s     rK   r   zCallTipWidget.mousePressEventq  s2    mT""225999		rL   c                 $   t          |           }t                      }|                    |            |                    t          j        |           |                                 t          t          |           	                    |           dS )z6 Reimplemented to paint the background panel.
        N)
r   r   rN   rO   r   rP   rQ   r   r   rR   rS   s       rK   rR   zCallTipWidget.paintEventu  sy      %%"$$f5v>>>mT""--e44444rL   c                 X    t          t          |                               |           dS )z> Reimplemented to allow use of this method as a slot.
        N)r   r   r   )rG   fontrJ   s     rK   r   zCallTipWidget.setFont  s)     	mT""**400000rL   c                     t          t          |                               |           | j        j                            | j                   | j                            |            dS )zD Reimplemented to connect signal handlers and event filter.
        N)r   r   	showEventr&   r   rA   r   installEventFilterr   s     rK   r   zCallTipWidget.showEvent  sb     	mT"",,U333-55)	+ 	+ 	+**400000rL   c                 .    |                                   dS )zV Reimplemented to hide it when focus goes out of the main
            window.
        Nr   r   s     rK   r   zCallTipWidget.focusOutEvent  r   rL   c                 *
   t          j                                                    t          j        k    rdS |                                 r!| j        |k    rdS |                                  | j        }|	                                }|
                                dz
  }|                     |d          \  | _        }| j        dk    rdS | j        r| j                                         t!          |          dk    rX|d                             d          d         }t!          |                    d	                    }	|	dk    rd
}
ni|	dk    rd}
n`d}
n]t!          |          dk    rH|d                                         }t!          |                    d	                    }|dk    rd}
nd}
nd}
| j                            |
|            || _        |                     |           |                     |                                            d}|                    |          }| j                                                            |          }|                    |                                |z              |                                                                 }|                                                                 }d}d}|                                |z   |                                |                                z   k    rw|                     |!                                          }|                                |z
  |k     r3d|                                z  |                                k     rd}nd}nd}|"                                |z   |                                |"                                z   k    rw|                     |!                                          }|"                                |z
  |k     r3d|"                                z  |                                k     rd}nd}nd}tG          |||          }|                      |                      }|dk    rBtH          j%        dk    rd}nd}|                    |                                |z
  |z
             |dk    r-|&                    |"                                |z
  |z
             | '                    |           | (                                 dS )zL Attempts to show the specified tip at the current cursor location.
        NTr   Fforwardr   r   (,ix  rp   i@  i  i	  i
  i  rn   ro   rq   rr   rs   rt   ru   ))r   r!   rv   r   rw   r   r$   rD   r&   r   r   _find_parenthesisr   r   r   r   lensplitstripr   r]   rd   re   rx   r"   ry   rz   r{   rf   r|   rg   r}   r~   r   ri   r   r   r   r   rh   rj   )rG   rk   r$   wrapped_tiplinesr   r   
search_pos_argsnargs	hide_timeargs1nargs1r   r   r   r   r   r   r   r   r   r   s                          rK   r   zCallTipWidget.show_tip  s     ""33559MMMF >> 	x3t		 O	%%''__&&*
"&"8"8AF #9 #H #Ha2%%5 	4!!### #$$))'*0055a8DJJsOO,,A:: $IIaZZ $II $II%&&!++(+1133U[[--..Q;; $II $II 	""9d333 SDMMOO$$$
 **622h&&((77	BB

57799w&'''YY[[''))
IIKK%%''	
7799z!K$6$6$8$8;==??$JJJ**;+?+?+A+ABBF xxzzJ&00 UWWYY;!3!3!5!555'HH$HH 7799y ;#4#4#6#6#HHH**;+?+?+A+ABBF xxzzI%//UWWYY;!2!2!4!444!(JJ!'JJ#
kHHjj#ABB"..ssuu55uw$JJ~''))J6@AAAJJ~''))I5?@@@		%		trL   Tc                    dx}}| j                                         }t          |                    |                    }t	          |          dk    r|dk    r|dk    r|dk    r|dz  }n)|dk    r|r|dk    rn`|dz  }n|dk    r|s|dk    rnK|dz  }||rdndz  }t          |                    |                    }t	          |          dk    r|dk    d}||fS )az   If 'forward' is True (resp. False), proceed forwards
            (resp. backwards) through the line that contains 'position' until an
            unmatched closing (resp. opening) parenthesis is found. Returns a
            tuple containing the position of this parenthesis (or -1 if it is
            not found) and the number commas (at depth 0) found along the way.
        r   Ccr   r   r   r   r   )r&   r   r   characterAtr   )rG   r   r   commasdepthr   chars          rK   r   zCallTipWidget._find_parenthesis  s    ?++--h228<<== tnn$$As{{uzz! uzz
 5A::
W,",H!("6"6x"@"@AAD tnn$$A HrL   c                     | j         re| j                                        sN| j                            t          j                              | k    r!| j                            d|            dS dS dS dS )zq Hides the tooltip after some time has passed (assuming the cursor is
            not over the tooltip).
        i   N)r   r   r   r"   r   r
   r   r   r   s    rK   r   zCallTipWidget._leave_event_hide"  s      	.t'7'@'@'B'B 	. H..$66""3-----	. 	. 	. 	. 76rL   c                    | j                                         }|                                }| j                                         }t	          |                    |dz
                      }|| j        k    r|                                  dS |dk    r9|                     |dz
  d          \  }}|dk    r|                                  dS dS dS )z8 Updates the tip based on user cursor movement.
        r   r   Fr   r   N)	r&   r   r   r   r   r  r   rD   r   )rG   r   r   r   r  r   r   s          rK   r   z&CallTipWidget._cursor_position_changed/  s     ++--??$$?++--h228a<@@AAt+++IIKKKKKS[[++HqL%+HHFCbyy		 [yrL   c                 R    |t           j        k    r|                                  dS dS r   r   r   s     rK   rF   zCallTipWidget._should_hide=  r   rL   )FF)T)r   r   r   r   r   r   r   r   r   r   r   rR   r   r   r   r   r   r   r   rF   r   r   s   @rK   r   r      s        $ $ $ $ $ $L#B #B #B #B #BJ  	$ 	$ 	$ 	$ 	$4 4 4 4 4! ! ! ! !    	5 	5 	5 	5 	51 1 1 1 1
1 1 1 1 1  h h h\       :	. 	. 	.        rL   r   )r   unicodedatar   r   r'   qtpy.QtCorer   r   r   r   r   r	   
qtpy.QtGuir
   r   qtpy.QtWidgetsr   r   r   r   r   r   r   r   r   spyder.py3compatr   r   r    rL   rK   <module>r     s    !           				 



! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ( ( ( ( ( ( ( (5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
 , + + + + +M M M M MF M M MbM M M M MF M M M M MrL   