§
    ŒŸjˆ6  ã                  óÆ   — d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
mZmZmZmZ ddlmZmZmZ g d¢Zeeeee
f         Z G d	„ d
¦  «        Z G d„ de¦  «        Zddd„ZdS )z
Wrapper for the layout.
é    )Úannotations)Ú	GeneratorÚIterableÚUnion)ÚBufferé   )ÚAnyContainerÚConditionalContainerÚ	ContainerÚWindowÚto_container)ÚBufferControlÚSearchBufferControlÚ	UIControl)ÚLayoutÚInvalidLayoutErrorÚwalkc                  óŠ  — e Zd ZdZ	 d4d5d	„Zd6d„Zd7d„Zd8d„Zd9d„Zd:d„Z	e
d;d„¦   «         Zej        d<d„¦   «         Ze
d=d„¦   «         Zej        d>d„¦   «         Ze
d?d„¦   «         Ze
d@d„¦   «         ZdAd „ZdBd"„Ze
dCd$„¦   «         ZdDd&„Ze
d?d'„¦   «         Ze
d;d(„¦   «         ZdEd)„ZdEd*„ZdEd+„ZdFd-„ZdFd.„ZdEd/„ZdEd0„ZdGd3„ZdS )Hr   aL  
    The layout for a prompt_toolkit
    :class:`~prompt_toolkit.application.Application`.
    This also keeps track of which user control is focused.

    :param container: The "root" container for the layout.
    :param focused_element: element to be focused initially. (Can be anything
        the `focus` function accepts.)
    NÚ	containerr	   Úfocused_elementúFocusableElement | NoneÚreturnÚNonec                óN  — t          |¦  «        | _        g | _        i | _        i | _        |€]	 | j                             t          |                      ¦   «         ¦  «        ¦  «         n7# t          $ r}t          d¦  «        |‚d }~ww xY w|  
                    |¦  «         g | _        d S )Nz>Invalid layout. The layout does not contain any Window object.)r   r   Ú_stackÚsearch_linksÚ_child_to_parentÚappendÚnextÚfind_all_windowsÚStopIterationr   ÚfocusÚvisible_windows)Úselfr   r   Úes       úi/var/www/finuniver-perm.ru/html/student/venv/lib/python3.11/site-packages/prompt_toolkit/layout/layout.pyÚ__init__zLayout.__init__(   sÃ   € õ
 & iÑ0Ô0ˆŒØ$&ˆŒð GIˆÔð
 =?ˆÔàÐ"ðØ”×"Ò"¥4¨×(=Ò(=Ñ(?Ô(?Ñ#@Ô#@ÑAÔAÐAÐAøÝ ð ð ð Ý(ØTñô àðøøøøðøøøð
 �JŠJ�Ñ'Ô'Ð'ð .0ˆÔÐÐs   ­9A' Á'
BÁ1BÂBÚstrc                ó(   — d| j         ›d| j        ›d�S )NzLayout(z, current_window=ú))r   Úcurrent_window©r$   s    r&   Ú__repr__zLayout.__repr__J   s    € ØT˜œÐTÐT¸DÔ<OÐTÐTÐTÐTó    úGenerator[Window, None, None]c              #  ój   K  — |                       ¦   «         D ]}t          |t          ¦  «        r|V — ŒdS )zJ
        Find all the :class:`.UIControl` objects in this layout.
        N)r   Ú
isinstancer   )r$   Úitems     r&   r    zLayout.find_all_windowsM   sE   è è € ð —I’I‘K”Kð 	ð 	ˆDÝ˜$¥Ñ'Ô'ð Ø�
�
�
øð	ð 	r.   úIterable[UIControl]c              #  óJ   K  — |                       ¦   «         D ]}|j        V — Œd S ©N)r    Úcontent©r$   r   s     r&   Úfind_all_controlszLayout.find_all_controlsU   s=   è è € Ø×.Ò.Ñ0Ô0ð 	$ð 	$ˆIØÔ#Ð#Ð#Ð#Ð#ð	$ð 	$r.   ÚvalueÚFocusableElementc                ó   — t          |t          ¦  «        rg|                      ¦   «         D ]?}t          |t          ¦  «        r(|j        j        |k    r|                      |¦  «          dS Œ@t          d|›d�¦  «        ‚t          |t          ¦  «        rb|                      ¦   «         D ]:}t          |t          ¦  «        r#|j        |k    r|                      |¦  «          dS Œ;t          d|›d�¦  «        ‚t          |t          ¦  «        rQ||                      ¦   «         vrt          d¦  «        ‚| 
                    ¦   «         st          d¦  «        ‚|| _        dS t          |¦  «        }t          |t          ¦  «        r1||                      ¦   «         vrt          d|›�¦  «        ‚|| _        dS g }t!          |d¬¦  «        D ]E}t          |t          ¦  «        r.|j         
                    ¦   «         r|                     |¦  «         ŒFt'          | j        ¦  «        D ]}||v r
