B
    νvV/                 @   s6   d Z ddlmZmZ ddlmZ G dd dejZdS )z$A simple completer for the qtconsole    )QtCoreQtGuiNc                   s<   e Zd ZdZ fddZ fddZdd Zdd	 Z  ZS )
CompletionPlainz7 A widget for tab completion,  navigable by arrow keys c                sD   t |jtjtjfsttt|   |j| _	|| _
| j	|  dS )zg Create a completion widget that is attached to the specified Qt
            text edit widget.
        N)
isinstanceZ_controlr   Z	QTextEditZQPlainTextEditAssertionErrorsuperr   __init__
_text_edit_console_widgetZinstallEventFilter)selfZconsole_widget)	__class__ 9lib/python3.7/site-packages/qtconsole/completion_plain.pyr      s
    zCompletionPlain.__init__c                s@   || j kr.| }|tjjtjjfkr.|   tt| 	||S )zm Reimplemented to handle keyboard input and to auto-hide when the
            text edit loses focus.
        )
r	   typer   ZQEventZKeyPressZFocusOutcancel_completionr   r   eventFilter)r   objZeventetype)r   r   r   r      s
    
zCompletionPlain.eventFilterc             C   s   | j   dS )zCCancel the completion, reseting internal variable, clearing buffer N)r
   Z_clear_temporary_buffer)r   r   r   r   r   ,   s    z!CompletionPlain.cancel_completionc             C   s0   |sdS |    t|}| jj||dd dS )ze Shows the completion widget with 'items' at the position specified
            by 'cursor'.
        NF)Zhtml)r   textZ	columnizer
   Z_fill_temporary_buffer)r   ZcursoritemsZstrngr   r   r   
show_items1   s
    
zCompletionPlain.show_items)	__name__
__module____qualname____doc__r   r   r   r   __classcell__r   r   )r   r   r   
   s
   r   )r   Zqtconsole.qtr   r   Zipython_genutils.textr   ZQWidgetr   r   r   r   r   <module>   s   