
    AHj                        d 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mZ dd	lmZ dd
lmZ ddlmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)z-Provides a Textual application header widget.    )annotations)datetime)Text)ComposeResultRenderResult)Content)NoScreen)ClickMount)Reactive)Widget)Staticc                  >    e Zd ZdZdZ ed      Z	 ddZd	dZd
dZ	y)
HeaderIconz,Display an 'icon' on the left of the header.z
    HeaderIcon {
        dock: left;
        padding: 0 1;
        width: 8;
        content-align: left middle;
    }

    HeaderIcon:hover {
        background: $foreground 10%;
    }
       ⭘c                N    | j                   j                  rd| _        y d| _        y )NzOpen the command paletteT)appENABLE_COMMAND_PALETTEtooltipdisabledselfs    O/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_header.pyon_mountzHeaderIcon.on_mount%   s    88**5DL DM    c                b   K   |j                          | j                  d       d{    y7 w)z0Launch the command palette when icon is clicked.zapp.command_paletteN)stop
run_action)r   events     r   on_clickzHeaderIcon.on_click+   s"     

oo3444s   %/-/c                    | j                   S )zQRender the header icon.

        Returns:
            The rendered icon.
        )iconr   s    r   renderzHeaderIcon.render0   s     yyr   NreturnNone)r   r
   r%   r&   r%   r   )