|| _         dS Œ|r|d	         | _        dS t          d
|›�¦  «        ‚)a¨  
        Focus the given UI element.

        `value` can be either:

        - a :class:`.UIControl`
        - a :class:`.Buffer` instance or the name of a :class:`.Buffer`
        - a :class:`.Window`
        - Any container object. In this case we will focus the :class:`.Window`
          from this container that was focused most recent, or the very first
          focusable :class:`.Window` of the container.
        Nz,Couldn't find Buffer in the current layout: ú.z7Invalid value. Container does not appear in the layout.z*Invalid value. UIControl is not focusable.z5Invalid value. Window does not appear in the layout: T©Úskip_hiddenr   z,Invalid value. Container cannot be focused: )r1   r(   r8   r   ÚbufferÚnamer"   Ú
ValueErrorr   r   Úis_focusableÚcurrent_controlr   r   r    r+   r   r6   r   Úreversedr   )r$   r9   ÚcontrolÚwindowsÚcÚws         r&   r"   zLayout.focusY   s¯  € õ �e�SÑ!Ô!ð >	Ø×1Ò1Ñ3Ô3ð ð �Ý˜g¥}Ñ5Ô5ð ¸'¼.Ô:MÐQVÒ:VÐ:VØ—J’J˜wÑ'Ô'Ð'Ø�F�FøÝÐVÈEÐVÐVÐVÑWÔWÐWõ ˜�vÑ&Ô&ð 6	Ø×1Ò1Ñ3Ô3ð ð �Ý˜g¥}Ñ5Ô5ð ¸'¼.ÈEÒ:QÐ:QØ—J’J˜wÑ'Ô'Ð'Ø�F�FøÝÐVÈEÐVÐVÐVÑWÔWÐWõ ˜�yÑ)Ô)ð .	Ø˜D×2Ò2Ñ4Ô4Ð4Ð4Ý ØMñô ð ð ×%Ò%Ñ'Ô'ð OÝ Ð!MÑNÔNÐNà#(ˆDÔ Ð Ð õ ! Ñ'Ô'ˆEå˜%¥Ñ(Ô(ð  à × 5Ò 5Ñ 7Ô 7Ð7Ð7Ý$ØYÐPUÐYÐYñô ð ð ',�Ô#Ð#Ð#ð �Ý˜e°Ð6Ñ6Ô6ð *ð *�AÝ! !¥VÑ,Ô,ð *°´×1GÒ1GÑ1IÔ1Ið *ØŸš qÑ)Ô)Ð)øõ " $¤+Ñ.Ô.ð ð �AØ˜G�|�|Ø./˜Ô+Ø˜˜ð $ð
 ð Ø*1°!¬*�DÔ'Ø�Få ØLÀ5ÐLÐLñô ð r.   Úboolc                ó€  — t          |t          ¦  «        r| j        €dS | j        j        |k    S t          |t          ¦  «        r| j        |k    S t          |t
          ¦  «        r| j        |k    S t          |¦  «        }t          |t          ¦  «        r| j	        |k    S t          |¦  «        D ]}|| j	        k    r dS ŒdS )zˆ
        Check whether the given control has the focus.
        :param value: :class:`.UIControl` or :class:`.Window` instance.
        NFT)r1   r(   Úcurrent_bufferr@   r   r   rC   r   r   r+   r   )r$   r9   Úelements      r&   Ú	has_focuszLayout.has_focus§   sØ   € õ
 �e�SÑ!Ô!ð 	5ØÔ"Ð*Ø�uØÔ&Ô+¨uÒ4Ð4Ý�e�VÑ$Ô$ð 	0ØÔ&¨%Ò/Ð/Ý�e�YÑ'Ô'ð 	ØÔ'¨5Ò0Ð0å  Ñ'Ô'ˆEÝ˜%¥Ñ(Ô(ð ØÔ*¨eÒ3Ð3õ  $ E™{œ{ð $ð $�GØ $Ô"5Ò5Ð5Ø#˜t˜tð 6à�ur.   r   c                ó&   — | j         d         j        S )zI
        Get the :class:`.UIControl` to currently has the focus.
        éÿÿÿÿ)r   r6   r,   s    r&   rC   zLayout.current_controlÀ   s   € ð
 Œ{˜2ŒÔ&Ð&r.   rE   c                óx   — |                       ¦   «         D ]}|j        |k    r
