o
    e~#g@                     @  s   d Z ddlmZ ddl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 ddlmZ dd	lmZ dd
lmZ ddlmZ e
rHddlmZ e G dd deZdS )zgr.UploadButton() component.    )annotationsN)CallableSequence)Path)TYPE_CHECKINGLiteralhandle_file)document)	Component)FileData)Events)Timerc                      s   e Zd ZdZejgZ		d2ddddddddddddddd3 fd!d"Zd4d&d'Zd5d)d*Z	d6d,d-Z
d7d.d/Zed0d1 Z  ZS )8DownloadButtonz
    Creates a button, that when clicked, allows a user to download a single file of arbitrary type.

    Demos: upload_and_download
    DownloadN	secondaryT)everyinputsvariantvisiblesizeiconscale	min_widthinteractiveelem_idelem_classesrenderkeylabelstrvaluestr | Path | Callable | Noner   Timer | float | Noner   7Component | Sequence[Component] | set[Component] | Noner   'Literal['primary', 'secondary', 'stop']r   boolr   Literal['sm', 'lg'] | Noner   
str | Noner   
int | Noner   r   r   r   list[str] | str | Noner   r   int | str | Nonec                  sL   t | _|| _|| _|| _t j||||||||||	|
|d | || _dS )a  
        Parameters:
            label: Text to display on the button. Defaults to "Download".
            value: A str or pathlib.Path filepath or URL to download, or a Callable that returns a str or pathlib.Path filepath or URL to download.
            every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            variant: 'primary' for main call-to-action, 'secondary' for a more subdued style, 'stop' for a stop button.
            visible: If False, component will be hidden.
            size: Size of the button. Can be "sm" or "lg".
            icon: URL or path to the icon file to display within the button. If None, no icon will be displayed.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            interactive: If False, the UploadButton will be in a disabled state.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
        )r   r   r   r   r   r   r   r   r!   r   r   r   N)	r   
data_modelr   r   r   super__init__serve_static_filer   )selfr   r!   r   r   r   r   r   r   r   r   r   r   r   r   r   	__class__ /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/gradio/components/download_button.pyr.      s&   %zDownloadButton.__init__payloadFileData | Nonereturnc                 C  s,   |du rdS |j }tjd| jd}||_|S )z
        Parameters:
            payload: File information as a FileData object,
        Returns:
            (Rarely used) passes the file as a `str` into the function.
        NF)deletedir)pathtempfileNamedTemporaryFileGRADIO_CACHEname)r0   r5   	file_namefiler3   r3   r4   
preprocessX   s   zDownloadButton.preprocessstr | Path | Nonec                 C  s"   |du rdS t t|t|jdS )z
        Parameters:
            value: Expects a `str` or `pathlib.Path` filepath
        Returns:
            File information as a FileData object
        N)r:   	orig_name)r   r    r   r>   )r0   r!   r3   r3   r4   postprocessf   s   zDownloadButton.postprocessdictc                 C  s   t dS NzMhttps://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdfr   r0   r3   r3   r4   example_payloadq   s   zDownloadButton.example_payloadc                 C     dS rF   r3   rG   r3   r3   r4   example_valuev   s   zDownloadButton.example_valuec                 C  rI   )NFr3   rG   r3   r3   r4   skip_apiy   s   zDownloadButton.skip_api)r   N)r   r    r!   r"   r   r#   r   r$   r   r%   r   r&   r   r'   r   r(   r   r)   r   r)   r   r&   r   r(   r   r*   r   r&   r   r+   )r5   r6   r7   r(   )r!   rB   r7   r6   )r7   rE   )r7   r    )__name__
__module____qualname____doc__r   clickEVENTSr.   rA   rD   rH   rJ   propertyrK   __classcell__r3   r3   r1   r4   r      s4    
9


r   )rO   
__future__r   r;   collections.abcr   r   pathlibr   typingr   r   gradio_clientr	   gradio_client.documentationr
   gradio.components.baser   gradio.data_classesr   gradio.eventsr   gradio.componentsr   r   r3   r3   r3   r4   <module>   s    