Mini Shell

Direktori : /usr/lib/python3.6/site-packages/simpleline/render/screen/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/simpleline/render/screen/__pycache__/input_manager.cpython-36.pyc

3

<�Zce�@s�ddlmZddlmZddlmZddlmZddlm	Z	ddl
mZmZddl
mZe�ZGdd	�d	e�ZGd
d�de�ZdS)
�)�Enum)�App)�ExitMainLoop)�ExceptionSignal)�Prompt)�InputHandler�PasswordInputHandler)�get_simpleline_loggercsxeZdZ�fdd�Zedd��Zedd��Zedd��Zejd	d��Zd
d�Z	dd
d�Z
dd�Zdd�Zdd�Z
�ZS)�InputManagercs,t�j�||_d|_d|_d|_d|_dS)z�Processor for user input.

        This class is mainly helper class for ScreenScheduler.

        :param ui_screen: Screen associated with this input manager.
        :type ui_screen: The `simpleline.render.screen.UIScreen` based instance.
        r�FN)�super�__init__�
_ui_screen�_input_error_counter�_input_error_threshold�_skip_concurrency_check�_input_args)�selfZ	ui_screen)�	__class__��#/usr/lib/python3.6/input_manager.pyr
%s
zInputManager.__init__cCs|jS)z2Return how many times the user provided bad input.)r)rrrr�input_error_counter4sz InputManager.input_error_countercCs|j|j}|dkS)zXDid the error counter pass the threshold?

        The screen should be redraw.
        r)rr)r�errorsrrr�input_error_threshold_exceeded9sz+InputManager.input_error_threshold_exceededcCs|jS)znShould the concurrency check be skipped?

        :returns bool: True if the check should be skipped.
        )r)rrrr�skip_concurrency_checkBsz#InputManager.skip_concurrency_checkcCs
||_dS)a=Set if the concurrency check should be skipped when asking for user input.

        WARNING: Use this option with caution. When the concurrency check is disabled you
                 can easily get to unexpected behavior which is hard to debug.

        :param bool value: True to skip the concurrency check.
        N)r)r�valuerrrrJs	cCsP|r&t|d�}|jjr0|j|jj�n
t|d�}|j|_|j|�|j�|j	S)z�Get blocking input from the user.

        :param message: Message prompt for the user.
        :type message: str

        :param hidden: Do not echo user input (password typing).
        :type hidden: bool
        )�source)
rr�
password_func�
set_pass_funcrrr�	get_inputZ
wait_on_inputr)r�messageZhidden�handlerrrr�get_input_blockingUs	


zInputManager.get_input_blockingNcCsz|jj|�}|j|�sdS||_|jjs6t|jd�}n"t|jd�}|jjrX|j|jj�|j	|_
|j|j�|j
|�dS)z�Get input from user.

        :param args: Arguments passed in when UIScreen was scheduled.
        :type args: Anything.
        N)r)r�prompt�_is_input_expectedrZhide_user_inputrrrrrrZset_callback�
process_inputr)r�argsr#r!rrrrjs
zInputManager.get_inputcCs|dkrd|_dSdSdS)a9Check if user handled input processing some other way.

        Do nothing if user did handled user input.

        :returns: True if prompt is set and we can use it to get user input.
                  False if prompt is not available, which means that user handled input on their
                  own.
        NrFT)r)rr#rrrr$�s
zInputManager._is_input_expectedcCs~y|j|�}Wn:tk
r$�Yn&tk
rHtj�jt|��dSX|j�rZd|_n|jd7_tj	�j
||j�dS)z�Process input from the screens.

        :param user_input: User input string.
        :type user_input: String.

        :raises: ExitMainLoop or any other kind of exception from screen processing.
        Nr�)�_process_inputr�	ExceptionrZget_event_loopZenqueue_signalr�was_successfulrZ
get_schedulerZprocess_input_resultr)rZ
user_input�resultrrrr%�s
zInputManager.process_inputcCs�ddlm}yT|jj|j|�}||jkr.tjS||jkr>tj	S||j
krNtjS||jkr^tj
SWntk
rv�YnX|tjkr�tj	S|tjkr�tjS|tjkr�tjS|dkr�tjd�tj
S)aVMethod called internally to process unhandled input key presses.

        :param key: The string entered by user.
        :type key: String.

        :return: Return state result object.
        :rtype: `simpleline.render.in_out_manager.UserInputResult` class.

        :raises: Anything the Screen can raise in the input processing.
        r)�
InputStateNzXReturned key from screen is None. This could be missing return in a screen input method?)Zsimpleline.render.screenr,r�inputrZ	PROCESSED�UserInputAction�NOOPZPROCESSED_AND_REDRAW�REDRAWZPROCESSED_AND_CLOSE�CLOSEZ	DISCARDED�INPUT_ERRORrrZREFRESHZCONTINUE�QUIT�logZwarning)r�keyr,rrrr(�s,








zInputManager._process_input)N)�__name__�
__module__�__qualname__r
�propertyrrr�setterr"rr$r%r(�
__classcell__rr)rrr
#s	
r
c@s,eZdZdZd
ZdZdZdZdZdd�Z	d	S)r.zStore user input result.r'rr��cCs
|tjkS)N)r.r2)rrrrr*�szUserInputAction.was_successfulN���)
r6r7r8�__doc__r2r/r0r1r3r*rrrrr.�sr.N)�enumrZ
simplelinerZsimpleline.event_looprZsimpleline.event_loop.signalsrZsimpleline.render.promptrZsimpleline.inputrrZsimpleline.loggingr	r4�objectr
r.rrrr�<module>s5