|| _         dS Œt          d¦  «        ‚)zC
        Set the :class:`.UIControl` to receive the focus.
        Nz(Control not found in the user interface.)r    r6   r+   rA   )r$   rE   Úwindows      r&   rC   zLayout.current_controlÇ   sQ   € ð
 ×+Ò+Ñ-Ô-ð 	ð 	ˆFØŒ~ Ò(Ð(Ø&,�Ô#Ø��ð )õ ÐCÑDÔDÐDr.   r   c                ó   — | j         d         S )z=Return the :class:`.Window` object that is currently focused.rO   )r   r,   s    r&   r+   zLayout.current_windowÓ   s   € ð Œ{˜2ŒÐr.   c                ó:   — | j                              |¦  «         dS )z8Set the :class:`.Window` object to be currently focused.N)r   r   )r$   r9   s     r&   r+   zLayout.current_windowØ   s    € ð 	Œ×Ò˜5Ñ!Ô!Ð!Ð!Ð!r.   c                ó   — | j         | j        v S )z#True if we are searching right now.)rC   r   r,   s    r&   Úis_searchingzLayout.is_searchingÝ   s   € ð Ô# tÔ'8Ð8Ð8r.   úBufferControl | Nonec                ór   — | j         }t          |t          ¦  «        r| j                             |¦  «        S dS )zY
        Return the :class:`.BufferControl` in which we are searching or `None`.
        N)rC   r1   r   r   Úget)r$   rE   s     r&   Úsearch_target_buffer_controlz#Layout.search_target_buffer_controlâ   s;   € ð Ô&ˆå�gÕ2Ñ3Ô3ð 	ØÔ$×(Ò(¨Ñ1Ô1Ð1à�4r.   úIterable[Window]c              #  óœ   K  — |                       ¦   «         D ]4}t          |t          ¦  «        r|j                             ¦   «         r|V — Œ5dS )zl
        Return all the :class:`.Window` objects which are focusable (in the
        'modal' area).
        N)Úwalk_through_modal_arear1   r   r6   rB   )r$   rH   s     r&   Úget_focusable_windowszLayout.get_focusable_windowsð   s^   è è € ð
 ×-Ò-Ñ/Ô/ð 	ð 	ˆAÝ˜!�VÑ$Ô$ð ¨¬×)?Ò)?Ñ)AÔ)Að Ø���øð	ð 	r.   úlist[Window]c                óR   ‡— | j         Šˆfd„|                      ¦   «         D ¦   «         S )zO
        Return a list of :class:`.Window` objects that are focusable.
        c                ó   •— g | ]}|‰v ¯|‘Œ	S © ra   )Ú.0rH   r#   s     €r&   ú
<listcomp>z8Layout.get_visible_focusable_windows.<locals>.<listcomp>   s#   ø€ ÐPÐPÐP�a¸1ÀÐ;OÐ;O�Ð;OÐ;OÐ;Or.   )r#   r]   )r$   r#   s    @r&   Úget_visible_focusable_windowsz$Layout.get_visible_focusable_windowsù   s3   ø€ ð Ô.ˆØPÐPÐPÐP˜4×5Ò5Ñ7Ô7ÐPÑPÔPÐPr.   úBuffer | Nonec                óL   — | j         }t          |t          ¦  «        r|j        S dS )zD
        The currently focused :class:`~.Buffer` or `None`.
        N)rC   r1   r   r?   ©r$   Ú
ui_controls     r&   rK   zLayout.current_buffer  s,   € ð
 Ô)ˆ
