
    AHj#                       U 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
mZ ddlmZ er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 erddlmZ e
d   Z	 g dZded<    ee      Zded<   g dZdZ  G d de!      Z" G d de      Z#y)zMProvides a Textual placeholder widget; useful when designing an app's layout.    )annotations)cycle)TYPE_CHECKING)WeakKeyDictionary)LiteralSelf)events)RenderResult)NoActiveAppError)friendly_list)Reactivereactive)Widget)Appdefaultsizetextzlist[PlaceholderVariant]#_VALID_PLACEHOLDER_VARIANTS_ORDEREDzset[PlaceholderVariant]_VALID_PLACEHOLDER_VARIANTS)z#881177z#aa3355z#cc6666z#ee9944z#eedd00z#99dd55z#44dd88z#22ccbbz#00bbccz#0099ccz#3366bbz#663399a  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam feugiat ac elit sit amet accumsan. Suspendisse bibendum nec libero quis gravida. Phasellus id eleifend ligula. Nullam imperdiet sem tellus, sed vehicula nisl faucibus sit amet. Praesent iaculis tempor ultricies. Sed lacinia, tellus id rutrum lacinia, sapien sapien congue mauris, sit amet pellentesque quam quam vel nisl. Curabitur vulputate erat pellentesque mauris posuere, non dictum risus mattis.c                      e Zd ZdZy)InvalidPlaceholderVariantz2Raised when an invalid Placeholder variant is set.N)__name__
__module____qualname____doc__     T/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_placeholder.pyr   r   4   s    <r   r   c                       e Zd ZU dZdZ e       Zded<   dZ e	e
   d      Zded<   d	e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 )Placeholdera  A simple placeholder widget to use before you build your custom widgets.

    This placeholder has a couple of variants that show different data.
    Clicking the placeholder cycles through the available variants, but a placeholder
    can also be initialised in a specific variant.

    The variants available are:

    | Variant | Placeholder shows                              |
    |---------|------------------------------------------------|
    | default | Identifier label or the ID of the placeholder. |
    | size    | Size of the placeholder.                       |
    | text    | Lorem Ipsum text.                              |
    z
    Placeholder {
        content-align: center middle;
        overflow: hidden;
        color: $text;

        &:disabled {
            opacity: 0.7;
        }
    }
    Placeholder.-text {
        padding: 1;
    }
    zWeakKeyDictionary[App, int]_COLORSz[b]{} x {}[/b]r   zReactive[PlaceholderVariant]variantzdict[PlaceholderVariant, str]_renderablesNFnameidclassesdisabledc               d   |r|n|rd| ndddj                  d t        d      D              d| _        t        |   ||||       | j                  |      | _        	 	 | j                  j                  | j                  d	      d
z   | j                  | j                  <   | j                  | j                     | _
        t        t              | _        t        | j                        | j                  k7  r%	 t        | j                        | j                  k7  r$yy# t        $ r
 d| _
        Y nw xY w)a  Create a Placeholder widget.

        Args:
            label: The label to identify the placeholder.
                If no label is present, uses the placeholder ID instead.
            variant: The variant of the placeholder.
            name: The name of the placeholder.
            id: The ID of the placeholder in the DOM.
            classes: A space separated string with the CSS classes
                of the placeholder, if any.
            disabled: Whether the placeholder is disabled or not.
        #r!    z

c              3  (   K   | ]
  }t           y w)N)_LOREM_IPSUM_PLACEHOLDER_TEXT).0_s     r   	<genexpr>z'Placeholder.__init__.<locals>.<genexpr>y   s     P! = =Ps      r   r%      r   N)joinranger$   super__init__validate_variantr#   r"   
setdefaultapp_color_offsetr   r   r   _variants_cyclenext)selflabelr#   r&   r'   r(   r)   	__class__s          r   r8   zPlaceholder.__init___   s   0 !&urQrd8}KKPuQxPP
 	dr7XN,,W55	#%)\\%<%<TXXr%JQ%NDLL"!%dhh!7D
  %%HI4''(DLL8 4''(DLL8   	#!"D	#s   "AD D/.D/c                ~   K   t        t              }t        | j                  |z     }| d| j                  _        yw)z#Set the color for this placeholder.z 50%N)len_PLACEHOLDER_BACKGROUND_COLORSr<   styles
background)r?   eventcolor_countcolors       r   _on_composezPlaceholder._on_compose   s8     89.t/A/AK/OP$)7$s   ;=c                4    | j                   | j                     S )zSRender the placeholder.

        Returns:
            The value to render.
        )r$   r#   r?   s    r   renderzPlaceholder.render   s       ..r   c                :    t        | j                        | _        | S )zeGet the next variant in the cycle.

        Returns:
            The `Placeholder` instance.
        )r>   r=   r#   rL   s    r   cycle_variantzPlaceholder.cycle_variant   s     D001r   c                T    | j                  d|        | j                  d|        y )N-)remove_class	add_class)r?   old_variantr#   s      r   watch_variantzPlaceholder.watch_variant   s+     	Ak]+,7)}%r   c                N    |t         vrt        dt        t                z         |S )z6Validate the variant to which the placeholder was set.zValid placeholder variants are )r   r   r   )r?   r#   s     r   r9   zPlaceholder.validate_variant   s4    55+1"#>?@B  r   c                ,   K   | j                          yw)z8Click handler to cycle through the placeholder variants.N)rO   )r?   r0   s     r   	_on_clickzPlaceholder._on_click   s     s   c                     | j                   j                  |j                   | j                  d<   | j                  dk(  r| j                          yy)zDUpdate the placeholder "size" variant with the new placeholder size.r   N)_SIZE_RENDER_TEMPLATEformatr   r$   r#   refresh)r?   rG   s     r   
_on_resizezPlaceholder._on_resize   sC    $ED$>$>$E$Euzz$R&!<<6!LLN "r   )Nr   )r@   
str | Noner#   PlaceholderVariantr&   r^   r'   r^   r(   r^   r)   boolreturnNone)rG   zevents.Composera   rb   )ra   r
   )ra   r   )rT   r_   r#   r_   ra   rb   )r#   r_   ra   r_   )r0   zevents.Clickra   rb   )rG   zevents.Resizera   rb   )r   r   r   r   DEFAULT_CSSr   r"   __annotations__rZ   r   r_   r#   r8   rJ   rM   rO   rU   r9   rX   r]   __classcell__)rA   s   @r   r!   r!   8   s    K  ,=+>G(>,,HH5G,H,SG)S// !&/+
  "++ $+
 + + + + 
+Z0/&-&8J&	&r   r!   N)$r   
__future__r   	itertoolsr   typingr   weakrefr   typing_extensionsr   r   textualr	   textual.appr
   textual._contextr   textual.css._error_toolsr   textual.reactiver   r   textual.widgetr   r   r_   r   rd   setr   rD   r.   	Exceptionr   r!   r   r   r   <module>rs      s    S "    % + ( - 2 / !67  ,A #%= 
 8;'8 4 "  !r =	 =B& Br   