Mini Shell

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

3

<�Zc�.�@s�ddlZddlmZddlmZddlmZmZmZddl	m
Z
ddlmZddl
mZmZmZddlmZe�Zej�Zd	gZGd
d	�d	e�ZdS)�N)�App)�ExitMainLoop)�ExceptionSignal�RenderScreenSignal�CloseScreenSignal)�RenderUnexpectedError)�UserInputAction)�ScreenStack�
ScreenData�ScreenStackEmptyException)�get_simpleline_logger�ScreenSchedulerc@s�eZdZd)dd�Zdd�Zdd�Zedd	��Zejd
d	��Zedd��Z	d
d�Z
d*dd�Zdd�Zd+dd�Z
d,dd�Zd-dd�Zdd�Zd.dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�ZdS)/r
NcCs2d|_||_|r||_nt�|_|j�d|_dS)a�Constructor where you can pass your own scheduler stack.

        The ScreenStack will be used automatically if scheduler stack will be None.

        :param event_loop: Event loop used for the scheduler.
        :type event_loop: Class based on `simpleline.event_loop.AbstractEventLoop`.
        :param scheduler_stack: Use custom scheduler stack if you need to.
        :type scheduler_stack: `simpleline.screen_stack.ScreenStack` based class.
        NF)�_quit_screen�_event_loop�
_screen_stackr	�_register_handlers�_first_screen_scheduled)�selfZ
event_loopZscheduler_stack�r�&/usr/lib/python3.6/screen_scheduler.py�__init__,s
zScreenScheduler.__init__cCsdjdtj�jdg�S)N�
��=)�joinrZget_configuration�width)rrrr�_spacerAszScreenScheduler._spacercCs$|jjt|j�|jjt|j�dS)N)rZregister_signal_handlerr�_process_screen_callbackr�_close_screen_callback)rrrrrDsz"ScreenScheduler._register_handlerscCs|jS)zReturn quit UIScreen.)r)rrrr�quit_screenHszScreenScheduler.quit_screencCs
||_dS)a,Set the UIScreen based instance which will be showed before the Application will quit.

        You can also use `simpleline.render.adv_widgets.YesNoDialog` or `UIScreen` based class
        with the `answer` property. Without the `answer` property the application will always
        close.
        N)r)rrrrrrMscCs
|jj�S)z�Is something for rendering in the scheduler stack?

        :return: True if the rendering stack is empty
        :rtype: bool
        )r�empty)rrrr�nothing_to_renderWsz!ScreenScheduler.nothing_to_rendercCs
|jj�S)z1Get string representation of actual screen stack.)r�
dump_stack)rrrrr"`szScreenScheduler.dump_stackcCs.tjd|�t||�}|jj|�|j�dS)aPAdd screen to the bottom of the stack.

        This is mostly useful at the beginning to prepare the first screen hierarchy to display.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument, please see switch_screen for details
        :type args: anything
        zScheduling screen %sN)�log�debugr
rZ	add_first�!_redraw_on_first_scheduled_screen)r�	ui_screen�args�screenrrr�schedule_screends

zScreenScheduler.schedule_screencCs|js|j�d|_dS)NT)r�redraw)rrrrr%ssz1ScreenScheduler._redraw_on_first_scheduled_screencCs^tjd|�y|jj�j}Wntk
r8td��YnXt|||�}|jj|�|j�dS)aNSchedules a screen to replace the current one.

        :param ui_screen: screen to show
        :type ui_screen: instance of UIScreen
        :param args: optional argument to pass to ui's refresh and setup methods
                     (can be used to select what item should be displayed or so)
        :type args: anything
        zReplacing screen %sz@Switch screen is not possible when there is no screen scheduled!N)	r#r$r�pop�execute_new_looprr
�appendr*)rr&r'r,r(rrr�replace_screenxs	zScreenScheduler.replace_screencCs0tjd|�t||d�}|jj|�|j�dS)aSchedules a screen to show, but keeps the current one in stack to
        return to, when the new one is closed.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument
        :type args: anything
        zPushing screen %s to stackFN)r#r$r