Ý�j¥-Ñ0Ô0ð 	%ØÔ$Ð$Øˆtr.   Úbuffer_namec                óØ   — |                       ¦   «         D ]T}t          |t          ¦  «        r=t          |j        t          ¦  «        r#|j        j        j        |k    r|j        j        c S ŒUdS )zt
        Look in the layout for a buffer with the given name.
        Return `None` when nothing was found.
        N)r   r1   r   r6   r   r?   r@   )r$   ri   rH   s      r&   Úget_buffer_by_namezLayout.get_buffer_by_name  sj   € ð
 —’‘”ð 	,ð 	,ˆAÝ˜!�VÑ$Ô$ð ,­°A´I½}Ñ)MÔ)Mð ,Ø”9Ô#Ô(¨KÒ7Ð7Øœ9Ô+Ð+Ð+Ð+øØˆtr.   c                ó:   — | j         }t          |t          ¦  «        S )zÊ
        Return `True` if the currently focused control is a
        :class:`.BufferControl`. (For instance, used to determine whether the
        default key bindings should be active or not.)
        )rC   r1   r   rg   s     r&   Úbuffer_has_focuszLayout.buffer_has_focus  s   € ð Ô)ˆ
Ý˜*¥mÑ4Ô4Ð4r.   c                ól   — 	 | j         d         j        S # t          $ r | j         d         j        cY S w xY w)zJ
        Get the :class:`.UIControl` to previously had the focus.
        éþÿÿÿrO   )r   r6   Ú
IndexErrorr,   s    r&   Úprevious_controlzLayout.previous_control!  sF   € ð
	+Ø”;˜r”?Ô*Ð*øÝð 	+ð 	+ð 	+Ø”;˜r”?Ô*Ð*Ð*Ð*ð	+øøøs   ‚ ”3²3c                ób   — t          | j        ¦  «        dk    r| j        dd…         | _        dS dS )z=
        Give the focus to the last focused control.
        r   NrO   )Úlenr   r,   s    r&   Ú
focus_lastzLayout.focus_last+  s7   € õ ˆtŒ{ÑÔ˜aÒÐØœ+ c r cÔ*ˆDŒKˆKˆKð  Ðr.   c                ó  — |                       ¦   «         }t          |¦  «        dk    r`	 |                     | j        ¦  «        }|dz   t          |¦  «        z  }n# t          $ r d}Y nw xY w|                      ||         ¦  «         dS dS )z:
        Focus the next visible/focusable Window.
        r   r   N©rd   rs   Úindexr+   rA   r"   ©r$   rF   rw   s      r&   Ú
focus_nextzLayout.focus_next2  ó£   € ð ×4Ò4Ñ6Ô6ˆåˆw‰<Œ<˜!ÒÐð3ØŸš dÔ&9Ñ:Ô:�ð  ™¥c¨'¡l¤lÑ2��øõ ð ð ð Ø���ðøøøð
 �JŠJ�w˜u”~Ñ&Ô&Ð&Ð&Ð&ð Ðó   ©A ÁA(Á'A(c                ó  — |                       ¦   «         }t          |¦  «        dk    r`	 |                     | j        ¦  «        }|dz
  t          |¦  «        z  }n# t          $ r d}Y nw xY w|                      ||         ¦  «         dS dS )z>
        Focus the previous visible/focusable Window.
        r   r   Nrv   rx   s      r&   Úfocus_previouszLayout.focus_previousB  rz   r{   úIterable[Container]c              #  ó>   K  — t          | j        ¦  «        E d{V —† dS )zX
        Walk through all the layout nodes (and their children) and yield them.
        N)r   r   r,   s    r&   r   zLayout.walkR  s0   è è € õ ˜œÑ'Ô'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'r.   c              #  óÐ   K  — | j         }|                     ¦   «         s3|| j        v r*| j        |         }|                     ¦   «         s	|| j        v °*t          |¦  «        E d{V —† dS )zn
        Walk through all the containers which are in the current 'modal' part
        of the layout.
        N)r+   Úis_modalr   r   )r$   Úroots     r&   r\   zLayout.walk_through_modal_areaX  s   è è € ð Ô-ˆØ—-’-‘/”/ð 	/ d¨dÔ.CÐ&CÐ&CØÔ(¨Ô.ˆDð —-’-‘/”/ð 	/ d¨dÔ.CÐ&CÐ&Cõ ˜‘:”:ÐÐÐÐÐÐÐÐÐr.   c                óJ   ‡‡— i Šdˆˆfd„Š ‰| j         ¦  «         ‰| _        dS )z=
        Update child->parent relationships mapping.
        r%   r   r   r   c                óV   •— |                       ¦   «         D ]}| ‰|<    ‰|¦  «         Œd S r5   )Úget_children)r%   rG   Úparentsr   s     €€r&   r   z-Layout.update_parents_relations.<locals>.walkk  s>   ø€ Ø—^’^Ñ%Ô%ð ð �Ø�˜‘