__name__
__module____qualname____doc__DEFAULT_CSSr   r"   r   r    r#    r   r   r   r      s)    6K E?D=!5
r   r   c                      e Zd ZdZdZddZy)HeaderClockSpacez;The space taken up by the clock on the right of the header.z`
    HeaderClockSpace {
        dock: right;
        width: 10;
        padding: 0 1;
    }
    c                     y)zYRender the header clock space.

        Returns:
            The rendered space.
         r-   r   s    r   r#   zHeaderClockSpace.renderD   s     r   Nr'   )r(   r)   r*   r+   r,   r#   r-   r   r   r/   r/   9   s    EKr   r/   c                  @    e Zd ZU dZdZ ed      Zded<   d	dZd
dZ	y)HeaderClockz+Display a clock on the right of the header.z
    HeaderClock {
        background: $foreground-darken-1 5%;
        color: $foreground;
        text-opacity: 85%;
        content-align: center middle;
    }
    %XReactive[str]time_formatc                @    | j                  d| j                  d       y )N   zupdate header clock)callbackname)set_intervalrefresh)r   _s     r   	_on_mountzHeaderClock._on_mount[   s    !dll9NOr   c                    t        t        j                         j                         j	                  | j
                              S )zSRender the header clock.

        Returns:
            The rendered clock.
        )r   r   nowtimestrftimer6   r   s    r   r#   zHeaderClock.render^   s/     HLLN'')2243C3CDEEr   Nr=   r   r%   r&   r'   )
r(   r)   r*   r+   r,   r   r6   __annotations__r>   r#   r-   r   r   r3   r3   M   s(    5K "*$K/PFr   r3   c                      e Zd ZdZdZy)HeaderTitlez+Display the title / subtitle in the header.z
    HeaderTitle {
        text-wrap: nowrap;
        text-overflow: ellipsis;
        content-align: center middle;
        width: 100%;
    }
    N)r(   r)   r*   r+   r,   r-   r   r   rF   rF   g   s    5Kr   rF   c                       e Zd ZU dZdZdZ ed      Zded<   	  ed      Z	ded	<   	  ed
      Z
ded<   	 	 ddddddd	 	 	 	 	 	 	 	 	 	 	 d fdZddZddZd ZddZedd       Zedd       ZddZ xZS )Headerz$A header widget with icon and clock.z
    Header {
        dock: top;
        width: 100%;
        background: $panel;
        color: $foreground;
        height: 1;
    }
    Header.-tall {
        height: 3;
    }
    r1   FzReactive[bool]tallr   r5   r"   r4   r6   N)r:   idclassesr"   r6   c               ^    t         |   |||       || _        ||| _        ||| _        yy)a  Initialise the header widget.

        Args:
            show_clock: ``True`` if the clock should be shown on the right of the header.
            name: The name of the header widget.
            id: The ID of the header widget in the DOM.
            classes: The CSS classes of the header widget.
            icon: Single character to use as an icon, or `None` for default.
            time_format: Time format (used by strftime) for clock, or `None` for default.
        )r:   rJ   rK   N)super__init___show_clockr"   r6   )r   
show_clockr:   rJ   rK   r"   r6   	__class__s          r   rN   zHeader.__init__   sA    ( 	dr7;%DI"*D #r   c              #     K   t               j                  t        j                         t	                | j
                  r*t               j                  t        j                         y t                y wN)	r   	data_bindrH   r"   rF   rO   r3   r6   r/   r   s    r   composezHeader.compose   sZ     l$$V[[11m  M##F$6$67	
 "#	
s   A9A;c                (    | j                  |d       y Nz-tall)	set_class)r   rI   s     r   
watch_tallzHeader.watch_tall   s    tW%r   c                &    | j                  d       y rW   )toggle_classr   s    r   	_on_clickzHeader._on_click   s    '"r   c                b    | j                   j                  | j                  | j                        S )a  Format the title and subtitle.

        Defers to [App.format_title][textual.app.App.format_title] by default.
        Override this method if you want to customize how the title is displayed in the header.

        Returns:
            Content for title display.
        )r   format_titlescreen_titlescreen_sub_titler   s    r   r^   zHeader.format_title   s'     xx$$T%6%68M8MNNr   c                j    | j                   j                  }||}|S | j                  j                  }|S )zThe title that this header will display.

        This depends on [`Screen.title`][textual.screen.Screen.title] and [`App.title`][textual.app.App.title].
        )screentitler   )r   r_   rc   s      r   r_   zHeader.screen_title   s7     {{(( , 8 ?Chhnnr   c                j    | j                   j                  }||}|S | j                  j                  }|S )zThe sub-title that this header will display.

        This depends on [`Screen.sub_title`][textual.screen.Screen.sub_title] and [`App.sub_title`][textual.app.App.sub_title].
        )rb   	sub_titler   )r   r`   re   s      r   r`   zHeader.screen_sub_title   sH      ;;00 0 < 	  CG((BTBT 	 r   c                     d fd} j                   j                  d|        j                   j                  d|        j                   j                  d|        j                   j                  d|       y )Nc                    K   	  j                  t              j                   j                                y # t        $ r Y y w xY wwrS   )	query_onerF   updater^   r	   r   s   r   	set_titlez#Header._on_mount.<locals>.set_title   s=     {+2243D3D3FG s%   A28 A	AAAArc   re   r$   )watchr   rb   )r   r=   rj   s   `  r   r>   zHeader._on_mount   sZ    	 	

488Wi0

488[)4

4;;3

4;;Y7r   )F)rP   boolr:   
str | NonerJ   rm   rK   rm   r"   rm   r6   rm   )r%   r   )rI   rl   r%   r&   )r%   r   )r%   strrC   )r(   r)   r*   r+   r,   DEFAULT_CLASSESr   rI   rD   r"   r6   rN   rU   rY   r\   r^   propertyr_   r`   r>   __classcell__)rQ   s   @r   rH   rH   t   s    .K O#E?D.*P"5/D-)3!)$K/# !+  ""&++ 	+
 + + +  +6
&#	O   	 	
8r   rH   N)r+   
__future__r   r   	rich.textr   textual.appr   r   textual.contentr   textual.domr	   textual.eventsr
   r   textual.reactiver   textual.widgetr   textual.widgetsr   r   r/   r3   rF   rH   r-   r   r   <module>r{      sh    3 "   3 #   ' % ! "$ $Nv (F" F4
& 
p8V p8r   