
    /_i'                    n   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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/m0Z0 erd dl1m2Z2 d dlm3Z3 e0e/z  dz  Z4de5d<   e G d d             Z6 G d d      Z7y)    )annotations)	dataclass)dedent)TYPE_CHECKING	TypeAliascast)enforce_filename_restriction)current_form_id)LayoutConfigvalidate_width)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)DeltaGenerator)WidthWithoutContentNr   SomeUploadedSnapshotFilec                  ,    e Zd Z	 	 	 	 ddZ	 	 	 	 ddZy)CameraInputSerdec                &   t               }|t        |t              r|S |j                  j	                         }|j
                  |_        |j                  |_        |j                  |_        |j                  j                  |j                         |S )N)FileUploaderStateProto
isinstancer   uploaded_file_infoaddfile_idnamesize	file_urlsCopyFrom
_file_urls)selfsnapshotstate_proto	file_infos       f/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/elements/widgets/camera_input.py	serializezCameraInputSerde.serialize:   sy     -.z(K@+6+I+I+M+M+O	$,,	!	!	$$X%8%89    c                    t        |      }t        |      dk(  rd n|d   }|'t        |t              st	        |j
                  dg       |S )Nr   z.jpg)r   lenr(   r   r	   r,   )r1   ui_valueupload_filesreturn_values       r5   deserializezCameraInputSerde.deserializeK   sL     )2"<0A5t<?#J|[,Q():):VHEr7   N)r2   r#   returnr'   )r:   zFileUploaderStateProto | Noner>   r#   )__name__
__module____qualname__r6   r=    r7   r5   r%   r%   8   s.    * 
 "5	!r7   r%   c                      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
       Zy)CameraInputMixincamera_inputNFvisiblestretch)disabledlabel_visibilitywidthc               L    t               }
| j                  |||||||||	|

      S )a2  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 : list or tuple
            An optional list or 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 aligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        width : "stretch" or int
            The width of the camera input widget. This can be one of the
            following:

            - ``"stretch"`` (default): The width of the widget matches the
              width of the parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        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

        )
labelkeyhelp	on_changeargskwargsrH   rI   rJ   ctx)r   _camera_input)r1   rL   rM   rN   rO   rP   rQ   rH   rI   rJ   rR   s              r5   rE   zCameraInputMixin.camera_inputV   sC    V !"!!- " 
 	
r7   )rH   rI   rJ   rR   c          
        t        |      }t        | j                  ||d d       t        ||       t	        d|d| j                  |||	      }t               }||_        ||_        t        | j                        |_	        ||_
        t        |      |j                  _        |t        |      |_        t!        |	       t#        |	      }t%               }t'        |j                  ||||j(                  |j*                  |
d      }| j                  j-                  d||	       t/        |j                  t0              ry |j                  S )
NF)default_valuewrites_allowedrE   T)user_keykey_as_main_identitydgrL   rN   rJ   )rJ   file_uploader_state_value)on_change_handlerrP   rQ   deserializer
serializerrR   
value_type)layout_config)r   r   rY   r   r   CameraInputProtoidrL   r
   form_idrH   r   rI   valuer   rN   r   r   r%   r   r=   r6   _enqueuer(   r   )r1   rL   rM   rN   rO   rP   rQ   rH   rI   rJ   rR   
element_idcamera_input_protor_   serdecamera_input_states                   r5   rS   zCameraInputMixin._camera_input   sL    SkGG 	
 	#5*:;4!%ww

 ./ *#( %4TWW%="&.#4T5
++1 &,Tl#u$51 ",!!'**2	
 	.m 	 	
 (..<!'''r7   c                    t        d|       S )zGet our DeltaGenerator.r!   )r   )r1   s    r5   rY   zCameraInputMixin.dg  s     $d++r7   )NNNNN)rL   strrM   
Key | NonerN   
str | NonerO   WidgetCallback | NonerP   WidgetArgs | NonerQ   WidgetKwargs | NonerH   boolrI   r   rJ   r"   r>   UploadedFile | None)rL   rj   rM   rk   rN   rl   rO   rm   rP   rn   rQ   ro   rH   rp   rI   r   rJ   r"   rR   zScriptRunContext | Noner>   rq   )r>   r!   )r?   r@   rA   r   rE   rS   propertyrY   rB   r7   r5   rD   rD   U   sa   N# +/"&&*v
 ,5%.v
v
 v
 	v

 )v
  v
 $v
 v
 *v
 #v
 
v
 $v
v +/"&&*E( ,5%.'+E(E( E( 	E(
 )E(  E( $E( E( *E( #E( %E( 
E(N , ,r7   rD   )8
__future__r   dataclassesr   textwrapr   typingr   r   r   *streamlit.elements.lib.file_uploader_utilsr	   !streamlit.elements.lib.form_utilsr
   #streamlit.elements.lib.layout_utilsr   r   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"   r#   __annotations__r%   rD   rB   r7   r5   <module>r      s    # !  1 1 S = L  G K R P 9 O  N8G&2[&@4&G ) G   8D, D,r7   