
    AHj                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ ddgZ G d ded      Z G d de      Zy)    )annotations)events)ComposeResult)Binding)	Container)ContentContentText)	NoMatches)Message)reactive)Widget)StaticCollapsibleCollapsibleTitlec                       e Zd ZU dZdZdZ edddd      gZ	  ed      Z	 e e
d	            Zd
ed<   	 	 	 	 	 	 	 	 	 	 d fdZ G d d	e      ZddZddZddZddZddZddZ xZS )r   z%Title and symbol for the Collapsible.Fa  
    CollapsibleTitle {
        width: auto;
        height: auto;
        padding: 0 1;
        text-style: $block-cursor-blurred-text-style;
        color: $block-cursor-blurred-foreground;

        &:hover {
            background: $block-hover-background;
            color: $foreground;
        }
        &:focus {
            text-style: $block-cursor-text-style;
            background: $block-cursor-background;
            color: $block-cursor-foreground;
        }
    }
    entertoggle_collapsiblezToggle collapsible)showTTogglezreactive[ContentText]labelc                   t         |           || _        || _        t	        j
                  |      | _        || _        y N)super__init__collapsed_symbolexpanded_symbolr   	from_textr   	collapsed)selfr   r   r   r   	__class__s        T/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_collapsible.pyr   zCollapsibleTitle.__init__5   s9     	 0.&&u-
"    c                      e Zd ZdZy)CollapsibleTitle.TogglezRequest toggle.N__name__
__module____qualname____doc__ r"   r!   r   r$   C   s    r"   c                j   K   |j                          | j                  | j                                yw)z"Inform ancestor we want to toggle.N)stoppost_messager   r   events     r!   	_on_clickzCollapsibleTitle._on_clickF   s#     

$++-(s   13c                B    | j                  | j                                y)z+Toggle the state of the parent collapsible.N)r-   r   r   s    r!   action_toggle_collapsiblez*CollapsibleTitle.action_toggle_collapsibleK   s    $++-(r"   c                ,    t        j                  |      S r   )r   r   )r   r   s     r!   validate_labelzCollapsibleTitle.validate_labelO   s      ''r"   c                >   t        | j                  t              sJ | j                  r;| j	                  t        j
                  | j                  d| j                               y | j	                  t        j
                  | j                  d| j                               y )N )
isinstancer   r   r   updateassembler   r   r2   s    r!   _update_labelzCollapsibleTitle._update_labelR   sg    $**g...>>KK(()>)>TZZPQKK(()=)=sDJJOPr"   c                $    | j                          y r   r;   r2   s    r!   _watch_labelzCollapsibleTitle._watch_labelY       r"   c                $    | j                          y r   r=   r   r   s     r!   _watch_collapsedz!CollapsibleTitle._watch_collapsed\   r?   r"   )
r   r	   r   strr   rC   r   boolreturnNone)r/   zevents.ClickrE   rF   )rE   rF   )r   r	   rE   r   r   rD   rE   rF   )r&   r'   r(   r)   ALLOW_SELECTDEFAULT_CSSr   BINDINGSr   r   r   r   __annotations__r   r   r   r0   r3   r5   r;   r>   rB   __classcell__r    s   @r!   r   r      s    /LK* 	-/C%PH I#+GH,=#>E ># # 	#
 # # 
# )
)(Qr"   T)	can_focusc            	          e Zd ZdZdZ edd      Z ed      ZdZ G d de	      Z
 G d	 d
e
      Z G d de
      Z G d de      Zddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZddZddZddZddZd dZd!dZ xZS )"r   zA collapsible container.TF)initr   a[  
    Collapsible {
        width: 1fr;
        height: auto;
        background: $surface;
        border-top: hkey $background;
        padding-bottom: 1;
        padding-left: 1;

        &:focus-within {
            background-tint: $foreground 5%;
        }

        &.-collapsed > Contents {
            display: none;   
        }
    }
    c                  6     e Zd ZdZd fdZedd       Z xZS )Collapsible.ToggledzParent class subclassed by `Collapsible` messages.

        Can be handled with `on(Collapsible.Toggled)` if you want to handle expansions
        and collapsed in the same way, or you can handle the specific events individually.
        c                2    || _         	 t        | 	          y)zCreate an instance of the message.

            Args:
                collapsible: The `Collapsible` widget that was toggled.
            N)collapsibler   r   )r   rT   r    s     r!   r   zCollapsible.Toggled.__init__   s     -8D3Gr"   c                    | j                   S )zTAn alias for [Toggled.collapsible][textual.widgets.Collapsible.Toggled.collapsible].)rT   r2   s    r!   controlzCollapsible.Toggled.control   s     ###r"   )rT   r   rE   rF   )rE   r   )r&   r'   r(   r)   r   propertyrV   rL   rM   s   @r!   ToggledrR   z   s!    		 
	$ 
	$r"   rX   c                      e Zd ZdZy)Collapsible.ExpandedzEvent sent when the `Collapsible` widget is expanded.

        Can be handled using `on_collapsible_expanded` in a subclass of
        [`Collapsible`][textual.widgets.Collapsible] or in a parent widget in the DOM.
        Nr%   r*   r"   r!   ExpandedrZ          	r"   r[   c                      e Zd ZdZy)Collapsible.CollapsedzEvent sent when the `Collapsible` widget is collapsed.

        Can be handled using `on_collapsible_collapsed` in a subclass of
        [`Collapsible`][textual.widgets.Collapsible] or in a parent widget in the DOM.
        Nr%   r*   r"   r!   	Collapsedr^      r\   r"   r_   c                      e Zd ZdZy)Collapsible.Contentszw
        Contents {
            width: 100%;
            height: auto;
            padding: 1 0 0 3;
        }
        N)r&   r'   r(   rI   r*   r"   r!   Contentsra      s	    r"   rb   u   ▶u   ▼N)titler   r   r   nameidclassesdisabledc                   t         
