o
    hi$                     @  sH  U d dl m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 d dlmZ d dlmZmZ d d	lmZmZmZ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&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, d dl-m.Z.m/Z/ erd dl0m1Z1 ee/e.df Z2de3d< eG dd dZ4G dd dZ5dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGUnioncast)	TypeAlias)enforce_filename_restriction)current_form_id)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)_get_upload_files)CameraInput)FileUploaderState)UploadedFileInfo)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)DeletedFileUploadedFile)DeltaGeneratorNr   SomeUploadedSnapshotFilec                   @  s    e Zd ZdddZdddZdS )CameraInputSerdesnapshotr    returnFileUploaderStateProtoc                 C  sP   t  }|d u st|tr|S |j }|j|_|j|_|j|_|j	|j
 |S )N)r$   
isinstancer   uploaded_file_infoaddfile_idnamesize	file_urlsCopyFrom
_file_urls)selfr"   state_proto	file_info r1   [/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/widgets/camera_input.py	serialize:   s   
zCameraInputSerde.serializeui_valueFileUploaderStateProto | None	widget_idstrc                 C  sF   t |}t|dkrd }n|d }|d ur!t|ts!t|jdg |S )Nr   z.jpg)r   lenr%   r   r	   r)   )r.   r4   r6   upload_filesreturn_valuer1   r1   r2   deserializeK   s   zCameraInputSerde.deserializeN)r"   r    r#   r$   )r4   r5   r6   r7   r#   r    )__name__
__module____qualname__r3   r;   r1   r1   r1   r2   r!   8   s    
r!   c                   @  s`   e Zd Zed					d"dddd#ddZ					d"ddddd$ddZed%d d!ZdS )&CameraInputMixincamera_inputNFvisible)disabledlabel_visibilitylabelr7   key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerB   boolrC   r   r#   UploadedFile | Nonec          
      C  s"   t  }	| j|||||||||	d	S )a  Display a widget that returns pictures from the user's webcam.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this widget is used for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this camera_input's value
            changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        disabled : bool
            An optional boolean that disables the camera input if set to
            ``True``. Default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        Returns
        -------
        None or UploadedFile
            The UploadedFile class is a subclass of BytesIO, and therefore is
            "file-like". This means you can pass an instance of it anywhere a
            file is expected.

        Examples
        --------
        >>> import streamlit as st
        >>>
        >>> enable = st.checkbox("Enable camera")
        >>> picture = st.camera_input("Take a picture", disabled=not enable)
        >>>
        >>> if picture:
        ...     st.image(picture)

        .. output::
           https://doc-camera-input.streamlit.app/
           height: 600px

        )	rD   rE   rG   rI   rK   rM   rB   rC   ctx)r   _camera_input)
r.   rD   rE   rG   rI   rK   rM   rB   rC   rQ   r1   r1   r2   r@   Y   s   _zCameraInputMixin.camera_input)rB   rC   rQ   rQ   ScriptRunContext | Nonec             
   C  s   t |}t| j||d dd t|| td|t| j||d}
t }|
|_||_t| j|_	||_
t||j_|d ur@t||_t }t|j||||j|j|	dd}| jd| t|jtrad S |jS )NF)default_valuewrites_allowedr@   )user_keyform_idrD   rG   file_uploader_state_value)on_change_handlerrK   rM   deserializer
serializerrQ   
value_type)r   r   dgr   r   r
   CameraInputProtoidrD   rW   rB   r   rC   valuer   rG   r!   r   r;   r3   _enqueuer%   r   )r.   rD   rE   rG   rI   rK   rM   rB   rC   rQ   
element_idcamera_input_protoserdecamera_input_stater1   r1   r2   rR      sR   

zCameraInputMixin._camera_inputr   c                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r.   r1   r1   r2   r]     s   
zCameraInputMixin.dg)NNNNN)rD   r7   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rB   rO   rC   r   r#   rP   )rD   r7   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rB   rO   rC   r   rQ   rS   r#   rP   )r#   r   )r<   r=   r>   r   r@   rR   propertyr]   r1   r1   r1   r2   r?   X   s.    	n	?r?   )6
__future__r   dataclassesr   textwrapr   typingr   r   r   typing_extensionsr   *streamlit.elements.lib.file_uploader_utilsr	   !streamlit.elements.lib.form_utilsr
   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   (streamlit.elements.widgets.file_uploaderr   streamlit.proto.CameraInput_pb2r   r^   streamlit.proto.Common_pb2r   r$   r   UploadedFileInfoProtostreamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   'streamlit.runtime.uploaded_file_managerr   r   streamlit.delta_generatorr   r    __annotations__r!   r?   r1   r1   r1   r2   <module>   s.   