rr-r*)rr&r'r(rrr�push_screen�s	zScreenScheduler.push_screencCs8tjd|�t||d�}|jj|�|jjt|��dS)a�Starts a new screen right away, so the caller can collect data back.

        When the new screen is closed, the caller is redisplayed.

        This method does not return until the new screen is closed.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument, please see switch_screen for details
        :type args: anything
        z Pushing modal screen %s to stackTN)r#r$r
rr-rr,r)rr&r'r(rrr�push_screen_modal�sz!ScreenScheduler.push_screen_modalcCs|j|j�dS)N)�close_screen�source)r�signal�datarrrr�sz&ScreenScheduler._close_screen_callbackcCs�|jj�}tjd||�|jj�|dk	rF||jk	rFtd||jf��|jrV|jj	�|jj
�rr|jrr|j�|jj
�r�t��dS)z�Close the currently displayed screen and exit it's main loop if necessary.

        Next screen from the stack is then displayed.
        zClosing screen %s from %sNzXYou are trying to close screen %s from screen %s! This is most probably not intentional.)
rr+r#r$r&�closedrr,rZ
close_loopr r*r)rZclosed_fromr(rrrr1�s



zScreenScheduler.close_screencCs|jjt|��dS)z4Register rendering to the event loop for processing.N)r�enqueue_signalr)rrrrr*�szScreenScheduler.redrawcCs|j�dS)N)�_process_screen)rr3r4rrrr�sz(ScreenScheduler._process_screen_callbackcCs�|j�}tjd|�|jjsL|jj|j�sL|jj�|j	�tj
d|�dSyN|jj|j�||j�krldS|j|�|jj
r�tjd|�|jj|j�Wn8tk
r��Yn$tk
r�|jjt|��dSXdS)z�Draws the current screen and returns True if user input is requested.

        If modal screen is requested, starts a new loop and initiates redraw after it ends.
        zProcessing screen %sz!Screen %s setup wasn't successfulNzInput is required by %s screenF)�_get_last_screenr#r$r&Zscreen_readyZsetupr'rr+r*ZwarningZrefresh�_draw_screenZinput_required�get_input_with_error_checkr�	Exceptionrr6r)rZ
top_screenrrrr7�s*

zScreenScheduler._process_screencCs`y"|jjst|j��|jj�Wn8tk
r8�Yn$tk
rZ|jjt	|��YnXdS)z�Draws the current `active_screen`.

        :param active_screen: Screen which should be draw to the console.
        :type active_screen: Classed based on `simpleline.render.screen.UIScreen`.
        N)
r&Zno_separator�printrZshow_allrr;rr6r)r�
active_screenrrrr9�szScreenScheduler._draw_screencCs|jj�rt��|jjd�S)NF)rr rr+)rrrrr8s
z ScreenScheduler._get_last_screencCs�|j�}|j�s8|r|j�q�tjd�|jj|j�n�|tj	krFdS|tj
krZ|j�nt|tjkrn|j�n`|tj
kr�|jr�|j|j�y |jjdkr�t��n|j�Wq�tk
r�t��Yq�Xnt��dS)Nz,Input was not successful, ask for new input.T)r8Zwas_successfulr*r#r$r&r:r'rZNOOPZREDRAWZCLOSEr1ZQUITrr0Zanswerr�AttributeError)rZinput_resultZ
should_redrawr=rrr�process_input_results,







z$ScreenScheduler.process_input_result)N)N)N)N)N)N)�__name__�
__module__�__qualname__rrr�propertyr�setterr!r"r)r%r.r/r0rr1r*rr7r9r8r?rrrrr
*s(

	




')Z	threadingZ
simplelinerZsimpleline.event_looprZsimpleline.event_loop.signalsrrrZsimpleline.renderrZ&simpleline.render.screen.input_managerrZsimpleline.render.screen_stackr	r
rZsimpleline.loggingrr#ZLockZRAW_INPUT_LOCK�__all__�objectr
rrrr�<module>s