
    AHj                        d 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lmZ ddlmZmZ dd	lmZmZ dd
lmZ  G d ded      Z G d ded      Z G d ded      Zy)z4Widgets for showing notification messages in toasts.    )annotations)ClassVar)on)	Container)Content)	NoMatches)ClickMount)NotificationNotifications)Staticc                      e Zd ZdZdZy)ToastHolderzContainer that holds a single toast.

    Used to control the alignment of each of the toasts in the main toast
    container.
    z
    ToastHolder {
        align-horizontal: right;
        width: 1fr;
        height: auto;
        visibility: hidden;        
    }
    N)__name__
__module____qualname____doc__DEFAULT_CSS     N/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_toast.pyr   r      s    Kr   r   F)inherit_cssc                  n     e Zd ZU dZdZdhZded<   	 dZd fdZddZ	dd	Z
 ee      dd
       Z xZS )Toastz2A widget for displaying short-lived notifications.a  
    Toast {
        width: 60;
        max-width: 50%;
        height: auto;
        margin-top: 1;
        visibility: visible;        
        padding: 1 1;
        background: $panel-lighten-1;
        link-background: initial;
        link-color: $foreground;
        link-style: underline;
        link-background-hover: $primary;
        link-color-hover: $foreground;
        link-style-hover: bold not underline;
    }

    .toast--title {
        text-style: bold;
        color: $foreground;
    }

    Toast.-information {
        border-left: outer $success;
    }

    Toast.-information .toast--title {
        color: $text-success;
    }

    Toast.-warning {
        border-left: outer $warning;
    }

    Toast.-warning .toast--title {
        color: $text-warning;
    }

    Toast.-error {
        border-left: outer $error;
    }

    Toast.-error .toast--title {
       color: $text-error;
    }
    toast--titlezClassVar[set[str]]COMPONENT_CLASSES-textual-systemc                p    t         |   d|j                          || _        |j                  | _        y)znInitialise the toast.

        Args:
            notification: The notification to show in the toast.
        -)classesN)super__init__severity_notification	time_left_timeout)selfnotification	__class__s     r   r"   zToast.__init__\   s8     	1\%:%:$;!<=)$..r   c                   | j                   }|j                  rt        j                  |j                        nt        |j                        }|j
                  r4| j                  d      }t        j                  |j
                  |fd|      }|S )z|Render the toast's content.

        Returns:
            A Rich renderable for the title and content of the Toast.
        r   
)r$   markupr   from_markupmessagetitleget_visual_styleassemble)r'   r(   message_contentheader_styles       r   renderzToast.renderf   s     )) ""  4 45--. 	 00@L%..##\2D/O r   c                P    | j                  | j                  | j                         y)z/Set the time running once the toast is mounted.N)	set_timerr&   _expire)r'   _s     r   	_on_mountzToast._on_mount|   s    t}}dll3r   c                    | j                   j                  | j                  d       t        | j                  t
              r| j                  j                          y| j                          y)z,Remove the toast once the timer has expired.F)refreshN)app	_unnotifyr$   
isinstanceparentr   remove)r'   s    r   r7   zToast._expire   sK     	4--u= #4;;<NNP$NNPr   )r(   r   returnNone)rA   r   )r8   r
   rA   rB   )rA   rB   )r   r   r   r   r   r   __annotations__DEFAULT_CLASSESr"   r4   r9   r   r	   r7   __classcell__)r)   s   @r   r   r   !   sT    <-K^ .<,<)< (O/,4 Y
Q 
Qr   r   c                  2    e Zd ZdZdZdZedd       ZddZy)		ToastRackzA container for holding toasts.a  
    ToastRack {
        display: none;
        layer: _toastrack;
        width: 1fr;
        height: auto;
        dock: bottom;
        align: right bottom;
        visibility: hidden;
        layout: vertical;
        overflow-y: scroll;
        margin-bottom: 1;         
    }
    r   c                     d| j                    S )zCreate a Textual-DOM-internal ID for the given notification.

        Args:
            notification: The notification to create the ID for.

        Returns:
            An ID for the notification that can be used within the DOM.
        z--textual-toast-)identity)r(   s    r   	_toast_idzToastRack._toast_id   s     ","7"7!899r   c                    t        |       _         j                  t              D ]!  }|j                  |vs|j                          # g }|D ]#  }	  j                   j                  |            }% |r9 j                   fd|D                j                   j                  dd       yy# t        $ r  |j                  s|j                  |       Y w xY w)zoShow the notifications as toasts.

        Args:
            notifications: The notifications to show.
        c              3  h   K   | ])  }t        t        |      j                  |              + yw))idN)r   r   rJ   ).0toastr'   s     r   	<genexpr>z!ToastRack.show.<locals>.<genexpr>   s0       E%LT^^E-BCCs   /2FT)animateforceN)booldisplayqueryr   r$   r@   get_child_by_idrJ   r   has_expiredappend	mount_all
call_later
scroll_end)r'   notificationsrO   
new_toastsr(   r8   s   `     r   showzToastRack.show   s     M*ZZ& 	E""-7	
 *,
) 	4L4(()EF	4 NN '  OODOOU$OG   4#//%%l34s    B11&CCN)r(   r   rA   str)r\   r   rA   rB   )	r   r   r   r   r   rD   staticmethodrJ   r^   r   r   r   rG   rG      s+    )K (O	: 	:Hr   rG   N)r   
__future__r   typingr   textualr   textual.containersr   textual.contentr   textual.css.queryr   textual.eventsr	   r
   textual.notificationsr   r   textual.widgets._staticr   r   r   rG   r   r   r   <module>rj      sT    : "   ( # ' ' = *) "jQF jQZ<H	u <Hr   