
    
8d                     `    d Z ddlZddlZddlmZ ddlmZmZmZ  G d dej                  Z	dS )z.A dropdown completer widget for the qtconsole.    N)QT6)QtCoreQtGui	QtWidgetsc                   r     e Zd ZdZd fd	Z fdZ fdZ fdZ fdZddZ	d	 Z
d
 Zd Zd Zd Z xZS )CompletionWidgetz& A widget for GUI tab completion.
    r   c                 "   |j         }t          |t          j        t          j        f          sJ t                                          |           || _        |dk    r|n%|                                 	                                | _
        |                     t          j        j                   |                     t          j        j                   |                     t          j        j                   |                     t&          j        j                   |                     t&          j        j                   |                                }|                     t&          j        j                   |                    |           |                     | j                   |                     t          j        j                   |                     t          j        j                    | j!        "                    | j#                   dS )zg Create a completion widget that is attached to the specified Qt
            text edit widget.
        )parentr   N)$_control
isinstancer   	QTextEditQPlainTextEditsuper__init__
_text_editsizeHintheight_height_maxsetEditTriggersQAbstractItemViewNoEditTriggerssetSelectionBehavior
SelectRowssetSelectionModeSingleSelectionsetWindowFlagsr   QtPopupsetAttributeWA_StaticContentsfocusPolicysetFocusPolicyNoFocussetFocusProxysetFrameShadowQFramePlainsetFrameShapeStyledPanelitemActivatedconnect_complete_current)selfconsole_widgetr   	text_editoriginal_policy	__class__s        ;lib/python3.11/site-packages/qtconsole/completion_widget.pyr   zCompletionWidget.__init__   s    #+	)i&99;S%TUUUUU///#%+aZZ66T]]__5K5K5M5MY8GHHH!!)"="HIIIi9IJJJ 	FIO,,,&)5666#//11FI-...  111 	4?+++I,23339+7888""4#9:::::    c                    || u r|                                 t          j        j        k    rw|                     |                                          }t          j                            |          }|r| 	                    |          s|| u rdS | 
                                 t                                          ||          S )zj Reimplemented to handle mouse input and to auto-hide when the
            text edit loses focus.
        F)typer   QEventMouseButtonPressmapToGlobalposr   QApplicationwidgetAtisAncestorOfcancel_completionr   eventFilter)r-   objeventr9   targetr1   s        r2   r>   zCompletionWidget.eventFilter2   s     $;;zz||v}===&&uyy{{33"/88== -t0088 -FdNN 5**,,,ww""3...r3   c                 n   |                                 }|t          j        j        t          j        j        t          j        j        fv r|                                  d S |t          j        j        k    r|                                  d S |t          j        j	        t          j        j
        t          j        j        t          j        j        t          j        j        t          j        j        fv r!t                                          |          S t"          j                            | j        |           d S N)keyr   r   
Key_Return	Key_EnterKey_Tabr,   
Key_EscapehideKey_UpKey_Down
Key_PageUpKey_PageDownKey_HomeKey_Endr   keyPressEventr   r:   	sendEventr   )r-   r@   rD   r1   s      r2   rP   zCompletionWidget.keyPressEventA   s    iikk69')<9$& & &""$$$$$FI(((IIKKKKKVY%vy'9Y)69+AY'):< < < 77((///",,T_eDDDDDr3   c                     t                                          |           	 | j        j                            | j                   n# t          $ r Y nw xY w|                     |            dS )zG Reimplemented to disconnect signal handlers and event filter.
        N)r   	hideEventr   cursorPositionChanged
disconnect_update_current	TypeErrorremoveEventFilterr-   r@   r1   s     r2   rS   zCompletionWidget.hideEventS   s{     	%   	O1<<T=QRRRR 	 	 	D	t$$$$$s   $A	 	
AAc                     t                                          |           | j        j                            | j                   |                     |            dS )zD Reimplemented to connect signal handlers and event filter.
        N)r   	showEventr   rT   r+   rV   installEventFilterrY   s     r2   r[   zCompletionWidget.showEvent]   sS     	%   -55d6JKKK%%%%%r3   c           
      <	   |                      |          }|                                  g }|D ]H}t          j                            t          j                            |                    dd                              sPt          j                            t          j                            |                    dd                              r*|                    |                    dd                     t          j
                    }|                    t          j        j        |           |                    |                    d          d                    |                     |           Jt          j                            t          j                            |                    }|D ]}	t          j
                    }|                    t          j        j        |	           |r|	                    |          d         }
n|	}
|                    |
           |                     |           t(          r'|                                                                 }n1t          j                                                            |           }|                                }t5          t7          | j        |dz
                      }||                                z
  |z
  dk     r| j                            | j                                         !                                          }|                                }|"                    t5          |t7          ||dz
            z
                       | #                    d          | $                                %                                &                                z   d| '                                z  z   }| (                    |)                                |                                ||           |*                    tV          j,        j-        |	           |.                                | _/        | 0                    d           | 1                                 | 2                                 d
S )ze Shows the completion widget with 'items' at the position specified
            by 'cursor'.
        " .2   r   
      )nN)3_get_top_left_positionclearospathisfileabspathreplaceisdirappendr   QListWidgetItemsetDatar   r   UserRolesetTextsplitaddItemdirnamecommonprefixr   screenavailableGeometryr:   desktopr   intminr   yr   r8   
cursorRecttopRightsetYsizeHintForColumnverticalScrollBarr   width
frameWidthsetGeometryxmovePositionr   QTextCursorLeftposition_start_positionsetCurrentRowraise_show)r-   cursoritemsprefix_lengthpoint
path_itemsitem	list_itemcommon_prefix	path_itemtextscreen_rectscreen_heightr   pyws                   r2   
show_itemszCompletionWidget.show_itemsh   s    ++F33


 	( 	(D rwt||D"/E/EFFGG (GMM"'//$,,tR2H2H"I"IJJ(!!$,,tR"8"89999%577	!!&)"4d;;;!!$**S//""5666Y''''(<(<Z(H(HII# 	$ 	$I!133Ifi0)<<< ! }55b9 d###LL#### 	S++--99;;KK#088::LLTRRK#**,,S)=2+=>>??UWWYY&/144O//0J0J0L0L0U0U0W0WXXEBJJs2FBG 4 4455666##A&&##%%..0066889"""# 	EGGIIq&999 	E-2mDDD%001		r3   c                     | j                             | j                                                                                   S )z0 Get top left position for this widget.
        )r   r8   r}   bottomRightr-   r   s     r2   rf   z'CompletionWidget._get_top_left_position   s4     **4?+E+E+G+G+S+S+U+UVVVr3   c                     |                                                      t          j        j                  }|                                                     |           |                                  dS )zB Perform the completion with the currently selected item.
        N)currentItemdatar   r   rq   _current_text_cursor
insertTextrI   )r-   r   s     r2   r,   z"CompletionWidget._complete_current   sY     !!&&vy'9::!!##..t444		r3   c                     | j                                         }|                                | j        k    r*|                    | j        t
          j        j                   |S )zn Returns a cursor with text between the start position and the
            current position selected.
        )r   
textCursorr   r   setPositionr   r   
KeepAnchorr   s     r2   r   z%CompletionWidget._current_text_cursor   sZ     ++--?? 444t3$0;= = =r3   c                 N   | j                                         }|                     |          }|                    |                                            |                     |           |                                                                                                 }|rl| 	                    |t          j        j        t          j        j        z            }|r|                     |d                    dS |                                  dS |                                  dS )zh Updates the current item based on the current text and the
            position of the widget.
        r   N)r   r   rf   r   r|   mover   	selectiontoPlainText	findItemsr   r   MatchStartsWithMatchCaseSensitivesetCurrentItemrI   )r-   r   r   prefixr   s        r2   rV   z CompletionWidget._update_current   s    
 ++--++F33

46688		% **,,6688DDFF 	NN6FI,E,2I,H-I K KE ##E!H-----		IIKKKKKr3   c                 .    |                                   d S rC   )rI   )r-   s    r2   r=   z"CompletionWidget.cancel_completion   s    		r3   )r   )__name__
__module____qualname____doc__r   r>   rP   rS   r[   r   rf   r,   r   rV   r=   __classcell__)r1   s   @r2   r   r   
   s        ; ; ; ; ; ;@/ / / / /E E E E E$% % % % %& & & & &4 4 4 4tW W W
      ,      r3   r   )
r   rh   sysqtpyr   r   r   r   QListWidgetr    r3   r2   <module>r      s    4 4 				 



       ) ) ) ) ) ) ) ) ) )E E E E Ey, E E E E Er3   