
    
8d)                     `    d dl Z d dlmZ d dlmZ d dlmZmZmZ  G d dej                  Z	dS )    N)category)QT6)QtCoreQtGui	QtWidgetsc                        e Zd ZdZ 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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.
    c                    t          |t          j        t          j        f          sJ t	                                          dt          j        j                   |j	        
                    | j                   t          j                    | _        || _        |                     |                                                                           |                     t&          j        j                   |                     t&          j        j                   |                     t          j                                                   |                     t          j        j                   |                     d           |                     t          j        j                    | !                    d| "                                #                    t          j$        j%        d|           z              | &                    | "                                '                    t          j$        j(        d| d          dz             | )                    d           dS )zf Create a call tip manager that is attached to the specified Qt
            text edit widget.
        N   g     o@T)*
isinstancer   	QTextEditQPlainTextEditsuper__init__r   QtToolTip	destroyedconnectdeleteLaterQBasicTimer_hide_timer
_text_editsetFontdocumentdefaultFontsetForegroundRoler   QPaletteToolTipTextsetBackgroundRoleToolTipBase
setPaletteQToolTippalettesetAlignment	AlignLeft	setIndentsetFrameStyleQFrameNoFrame	setMarginstylepixelMetricQStylePM_ToolTipLabelFrameWidthsetWindowOpacity	styleHintSH_ToolTipLabel_OpacitysetWordWrap)self	text_edit	__class__s     9lib/python3.11/site-packages/qtconsole/call_tip_widget.pyr   zCallTipWidget.__init__   s    )i&99;S%TUUUUUvy0111##D$4555!-//#Y''))5577888u~9:::u~9:::	*2244555&)-...q9+3444q4::<<33 :D$H H H 	I 	I 	Idjjll44 8$dL LNST 	U 	U 	U    c                    || j         k    r$|                                }|t          j        j        k    ry|                                }|t          j        j        t          j        j        fv r| 	                                 n|t          j        j
        k    r| 	                                 dS n|t          j        j        k    r| 	                                 nX|t          j        j        k    r| j                                         n)|t          j        j        k    r|                                  t#                                          ||          S )zb Reimplemented to hide on certain key presses and on text edit focus
            changes.
        T)r   typer   QEventKeyPresskeyr   	Key_Enter
Key_Returnhide
Key_EscapeFocusOutEnterr   stopLeave_leave_event_hider   eventFilter)r3   objeventetyper<   r5   s        r6   rF   zCallTipWidget.eventFilter,   s    $/!!JJLLE...iikk69.	0DEEEIIKKKKFI000IIKKK4 1 &-000		&---- %%''''&----&&(((ww""3...r7   c                     |                                 | j                                         k    r/| j                                         |                                  dS dS )zE Reimplemented to hide the widget when the hide timer fires.
        N)timerIdr   rC   r?   )r3   rH   s     r6   
timerEventzCallTipWidget.timerEventF   sT     ==??d.668888!!###IIKKKKK 98r7   c                 |    t                                          |           | j                                         dS )z1 Reimplemented to cancel the hide timer.
        N)r   
enterEventr   rC   r3   rH   r5   s     r6   rN   zCallTipWidget.enterEventQ   s8     	5!!!r7   c                     t                                          |           	 | j        j                            | j                   n# t          $ r Y nw xY w| j                            |            dS )zG Reimplemented to disconnect signal handlers and event filter.
        N)r   	hideEventr   cursorPositionChanged
disconnect_cursor_position_changed	TypeErrorremoveEventFilterrO   s     r6   rQ   zCallTipWidget.hideEventW   s     	%   	O1<<-/ / / / 	 	 	D	))$/////s   $A	 	
AAc                 r    t                                          |           |                                  dS )z0 Reimplemented to start the hide timer.
        N)r   
leaveEventrE   rO   s     r6   rX   zCallTipWidget.leaveEventc   s5     	5!!!     r7   c                 4   t          j        |           }t          j                    }|                    |            |                    t           j        j        |           |                                 t                      	                    |           dS )z6 Reimplemented to paint the background panel.
        N)
r   QStylePainterQStyleOptionFrameinitFromdrawPrimitiver-   PE_PanelTipLabelendr   
paintEvent)r3   rH   painteroptionr5   s       r6   r`   zCallTipWidget.paintEventi   s|     )$//,..i.?HHH5!!!!!r7   c                 J    t                                          |           dS )z> Reimplemented to allow use of this method as a slot.
        N)r   r   )r3   fontr5   s     r6   r   zCallTipWidget.setFontt   s!     	r7   c                     t                                          |           | j        j                            | j                   | j                            |            dS )zD Reimplemented to connect signal handlers and event filter.
        N)r   	showEventr   rR   r   rT   installEventFilterrO   s     r6   rf   zCallTipWidget.showEventy   s\     	%   -55)	+ 	+ 	+**400000r7   c                 h    	 t                                                      S # t          $ r Y dS w xY w)zm Avoids an error when the widget has already been deleted.

            Fixes jupyter/qtconsole#507.
        N)r   r   RuntimeError)r3   r5   s    r6   r   zCallTipWidget.deleteLater   s@    
	77&&((( 	 	 	DD	s   # 
11   c                    |                     di           }|                     dd          }t          j        d|z  |          }|r|d|                                         dz   }|                     |                     |                    S )z!Show inspection data as a tooltipdataz
text/plain z(?:[^
]*
){%i}Nz
[Documentation continues...])getrematchr_   show_tip_format_tooltip)r3   contentmaxlinesrl   textrp   s         r6   show_inspect_datazCallTipWidget.show_inspect_data   s    {{62&&xxb))+h6== 	I%(HHD}}T11$77888r7   c                 f   | j         }|                                }|                                }|                                dz
  }|                     |d          \  | _        }| j        dk    rdS |                     |           |                     |                                            d}|	                    |          }t          r'|                                                                }	nCt          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
}t7          |||          }|                     |                      }
|
                    |
                                |z              |d	k    r*|
                    |
                                |z
             |d