|   ||||       t        ||||      | _        || _        t        |	      | _        || _        y)aM  Initialize a Collapsible widget.

        Args:
            *children: Contents that will be collapsed/expanded.
            title: Title of the collapsed/expanded contents.
            collapsed: Default status of the contents.
            collapsed_symbol: Collapsed symbol before the title.
            expanded_symbol: Expanded symbol before the title.
            name: The name of the collapsible.
            id: The ID of the collapsible in the DOM.
            classes: The CSS classes of the collapsible.
            disabled: Whether the collapsible is disabled or not.
        )rd   re   rf   rg   )r   r   r   r   N)r   r   r   _titlerc   list_contents_listr   )r   rc   r   r   r   rd   re   rf   rg   childrenr    s             r!   r   zCollapsible.__init__   sO    2 	dr7XN&-+	
 
,0N"r"   c                H    |j                          | j                   | _        y r   )r,   r   r.   s     r!   _on_collapsible_title_togglez(Collapsible._on_collapsible_title_toggle   s    

!^^+r"   c                   | j                  |       | j                  r!| j                  | j                  |              n | j                  | j	                  |              | j
                  r| j                  | j                         yy)z0Update collapsed state when reactive is changed.N)_update_collapsedr   r-   r_   r[   
is_mountedcall_after_refreshscroll_visiblerA   s     r!   rB   zCollapsible._watch_collapsed   se    y)>>dnnT23dmmD12??##D$7$78 r"   c                j    	 || j                   _        | j                  |d       y# t        $ r Y yw xY w)z)Update children to match collapsed state.z
-collapsedN)ri   r   	set_classr
   rA   s     r!   rp   zCollapsible._update_collapsed   s3    	$-DKK!NN9l3 		s   #& 	22c                :    | j                  | j                         y)zInitialise collapsed state.N)rp   r   r.   s     r!   	_on_mountzCollapsible._on_mount   s    t~~.r"   c              #     K   | j                    | j                         5  | j                  E d {    d d d        y 7 # 1 sw Y   y xY wwr   )ri   rb   rk   r2   s    r!   composezCollapsible.compose   sE     kk]]_ 	+****	+ 	+*	+ 	+s)   AA?A	AAA
Ac                :    | j                   j                  |       y)zWhen using the context manager compose syntax, we want to attach nodes to the contents.

        Args:
            widget: A Widget to add.
        N)rk   append)r   widgets     r!   compose_add_childzCollapsible.compose_add_child   s     	""6*r"   c                &    || j                   _        y r   )ri   r   )r   rc   s     r!   _watch_titlezCollapsible._watch_title   s    !r"   )rl   r   rc   rC   r   rD   r   rC   r   rC   rd   
str | Nonere   r   rf   r   rg   rD   rE   rF   )r/   r$   rE   rF   rG   )r/   zevents.MountrE   rF   )rE   r   )r|   r   rE   rF   )rc   rC   rE   rF   )r&   r'   r(   r)   ALLOW_MAXIMIZEr   r   rc   rI   r   rX   r[   r_   r   rb   r   rn   rB   rp   rw   ry   r}   r   rL   rM   s   @r!   r   r   `   s    "NE*IXEK&$' $,7 G 9   %$""#"# "# 	"#
 "# "# "# "# "# "# 
"#H,9/+
+"r"   N)
__future__r   textualr   textual.appr   textual.bindingr   textual.containersr   textual.contentr   r	   textual.css.queryr
   textual.messager   textual.reactiver   textual.widgetr   textual.widgetsr   __all__r   r   r*   r"   r!   <module>r      sP    "  % # ( 0 ' # % ! ",
-Lv L^S"& S"r"   