
    ^h6                        S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
JrJrJrJr  SSKJrJrJr  / SQr\\\\\
4   r " S	 S
5      r " S S\5      rSSS jjrg)z
Wrapper for the layout.
    )annotations)	GeneratorIterableUnion)Buffer   )AnyContainerConditionalContainer	ContainerWindowto_container)BufferControlSearchBufferControl	UIControl)LayoutInvalidLayoutErrorwalkc                     \ rS rSrSr S     S S jjrS!S jrS"S jrS#S jrS$S jr	S%S	 jr
\S&S
 j5       r\R                  S'S j5       r\S(S j5       r\R                  S)S j5       r\S*S j5       r\S+S j5       rS,S jrS-S jr\S.S j5       rS/S jr\S*S j5       r\S&S j5       rS0S jrS0S jrS0S jrS1S jrS1S jrS0S jrS0S jrS2S jrSrg)3r      a0  
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.)
Nc                (   [        U5      U l        / U l        0 U l        0 U l        Uc4   U R                  R                  [        U R                  5       5      5        OU R                  U5        / U l        g ! [         a  n[        S5      UeS nAff = f)Nz>Invalid layout. The layout does not contain any Window object.)r   	container_stacksearch_links_child_to_parentappendnextfind_all_windowsStopIterationr   focusvisible_windows)selfr   focused_elementes       V/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/layout/layout.py__init__Layout.__init__(   s    
 &i0$& GI
 =?"""4(=(=(?#@A JJ' .0 ! (Ts   2A6 6
B BBc                @    SU R                   < SU R                  < S3$ )NzLayout(z, current_window=))r   current_windowr!   s    r$   __repr__Layout.__repr__J   s%    **;D<O<O;RRSTT    c              #  p   #    U R                  5        H  n[        U[        5      (       d  M  Uv   M      g7f)z:
Find all the :class:`.UIControl` objects in this layout.
N)r   
isinstancer   )r!   items     r$   r   Layout.find_all_windowsM   s)      IIKD$''
  s   '6	6c              #  V   #    U R                  5        H  nUR                  v   M     g 7fN)r   contentr!   r   s     r$   find_all_controlsLayout.find_all_controlsU   s$     ..0I### 1s   ')c                   [        U[        5      (       ak  U R                  5        HG  n[        U[        5      (       d  M  UR                  R
                  U:X  d  M6  U R                  U5          g   [        SU< S35      e[        U[        5      (       aa  U R                  5        H=  n[        U[        5      (       d  M  UR                  U:X  d  M,  U R                  U5          g   [        SU< S35      e[        U[        5      (       aE  XR                  5       ;  a  [        S5      eUR                  5       (       d  [        S5      eXl        g[        U5      n[        U[        5      (       a)  XR                  5       ;  a  [        SU< 35      eXl        g/ n[!        USS9 HL  n[        U[        5      (       d  M  UR"                  R                  5       (       d  M;  UR%                  U5        MN     ['        U R(                  5       H  nXS;   d  M
  XPl          g   U(       a  US	   U l        g[        S
U< 35      e)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: )r/   strr6   r   buffernamer   
ValueErrorr   r   is_focusablecurrent_controlr   r   r   r)   r   r4   r   reversedr   )r!   valuecontrolwindowscws         r$   r   Layout.focusY   s    eS!!113g}55'..:M:MQV:VJJw' 4 KE9TUVWW v&&113g}55'..E:QJJw' 4 KE9TUVWW y))2244 M  %%'' !MNN#(  !'E%(( 5 5 77$OPUyY  ',# e6A!!V,,1G1G1I1Iq) 7
 "$++.A|./+ / *1!*D' B5)L r-   c                   [        U[        5      (       a'  U R                  c  gU R                  R                  U:H  $ [        U[        5      (       a  U R                  U:H  $ [        U[
        5      (       a  U R                  U:H  $ [        U5      n[        U[        5      (       a  U R                  U:H  $ [        U5       H  nX R                  :X  d  M    g   g)zp
Check whether the given control has the focus.
:param value: :class:`.UIControl` or :class:`.Window` instance.
FT)r/   r<   current_bufferr>   r   r   rA   r   r   r)   r   )r!   rC   elements      r$   	has_focusLayout.has_focus   s    
 eS!!""*&&++u44eV$$&&%//eY''''500 'E%((**e33  $E{G"5"55#  + r-   c                4    U R                   S   R                  $ )z9
Get the :class:`.UIControl` to currently has the focus.
)r   r4   r*   s    r$   rA   Layout.current_control   s    
 {{2&&&r-   c                v    U R                  5        H  nUR                  U:X  d  M  X l          g   [        S5      e)z3
Set the :class:`.UIControl` to receive the focus.
Nz(Control not found in the user interface.)r   r4   r)   r?   )r!   rD   windows      r$   rA   rP      s:    
 ++-F~~(&,# .
 CDDr-   c                     U R                   S   $ )z=Return the :class:`.Window` object that is currently focused.rO   )r   r*   s    r$   r)   Layout.current_window   s     {{2r-   c                :    U R                   R                  U5        g)z8Set the :class:`.Window` object to be currently focused.N)r   r   )r!   rC   s     r$   r)   rT      s     	5!r-   c                4    U R                   U R                  ;   $ )z#True if we are searching right now.)rA   r   r*   s    r$   is_searchingLayout.is_searching   s     ##t'8'888r-   c                |    U R                   n[        U[        5      (       a  U R                  R	                  U5      $ g)zI
Return the :class:`.BufferControl` in which we are searching or `None`.
N)rA   r/   r   r   get)r!   rD   s     r$   search_target_buffer_control#Layout.search_target_buffer_control   s7     &&g233$$((11r-   c              #     #    U R                  5        H?  n[        U[        5      (       d  M  UR                  R	                  5       (       d  M;  Uv   MA     g7f)zT
Return all the :class:`.Window` objects which are focusable (in the
'modal' area).
N)walk_through_modal_arear/   r   r4   r@   )r!   rG   s     r$   get_focusable_windowsLayout.get_focusable_windows   s>     
 --/A!V$$)?)?)A)A 0s   'AA	Ac                t    U R                   nU R                  5        Vs/ s H  o"U;   d  M
  UPM     sn$ s  snf )z?
Return a list of :class:`.Window` objects that are focusable.
)r    r_   )r!   r    rG   s      r$   get_visible_focusable_windows$Layout.get_visible_focusable_windows   s7     ..557P7a;O7PPPs   	55c                ^    U R                   n[        U[        5      (       a  UR                  $ g)z4
The currently focused :class:`~.Buffer` or `None`.
N)rA   r/   r   r=   r!   
ui_controls     r$   rJ   Layout.current_buffer  s+    
 ))
j-00$$$r-   c                   U R                  5        Hw  n[        U[        5      (       d  M  [        UR                  [        5      (       d  M;  UR                  R
                  R                  U:X  d  Ma  UR                  R
                  s  $    g)z\
Look in the layout for a buffer with the given name.
Return `None` when nothing was found.
N)r   r/   r   r4   r   r=   r>   )r!   buffer_namerG   s      r$   get_buffer_by_nameLayout.get_buffer_by_name  s^    
 A!V$$AII})M)M99##((K799+++  r-   c                :    U R                   n[        U[        5      $ )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.)
)rA   r/   r   re   s     r$   buffer_has_focusLayout.buffer_has_focus  s     ))
*m44r-   c                     U R                   S   R                  $ ! [         a    U R                   S   R                  s $ f = f)z:
Get the :class:`.UIControl` to previously had the focus.
rO   )r   r4   
IndexErrorr*   s    r$   previous_controlLayout.previous_control!  s>    
	+;;r?*** 	+;;r?***	+s    #A Ac                `    [        U R                  5      S:  a  U R                  SS U l        gg)z-
Give the focus to the last focused control.
r   NrO   )lenr   r*   s    r$   
focus_lastLayout.focus_last+  s,     t{{a++cr*DK  r-   c                    U R                  5       n[        U5      S:  aA   UR                  U R                  5      nUS-   [        U5      -  nU R                  X   5        gg! [         a    Sn N#f = f)z*
Focus the next visible/focusable Window.
r   r   Nrb   ru   indexr)   r?   r   r!   rE   rz   s      r$   
focus_nextLayout.focus_next2  t     446w<!3d&9&9: c'l2JJw~&      A" "A10A1c                    U R                  5       n[        U5      S:  aA   UR                  U R                  5      nUS-
  [        U5      -  nU R                  X   5        gg! [         a    Sn N#f = f)z.
Focus the previous visible/focusable Window.
r   r   Nry   r{   s      r$   focus_previousLayout.focus_previousB  r~   r   c              #  J   #    [        U R                  5       Sh  vN   g N7f)zH
Walk through all the layout nodes (and their children) and yield them.
N)r   r   r*   s    r$   r   Layout.walkR  s      '''s   #!#c              #     #    U R                   nUR                  5       (       dD  XR                  ;   a5  U R                  U   nUR                  5       (       d  XR                  ;   a  M5  [        U5       Sh  vN   g N7f)zV
Walk through all the containers which are in the current 'modal' part
of the layout.
N)r)   is_modalr   r   )r!   roots     r$   r^   Layout.walk_through_modal_areaX  s_      ----//d.C.C&C((.D --//d.C.C&C :s   A$A>(A>6A<7A>c                P   ^^ 0 mSUU4S jjmT" U R                   5        TU l        g)z-
Update child->parent relationships mapping.
c                N   > U R                  5        H  nU TU'   T" U5        M     g r3   )get_children)r#   rF   parentsr   s     r$   r   -Layout.update_parents_relations.<locals>.walkk  s$    ^^%
Q &r-   N)r#   r   returnNone)r   r   )r!   r   r   s    @@r$   update_parents_relationsLayout.update_parents_relationse  s*     	 	
 	T^^ 'r-   c                l    U R                   R                  5         U R                  R                  5         g r3   )r   clearr   resetr*   s    r$   r   Layout.resett  s&    
 	!r-   c                B     U R                   U   $ ! [         a     gf = f)zW
Return the parent container for the given container, or ``None``, if it
wasn't found.
N)r   KeyErrorr5   s     r$   
get_parentLayout.get_parent}  s*    
	((33 		s    
)r   r   r   rA   r)   r   r    r3   )r   r	   r"   zFocusableElement | Noner   r   )r   r<   )r   zGenerator[Window, None, None])r   zIterable[UIControl])rC   FocusableElementr   r   )rC   r   r   bool)r   r   )rD   r   r   r   )r   r   )rC   r   r   r   )r   r   )r   zBufferControl | None)r   zIterable[Window])r   zlist[Window])r   Buffer | None)ri   r<   r   r   )r   r   )r   Iterable[Container])r   r   r   zContainer | None) __name__
__module____qualname____firstlineno____doc__r%   r+   r   r6   r   rL   propertyrA   setterr)   rW   r[   r_   rb   rJ   rj   rm   rr   rv   r|   r   r   r^   r   r   r   __static_attributes__ r-   r$   r   r      sD    48 0 0 1 0 
	 0DU$L\2 ' ' 	E 	E   " " 9 9  Q  	 5 5 + ++' ' ((r-   r   c                      \ rS rSrSrg)r   i  r   N)r   r   r   r   r   r   r-   r$   r   r     s    r-   r   c              #     #    U(       a+  [        U [        5      (       a  U R                  5       (       d  gU v   U R                  5        H  n[	        X!S9 Sh  vN   M     g N	7f)z2
Walk through layout, starting at this container.
Nr:   )r/   r
   filterr   r   )r   r;   rF   s      r$   r   r     sS      	y"677  ""
O##%333 &3s   AA$A"
A$N)F)r   r   r;   r   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   r   r-   r$   <module>r      sf    # - - (  D C fi=> h hV	 	4r-   