Ø��Q‘”��ðð r.   N)r%   r   r   r   )r   r   )r$   r†   r   s    @@r&   Úupdate_parents_relationszLayout.update_parents_relationse  sP   øø€ ð ˆð	ð 	ð 	ð 	ð 	ð 	ð 	ð
 	ˆˆTŒ^ÑÔÐà 'ˆÔÐÐr.   c                ój   — | j                              ¦   «          | j                             ¦   «          d S r5   )r   Úclearr   Úresetr,   s    r&   rŠ   zLayout.resett  s3   € ð
 	Ô×ÒÑ!Ô!Ð!àŒ×ÒÑÔÐÐÐr.   r   úContainer | Nonec                ó@   — 	 | j         |         S # t          $ r Y dS w xY w)zo
        Return the parent container for the given container, or ``None``, if it
        wasn't found.
        N)r   ÚKeyErrorr7   s     r&   Ú
get_parentzLayout.get_parent}  s7   € ð
	ØÔ(¨Ô3Ð3øÝð 	ð 	ð 	Ø�4�4ð	øøøs   ‚ �
œr5   )r   r	   r   r   r   r   )r   r(   )r   r/   )r   r3   )r9   r:   r   r   )r9   r:   r   rI   )r   r   )rE   r   r   r   )r   r   )r9   r   r   r   )r   rI   )r   rV   )r   rZ   )r   r^   )r   re   )ri   r(   r   re   )r   r   )r   r~   )r   r   r   r‹   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   r-   r    r8   r"   rM   ÚpropertyrC   Úsetterr+   rU   rY   r]   rd   rK   rk   rm   rq   rt   ry   r}   r   r\   r‡   rŠ   rŽ   ra   r.   r&   r   r      s¶  € € € € € ðð ð 48ð 0ð  0ð  0ð  0ð  0ðDUð Uð Uð Uðð ð ð ð$ð $ð $ð $ðLð Lð Lð Lð\ð ð ð ð2 ð'ð 'ð 'ñ „Xð'ð Ôð	Eð 	Eð 	Eñ Ôð	Eð ðð ð ñ „Xðð Ôð"ð "ð "ñ Ôð"ð ð9ð 9ð 9ñ „Xð9ð ðð ð ñ „Xððð ð ð ðQð Qð Qð Qð ðð ð ñ „Xðð	ð 	ð 	ð 	ð ð5ð 5ð 5ñ „Xð5ð ð+ð +ð +ñ „Xð+ð+ð +ð +ð +ð'ð 'ð 'ð 'ð 'ð 'ð 'ð 'ð (ð (ð (ð (ðð ð ð ð(ð (ð (ð (ðð ð ð ðð ð ð ð ð r.   r   c                  ó   — e Zd ZdS )r   N)r�   r�   r‘   ra   r.   r&   r   r   ˆ  s   € € € € € Ø€Dr.   r   Fr   r   r>   rI   r   r~   c              #  óÈ   K  — |r+t          | t          ¦  «        r|                      ¦   «         sdS | V — |                      ¦   «         D ]}t	          ||¬¦  «        E d{V —† ŒdS )z:
    Walk through layout, starting at this container.
    Nr=   )r1   r
   Úfilterr…   r   )r   r>   rG   s      r&   r   r   Œ  s–   è è € ð 	ðå�yÕ"6Ñ7Ô7ðð × Ò Ñ"Ô"ðð
 	ˆà
€O€O€Oà×#Ò#Ñ%Ô%ð 4ð 4ˆå˜ {Ð3Ñ3Ô3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3ð4ð 4r.   N)F)r   r   r>   rI   r   r~   )r’   Ú
__future__r   Útypingr   r   r   Úprompt_toolkit.bufferr   Ú
containersr	   r
   r   r   r   Úcontrolsr   r   r   Ú__all__r(   r:   r   Ú	Exceptionr   r   ra   r.   r&   ú<module>rŸ      s_  ððð ð #Ð "Ð "Ð "Ð "Ð "à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à (Ð (Ð (Ð (Ð (Ð (ðð ð ð ð ð ð ð ð ð ð ð ð ð ð DÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ Cðð ð €ð ˜˜f i°Ð=Ô>Ð ðhð hð hð hð hñ hô hð hðV	ð 	ð 	ð 	ð 	˜ñ 	ô 	ð 	ð4ð 4ð 4ð 4ð 4ð 4ð 4r.   