
    AHjF                        d dl mZ d dlmZmZ d dlmZmZ er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  G d	 d
e      Zy)    )annotations)TYPE_CHECKINGcast)AlignAlignMethod)RenderResult)Size)Digits)	Selection)Widgetc                       e Zd ZdZdZ	 dddddd	 	 	 	 	 	 	 	 	 	 	 d fdZedd       ZddZdd	Z	dd
Z
ddZddZ xZS )r
   zLA widget to display numerical values using a 3x3 grid of unicode characters.z
    Digits {
        width: 1fr;
        height: auto;
        text-align: left;        
        box-sizing: border-box;
    }
    NFnameidclassesdisabledc               p    t        |t              st        d      t        |   ||||       || _        y)a/  Initialize a Digits widget.

        Args:
            value: Value to display in widget.
            name: The name of the widget.
            id: The ID of the widget in the DOM.
            classes: The CSS classes of the widget.
            disabled: Whether the widget is disabled or not.

        value must be a strr   N)
isinstancestr	TypeErrorsuper__init___value)selfvaluer   r   r   r   	__class__s         O/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_digits.pyr   zDigits.__init__   s8    & %%122dr7XN    c                    | j                   S )z*The current value displayed in the Digits.r   )r   s    r   r   zDigits.value4   s     {{r   c                    | j                   S )Nr!   )r   	selections     r   get_selectionzDigits.get_selection9   s    {{r   c                   t        |t              st        d      t        |      t        | j                        k7  xs5 t        j                  | j                        t        j                  |      k7  }|| _        | j                  |       y)zUpdate the Digits with a new value.

        Args:
            value: New value to display.

        Raises:
            TypeError: If the value isn't a `str`.
        r   )layoutN)r   r   r   lenr   DigitsRenderable	get_widthrefresh)r   r   layout_requireds      r   updatezDigits.update<   st     %%122e*DKK(88 
&&t{{37G7Q7QRW7XX 	 O,r   c                    | j                   }| j                  r|| j                  z  }t        | j                  |      }| j
                  j                  }|dvrdn|}t        |t        t        |      |      S )zRender digits.>   leftrightcenterr.   )

rich_styletext_selectionselection_styler(   r   styles
text_alignr   r   r   )r   r1   digitsr5   aligns        r   renderzDigits.renderM   sh    __
$...J!$++z:[[++
$,GGZVT+u5zBBr   c                @    t        j                  | j                        S )a  Called by textual to get the width of the content area.

        Args:
            container: Size of the container (immediate parent) widget.
            viewport: Size of the viewport.

        Returns:
            The optimal width of the content.
        )r(   r)   r   )r   	containerviewports      r   get_content_widthzDigits.get_content_widthW   s      ))$++66r   c                     y)a%  Called by Textual to get the height of the content area.

        Args:
            container: Size of the container (immediate parent) widget.
            viewport: Size of the viewport.
            width: Width of renderable.

        Returns:
            The height of the content.
            )r   r:   r;   widths       r   get_content_heightzDigits.get_content_heightc   s     r   ) )r   r   r   
str | Noner   rC   r   rC   r   boolreturnNone)rE   r   )r#   r   rE   rC   )r   r   rE   rF   )rE   r   )r:   r	   r;   r	   rE   int)r:   r	   r;   r	   r@   rG   rE   rG   )__name__
__module____qualname____doc__DEFAULT_CSSr   propertyr   r$   r,   r8   r<   rA   __classcell__)r   s   @r   r
   r
      s    VK   " 	
    
0  -"C
7r   r
   N)
__future__r   typingr   r   
rich.alignr   r   textual.appr   textual.geometryr	   textual.renderables.digitsr
   r(   textual.selectionr   textual.widgetr   r?   r   r   <module>rW      s.    " & )( ! A ' !^V ^r   