k    r-|
                    |
                                |z
  |z
             |                     |
           |                                  dS )zL Attempts to show the specified tip at the current cursor location.
        r   F)forward   bottomRight   topLeftT)r   r   
textCursorposition_find_parenthesis_start_positionsetTextresizesizeHint
cursorRectr   screengeometryr   QApplicationinstancedesktopscreenGeometrymapToGlobalbottomRightsetYysizeheightwidthtopRightxgetattrsetXmoveshow)r3   tipr4   r   cursor
search_pos_paddingcursor_rectscreen_rectpoint
tip_height	tip_widthvertical
horizontalpoint_poss                    r6   rq   zCallTipWidget.show_tip   s    O	%%''%%''__&&*
"&"8"8AF #9 #H #Ha2%%5 	SDMMOO$$$
 **622 	`#**,,5577KK#099;;CCEETTU^__K%%k&=&=&?&?@@

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%%ccee,,

57799w&'''uJJuwwyy:-...JJuwwyy9,w6777		%		tr7   Tc                    dx}}| j                                         }|                    |          }t          |          dk    rx|dk    rr|dk    r|dk    r|dz  }n)|dk    r|r|dk    rnS|dz  }n|dk    r|s|dk    rn>|dz  }||rdndz  }|                    |          }t          |          dk    r|dk    rd}||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   Cc,r   )(ry   )r   r   characterAtr   )r3   r   rx   commasdepthr   chars          r6   r   zCallTipWidget._find_parenthesis   s
    ?++--##H-- tnn$$As{{uzz! uzz
 5A::
W,",H''11D tnn$$A Hr7   c                    | j                                         snt          j                                                            t          j                                                  | k    r| j         	                    d|            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   isActiver   r   r   
topLevelAtr   QCursorr   start)r3   s    r6   rE   zCallTipWidget._leave_event_hide   s      ))++ 	. "++--889J9J9L9LMMQUUU""3-----	. 	. VUr7   c                 2    t          j        dd|          }|S )Nz\033\[(\d|;)+?mrm   )ro   sub)r3   docs     r6   rr   zCallTipWidget._format_tooltip
  s    f'S11
r7   c                    | j                                         }|                                | j        k    r|                                  dS |                     | j        dz             \  }}|dk    r|                                  dS dS )z8 Updates the tip based on user cursor movement.
        r   ry   N)r   r   r   r   r?   r   )r3   r   r   r   s       r6   rT   z&CallTipWidget._cursor_position_changed  s     ++--?? 444IIKKKKK#55d6JQ6NOOHf2~~		 ~r7   )rj   )T)__name__
__module____qualname____doc__r   rF   rL   rN   rQ   rX   r`   r   rf   r   rv   rq   r   rE   rr   rT   __classcell__)r5   s   @r6   r	   r	   
   s            4/ / / / /4           
0 
0 
0 
0 
0! ! ! ! !	" 	" 	" 	" 	"    
1 1 1 1 1    9 9 9 9C C CR       :	. 	. 	.  	 	 	 	 	 	 	r7   r	   )
ro   unicodedatar   qtpyr   r   r   r   QLabelr	    r7   r6   <module>r      s    				                   ) ) ) ) ) ) ) ) ) )O O O O OI$ O O O O Or7   