
    AHj                        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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  G d ded      Zy)    )annotations)TYPE_CHECKINGClassVar)RenderableType)RenderResult)Self)BindingBindingType)Click)Size)Message)reactive)ScrollBarRender)Widgetc                      e Zd ZU dZ edddd      gZded<   	 d	hZd
ed<   	 dZ e	dd      Z
ded<   	  e	d      Z	  G d de      Z	 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d(dZ xZS ))Switcha  A switch widget that represents a boolean value.

    Can be toggled by clicking on it or through its [bindings][textual.widgets.Switch.BINDINGS].

    The switch widget also contains [component classes][textual.widgets.Switch.COMPONENT_CLASSES]
    that enable more customization.
    zenter,spacetoggle_switchToggleF)showzClassVar[list[BindingType]]BINDINGSswitch--sliderzClassVar[set[str]]COMPONENT_CLASSESav  
    Switch {
        border: tall $border-blurred;
        background: $surface;
        height: auto;
        width: auto;
        
        padding: 0 2;
        &.-on .switch--slider {
            color: $success;
        }
        & .switch--slider {
            color: $panel;
            background: $panel-darken-2;
        }
        &:hover {
            & > .switch--slider {
                color: $panel-lighten-1
            }
            &.-on > .switch--slider {
                color: $success-lighten-1;
            }
        }
        &:focus {
            border: tall $border;
            background-tint: $foreground 5%;
        }

        &:light {
            &.-on .switch--slider {
                color: $success;
            }
            & .switch--slider {
                color: $primary 15%;
                background: $panel-darken-2;
            }
            &:hover {
                & > .switch--slider {
                    color: $primary 25%;
                }
                &.-on > .switch--slider {
                    color: $success-lighten-1;
                }
            }
        }
    }

    )initzreactive[bool]value        c                  6     e Zd ZdZd fdZedd       Z xZS )Switch.Changeda8  Posted when the status of the switch changes.

        Can be handled using `on_switch_changed` in a subclass of `Switch`
        or in a parent widget in the DOM.

        Attributes:
            value: The value that the switch was changed to.
            switch: The `Switch` widget that was changed.
        c                >    t         |           || _        || _        y )N)super__init__r   switch)selfr!   r   	__class__s      O/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/widgets/_switch.pyr    zSwitch.Changed.__init__q   s    G$DJ"(DK    c                    | j                   S )zAlias for self.switch.)r!   r"   s    r$   controlzSwitch.Changed.controlv   s     ;;r%   )r!   r   r   boolreturnNone)r*   r   )__name__
__module____qualname____doc__r    propertyr(   __classcell__r#   s   @r$   Changedr   f   s!    		)
 
	 
	r%   r3   TN)animatenameidclassesdisabledtooltipc                   t         |   ||||       |r'd| _        | j                  t        j
                  |       || _        ||| _        yy)a  Initialise the switch.

        Args:
            value: The initial value of the switch.
            animate: True if the switch should animate when toggled.
            name: The name of the switch.
            id: The ID of the switch in the DOM.
            classes: The CSS classes of the switch.
            disabled: Whether the switch is disabled or not.
            tooltip: Optional tooltip.
        )r5   r6   r7   r8         ?N)r   r    _slider_positionset_reactiver   r   _should_animater9   )	r"   r   r4   r5   r6   r7   r8   r9   r#   s	           r$   r    zSwitch.__init__{   sT    , 	dr7XN$'D!fllE2&"DL r%   c                    |rdnd}| j                   r| j                  d|dd       n|| _        | j                  | j	                  | | j
                               y )Nr;   r   r<   g333333?basic)durationlevel)r>   r4   r<   post_messager3   r   )r"   r   target_slider_positions      r$   watch_valuezSwitch.watch_value   sY    (-3LL"&	   %;D!$,,tTZZ89r%   c                .    | j                  |dk(  d       y )N   z-on)	set_class)r"   slider_positions     r$   watch__slider_positionzSwitch.watch__slider_position   s    !+U3r%   c                ^    | j                  d      }t        dd| j                  dz  |d      S )Nr   d   2   F)virtual_sizewindow_sizepositionstylevertical)get_component_rich_styler   r<   )r"   rQ   s     r$   renderzSwitch.render   s:    --.>?**R/
 	
r%   c                     y)N    )r"   	containerviewports      r$   get_content_widthzSwitch.get_content_width       r%   c                     y)NrG   rW   )r"   rX   rY   widths       r$   get_content_heightzSwitch.get_content_height   r[   r%   c                L   K   |j                          | j                          ywzToggle the state of the switch.N)stoptoggle)r"   events     r$   	_on_clickzSwitch._on_click   s     

s   "$c                $    | j                          yr`   )rb   r'   s    r$   action_toggle_switchzSwitch.action_toggle_switch   s    r%   c                *    | j                    | _         | S )zToggle the switch value.

        As a result of the value changing, a `Switch.Changed` message will
        be posted.

        Returns:
            The `Switch` instance.
        )r   r'   s    r$   rb   zSwitch.toggle   s     ^
r%   )F)r   r)   r4   r)   r5   
str | Noner6   rh   r7   rh   r8   r)   r9   zRenderableType | None)r   r)   r*   r+   )rI   floatr*   r+   )r*   r   )rX   r   rY   r   r*   int)rX   r   rY   r   r]   rj   r*   rj   )rc   r   r*   r+   )r*   r+   )r*   r   )r,   r-   r.   r/   r	   r   __annotations__r   DEFAULT_CSSr   r   r<   r   r3   r    rE   rJ   rT   rZ   r^   rd   rf   rb   r1   r2   s   @r$   r   r      s    	uE-H)  	-) /Kb %U7E>7E}%' . # ")-## 	#
 # # # # '#<:4


r%   r   T)	can_focusN)
__future__r   typingr   r   rich.consoler   textual.appr   typing_extensionsr   textual.bindingr	   r
   textual.eventsr   textual.geometryr   textual.messager   textual.reactiver   textual.scrollbarr   textual.widgetr   r   rW   r%   r$   <module>rz      s<    " * '(& 0   ! # % - !xVt xr%   