
    AHj                    L    d Z ddlmZ ddlmZ  G d de      Z G d de      Zy)	z!
Tools for lazy loading widgets.
    )annotations)Widgetc                  8     e Zd ZdZdZd fdZddZddZ xZS )Lazya  Wraps a widget so that it is mounted *lazily*.

    Lazy widgets are mounted after the first refresh. This can be used to display some parts of
    the UI very quickly, followed by the lazy widgets. Technically, this won't make anything
    faster, but it reduces the time the user sees a blank screen and will make apps feel
    more responsive.

    Making a widget lazy is beneficial for widgets which start out invisible, such as tab panes.

    Note that since lazy widgets aren't mounted immediately (by definition), they will not appear
    in queries for a brief interval until they are mounted. Your code should take this into account.

    Example:
        ```python
        def compose(self) -> ComposeResult:
            yield Footer()
            with ColorTabs("Theme Colors", "Named Colors"):
                yield Content(ThemeColorButtons(), ThemeColorsView(), id="theme")
                yield Lazy(NamedColorsView())
        ```

    z6
    Lazy {
        display: none;        
    } 
    c                0    || _         t        | 	          y)zrCreate a lazy widget.

        Args:
            widget: A widget that should be mounted after a refresh.
        N)_replace_widgetsuper__init__selfwidget	__class__s     D/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/lazy.pyr
   zLazy.__init__(   s      &    c                :    | j                   j                  |       y N)r   compose_add_childr   r   s     r   r   zLazy.compose_add_child1   s    ..v6r   c                    K    j                   y t        t              sJ d fd} j                  |       y w)Nc                    K    j                  j                         d{    j                          d{    y7 7 w)z.Perform the mount and discard the lazy widget.afterN)mountr   remove)parentr   s   r   r   z*Lazy.mount_composed_widgets.<locals>.mount:   s<     ,,t334,@@@++- As   !AAAAAAreturnNone)r   
isinstancer   call_after_refresh)r   widgetsr   r   s   `  @r   mount_composed_widgetszLazy.mount_composed_widgets4   s=     >&&)))	 
 	&s   ;?r   r   r   r   r!   list[Widget]r   r   )	__name__
__module____qualname____doc__DEFAULT_CSSr
   r   r"   __classcell__r   s   @r   r   r   
   s    .K7'r   r   c                  J     e Zd ZdZdZd fdZedd       ZddZd	dZ	 xZ
S )
Reveala  Similar to [Lazy][textual.lazy.Lazy], but mounts children sequentially.

    This is useful when you have so many child widgets that there is a noticeable delay before
    you see anything. By mounting the children over several frames, the user will feel that
    something is happening.

    Example:
        ```python
        def compose(self) -> ComposeResult:
            with lazy.Reveal(containers.VerticalScroll(can_focus=False)):
                yield Markdown(WIDGETS_MD, classes="column")
                yield Buttons()
                yield Checkboxes()
                yield Datatables()
                yield Inputs()
                yield ListViews()
                yield Logs()
                yield Sparklines()
            yield Footer()
        ```
    z/
    Reveal {
        display: none;
    }
    c                >    || _         g | _        t        |           y)z>
        Args:
            widget: A widget to mount.
        N)r   _widgetsr	   r
   r   s     r   r
   zReveal.__init___   s    
  &&(r   c                <    dfdj                         y)zzReveal children lazily.

        Args:
            parent: The parent widget.
            widgets: Child widgets.
        c                    K   syj                  d      } 	 j                  |        d{    rj                  d       yy7 # t        $ r Y yw xY ww)zCheck for pending childrenNr   g{Gz?)popr   	Exception	set_timer)r   check_childrenr   r!   s    r   r6   z&Reveal._reveal.<locals>.check_childrenq   sc     [[^Fll6***   ~6  +  s7   AA
 AA
 AA
 
	AAAANr   )	call_next)clsr   r!   r6   s    ``@r   _revealzReveal._revealh   s    	7 	(r   c                :    | j                   j                  |       y r   )r0   appendr   s     r   r   zReveal.compose_add_child   s    V$r   c                l  K   | j                   }|y t        |t              sJ |j                  | j                  |        d {    | j                          d {    | j                  | j                  | j                  j                                | j                  j                          y 7 k7 Uw)Nr   )
r   r   r   r   r   r   r9   r0   copyclear)r   r!   r   s      r   r"   zReveal.mount_composed_widgets   s     >&&)))ll4//tl<<<kkmT))4==+=+=+?@ 	=s%   AB4B0B4B2AB42B4r#   )r   r   r!   r%   r   r   r$   )r&   r'   r(   r)   r*   r
   classmethodr9   r   r"   r+   r,   s   @r   r.   r.   B   s2    ,K ) )2%r   r.   N)r)   
__future__r   textual.widgetr   r   r.    r   r   <module>rC      s-    # !5'6 5'pKV Kr   