
    wi                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZ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           G d de                      ZdS )zYPredefined buttons with bound events that can be included in a gr.Blocks for convenience.    )annotationsN)Sequence)Path)TYPE_CHECKINGAnyLiteral)document)Button	Component)get_blocks_context)GradioModelGradioRootModel)resolve_singleton)Timeraddc                  |     e Zd ZdZdZ	 d3ddddddddddddddddddd	d4 fd)Zd5d,Zd6d.Zd7d/Zd8d1Z	d8d2Z
 xZS )9ClearButtonaH  
    Button that clears the value of a component or a list of components when clicked. It is instantiated with the list of components to clear.
    Preprocessing: passes the button value as a {str} into the function
    Postprocessing: expects a {str} to be returned from a function, which is set as the label of the button
    TNClear	secondarylgvalueF)r   everyinputsvariantsizeiconlinkvisibleinteractiveelem_idelem_classesrenderkeypreserved_by_keyscale	min_widthapi_nameshow_api
components&None | Sequence[Component] | Componentstrr   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   'Literal['primary', 'secondary', 'stop']r   Literal['sm', 'md', 'lg']r   str | Path | Noner   
str | Noner   boolr   r    r!   list[str] | str | Noner"   r#   (int | str | tuple[int | str, ...] | Noner$   r%   
int | Noner&   r'   str | None | Literal['False']r(   c                   t                                          ||||||||	|
|||||||           || _        || _        t	                      r|                     |           d S d S )N)r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )super__init__r'   r(   r   r   )selfr)   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   	__class__s                       n/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/gradio/components/clear_button.pyr9   zClearButton.__init__    s    . 	#%-! 	 	
 	
 	
$ !  	!HHZ     	! 	!    &None | Component | Sequence[Component]returnc                   ddl m} |s| S t          |t                    r|g}g }g }g |D ]}t          ||          rA|                    |                               t          j        |j                             |                    d          }t          |t          t          f          r|                                }|                    |           t          j        |          }|                     dg |d| | j        | j                   |r'|                     fdd|| j        | j                   | S )z
        Adds a component or list of components to the list of components that will be cleared when the button is clicked.
        r   )StateNz() => )jsr'   r(   c                 F    t          j        t                               S N)copydeepcopyr   )initial_statess   r<   <lambda>z!ClearButton.add.<locals>.<lambda>s   s    &7&G&GHH r=   )r'   r(   )gradio.componentsrA   
isinstancer   appendrE   rF   r   postprocessr   r   
model_dumpjsondumpsclickr'   r(   )	r:   r)   rA   none_valuesstate_components	componentnoneclear_valuesrG   s	           @r<   r   zClearButton.addO   s    	,+++++ 	 Kj),, 	&$J# 	% 	%I)U++ F ''	222%%dmIO&D&DEEE((..D$o >?? )((t$$$$z+..

&&&]] 	 	
 	
 	
  	JJHHHH      r=   payloadc                    |S )z
        Parameters:
            payload: string corresponding to the button label
        Returns:
            (Rarely used) the `str` corresponding to the button label when the button is clicked
         )r:   rV   s     r<   
preprocesszClearButton.preprocess{   s	     r=   c                    |S )z
        Parameters:
            value: string corresponding to the button label
        Returns:
            Expects a `str` value that is set as the button label
        rX   )r:   r   s     r<   rL   zClearButton.postprocess   s	     r=   r   c                    dS Nr   rX   r:   s    r<   example_payloadzClearButton.example_payload       wr=   c                    dS r\   rX   r]   s    r<   example_valuezClearButton.example_value   r_   r=   rD   )&r)   r*   r   r+   r   r,   r   r-   r   r.   r   r/   r   r0   r   r1   r   r2   r   r2   r    r1   r!   r3   r"   r2   r#   r4   r$   r3   r%   r5   r&   r5   r'   r6   r(   r2   )r)   r>   r?   r   )rV   r1   r?   r1   )r   r1   r?   r1   )r?   r   )__name__
__module____qualname____doc__is_templater9   r   rY   rL   r^   ra   __classcell__)r;   s   @r<   r   r      s         K >B-! &*JN;F*."& "/38<3:  $26+-! -! -! -! -! -! -! -!^* * * *X                r=   r   )re   
__future__r   rE   rN   collections.abcr   pathlibr   typingr   r   r   gradio_client.documentationr	   rI   r
   r   gradio.contextr   gradio.data_classesr   r   gradio.utilsr   r   r   rX   r=   r<   <module>rp      sC   _ _ " " " " " "   $ $ $ $ $ $       . . . . . . . . . . 0 0 0 0 0 0 / / / / / / / / - - - - - - < < < < < < < < * * * * * * ('''''' 
%z z z z z& z z z z zr=   