o
    ,&]iX                     @  s  U 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mZmZmZmZmZmZ ddlmZmZmZmZ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" 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. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZC ddlDmEZEmFZFmGZGmHZH ddlImJZJ ddlKmLZL ddlMmNZN dd lOmPZP dd!lQmRZR dd"lSmTZT dd#lUmVZV dd$lWmXZX dd%lYmZZZ dd&l[m\Z\ dd'l]m^Z^ dd(l_m`Z` dd)lambZb dd*lcmdZd dd+lemfZf dd,lgmhZh dd-limjZj dd.lkmlZl dd/lmmnZn dd0lompZp dd1lqmrZr dd2lsmtZt dd3lumvZv dd4lwmxZx dd5lymzZz dd6l{m|Z| dd7l}m~Z~ dd8lmZ dd9lmZ dd:lmZ dd;lmZ dd<lmZ dd=lmZmZ dd>lmZ dd?lmZ dd@lmZ ddAlmZ e
rddBlmZ ddClmZ ddDlmZ ddElmZ ddFlDmZ dGZdHedI< edJZeZdKedL< ee ZdKedM< dNadOedP< d\dSdTZd\dUdVZG dWdX dXge ede$e&efehejelene(epe.e0ete2e4e6e,e8e:e<e@eLeJeNePevexeReTeVe*eXeze~e|eeZe\e>e^eee`ee"ebereR  Zd]dZd[ZdS )^z@Allows us to create and absorb changes (aka Deltas) to elements.    )annotationsN)CallableIterable)deepcopy)TYPE_CHECKINGAnyFinalLiteralNoReturn	TypeAliasTypeVarcast)cli_utilconfigcursorenv_utilloggerruntimeutil)BidiComponentMixin)context_dg_stack"get_last_dg_added_to_context_stack)
AlertMixin)
ArrowMixin)BalloonsMixin)
BokehMixin)	CodeMixin)PydeckMixin)	HelpMixin)
EmptyMixin)ExceptionMixin)	FormMixin)GraphvizMixin)HeadingMixin)	HtmlMixin)IframeMixin)
ImageMixin)	JsonMixin)LayoutsMixin)FormDatacurrent_form_id)get_height_configget_text_alignment_configget_width_configvalidate_text_alignment)MapMixin)MarkdownMixin)
MediaMixin)MetricMixin)PdfMixin)PlotlyMixin)ProgressMixin)PyplotMixin)	SnowMixin)
SpaceMixin)	TextMixin)
ToastMixin)VegaChartsMixin)AudioInputMixin)ButtonMixin)ButtonGroupMixin)CameraInputMixin)	ChatMixin)CheckboxMixin)ColorPickerMixin)DataEditorMixin)FileUploaderMixin)MultiSelectMixin)NumberInputMixin)
RadioMixin)SelectSliderMixin)SelectboxMixin)SliderMixin)TextWidgetsMixin)TimeWidgetsMixin)
WriteMixin)StreamlitAPIException)	Block_pb2ForwardMsg_pb2)RootContainer)caching)enqueue_message)get_script_run_ctx)TracebackType)Message)Cursor)AddRowsMetadata)LayoutConfigi   z
Final[int]MAX_DELTA_BYTESValuer   	BlockTypeAncestorBlockTypesFbool_use_warning_has_been_displayedreturnNonec                  C  s   t s=da tjdddd} t rtdd|  d dS t	 s?t
drAtjd	 }tdd|  d
| d dS dS dS dS )zPrint a warning if Streamlit is imported but not being run with `streamlit run`.
    The warning is printed only once, and is printed using the root logger.
    TWarning:yellowboldfgroot
  z to view a Streamlit app on a browser, use Streamlit in a file and
  run it with the following command:

    streamlit run [FILE_NAME] [ARGUMENTS]z#global.showWarningOnDirectExecutionr   zb to view this Streamlit app on a browser, run it with the following
  command:

    streamlit run z [ARGUMENTS]N)r_   r   style_for_clir   is_replr   
get_loggerwarningr   existsr   
get_optionsysargv)rl   script_name rr   W/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/delta_generator.py_maybe_print_use_warning   s$   



rt   c                  C  sJ   t  } | r!t| ddr#tjdddd}tdd| d	 d
S d
S d
S )zJPrint a warning if elements are being modified during a fragment callback.in_fragment_callbackFrb   Trc   rd   rg   rh   a   A fragment rerun was triggered with a callback that displays one or more elements. During a fragment rerun, within a callback, displaying elements is not officially supported because those elements will replace the existing elements at the top of your app.N)rT   getattrr   ri   r   rk   rl   )ctxrl   rr   rr   rs   &_maybe_print_fragment_callback_warning   s   

rx   c                   @  s   e Zd ZdZejdddfdKddZdLddZdMddZdNddZ	e
dOddZe
dOdd ZdPd#d$ZdQd'd(Ze
dRd*d+Ze
dSd-d.ZdTd1d2Ze
dUd3d4Ze
dVd6d7Ze
dLd8d9ZdLd:d;Z		dWdXdCdDZ		dWdYdIdJZdS )ZDeltaGeneratoraG  Creator of Delta protobuf messages.

    Parameters
    ----------
    root_container: BlockPath_pb2.BlockPath.ContainerValue or None
      The root container for this DeltaGenerator. If None, this is a null
      DeltaGenerator which doesn't print to the app at all (useful for
      testing).

    cursor: cursor.Cursor or None
      This is either:
      - None: if this is the running DeltaGenerator for a top-level
        container (MAIN or SIDEBAR)
      - RunningCursor: if this is the running DeltaGenerator for a
        non-top-level container (created with dg.container())
      - LockedCursor: if this is a locked DeltaGenerator returned by some
        other DeltaGenerator method. E.g. the dg returned in dg =
        st.text("foo").

    parent: DeltaGenerator
      To support the `with dg` notation, DGs are arranged as a tree. Each DG
      remembers its own parent, and the root of the tree is the main DG.

    block_type: None or "vertical" or "horizontal" or "column" or "expandable"
      If this is a block DG, we track its type to prevent nested columns/expanders

    Nroot_container
int | Noner   Cursor | NoneparentDeltaGenerator | None
block_type
str | Noner`   ra   c                 C  sr   |dur|dur||j krtd|| _|| _|| _|| _d| _| jjD ]}|j	
 D ]
}t|r5| j|_q+q$dS )am  Inserts or updates elements in Streamlit apps.

        As a user, you should never initialize this object by hand. Instead,
        DeltaGenerator objects are initialized for you in two places:

        1) When you call `dg = st.foo()` for some method "foo", sometimes `dg`
        is a DeltaGenerator object. You can call methods on the `dg` object to
        update the element `foo` that appears in the Streamlit app.

        2) This is an internal detail, but `st.sidebar` itself is a
        DeltaGenerator. That's why you can call `st.sidebar.foo()` to place
        an element `foo` inside the sidebar.

        NzHDeltaGenerator root_container and cursor.root_container must be the same)rz   RuntimeError_root_container_provided_cursor_parent_block_type
_form_data	__class__	__bases____dict__valuescallable
__module__)selfrz   r   r}   r   mixinfuncrr   rr   rs   __init__   s$   
zDeltaGenerator.__init__strc                 C  s
   t | S N)r   repr_r   rr   rr   rs   __repr__4  s   
zDeltaGenerator.__repr__c                 C  s   t g t  | R  d S r   r   setgetr   rr   rr   rs   	__enter__7  s   zDeltaGenerator.__enter__typtype[BaseException] | NoneexcBaseException | NonetbTracebackType | NoneLiteral[False]c                 C  s   t t  d d  dS )NFr   )r   r   r   r   rr   rr   rs   __exit__;  s   zDeltaGenerator.__exit__c                 C  s    | | j krt }|dur|S | S )zReturn the DeltaGenerator that's currently 'active'.
        If we are the main DeltaGenerator, and are inside a `with` block that
        creates a container, our active_dg is that container. Otherwise,
        our active_dg is self.
        N)_main_dgr   )r   last_context_stack_dgrr   rr   rs   
_active_dgH  s
   
zDeltaGenerator._active_dgc                 C  s   | j r| j jS | S )zReturn this DeltaGenerator's root - that is, the top-level ancestor
        DeltaGenerator that we belong to (this generally means the st._main
        DeltaGenerator).
        )r   r   r   rr   rr   rs   r   Z  s   zDeltaGenerator._main_dgnameCallable[..., NoReturn]c                   s4   dd l fddtD d fd	d
}|S )Nr   c                   s   g | ]}t t |r|qS rr   )r   rv   ).0method_name)strr   rs   
<listcomp>e  s
    z.DeltaGenerator.__getattr__.<locals>.<listcomp>argsr   kwargsr`   r
   c                    s\    v r$j tjkrd  d  d}t|d  d  d}t|d  d}t|)NzMethod `z6()` does not exist for `st.sidebar`. Did you mean `st.z()`?zB()` does not exist for `DeltaGenerator` objects. Did you mean `st.`z%()` is not a valid Streamlit command.)r   rQ   SIDEBARrN   )r   r   message)r   r   streamlit_methodsrr   rs   wrapperi  s   z+DeltaGenerator.__getattr__.<locals>.wrapper)r   r   r   r   r`   r
   )	streamlitdir)r   r   r   rr   )r   r   r   r   rs   __getattr__b  s   
zDeltaGenerator.__getattr___memor   c                 C  s0   t | jt| jt| j| jd}t| j|_|S )Nrz   r   r}   r   )ry   r   r   _cursorr   r   r   )r   r   dgrr   rr   rs   __deepcopy__}  s   zDeltaGenerator.__deepcopy__Iterable[DeltaGenerator]c                 c  s*    | }|d ur|V  |j }|d usd S d S r   )r   )r   
current_dgrr   rr   rs   
_ancestors  s   zDeltaGenerator._ancestorsr]   c                 c  s$    | j D ]}|jdur|jV  qdS )znIterate all the block types used by this DeltaGenerator and all
        its ancestor DeltaGenerators.
        N)r   r   )r   arr   rr   rs   _ancestor_block_types  s   

z$DeltaGenerator._ancestor_block_typesancestor_block_typesintc                 C  s   t dd |D S )Nc                 s  s    | ]	}|d krdV  qdS )column   Nrr   )r   ancestor_blockrr   rr   rs   	<genexpr>  s    z>DeltaGenerator._count_num_of_parent_columns.<locals>.<genexpr>)sum)r   r   rr   rr   rs   _count_num_of_parent_columns  s   z+DeltaGenerator._count_num_of_parent_columnsc                 C  s   | j du rt| jS | j S )zReturn our Cursor. This will be None if we're not running in a
        ScriptThread - e.g., if we're running a "bare" script outside of
        Streamlit.
        N)r   r   get_container_cursorr   r   rr   rr   rs   r     s   
zDeltaGenerator._cursorr^   c                 C  s
   | j d u S r   )r   r   rr   rr   rs   _is_top_level  s   
zDeltaGenerator._is_top_levelc                 C  s   t t| S r   )r   idr   rr   rr   rs   r     s   zDeltaGenerator.idc                 C  s    | j }|jdurt|jjS dS )a  Returns the element's delta path as a string like "[0, 2, 3, 1]".

        This uniquely identifies the element's position in the front-end,
        which allows (among other potential uses) the MediaFileManager to maintain
        session-specific maps of MediaFile objects placed with their "coordinates".

        This way, users can (say) use st.image with a stream of different images,
        and Streamlit will expire the older images and replace them in place.
        Nz[])r   r   r   
delta_path)r   r   rr   rr   rs   _get_delta_path_str  s   z"DeltaGenerator._get_delta_path_str
delta_typeelement_protorV   add_rows_metadataAddRowsMetadata | Nonelayout_configLayoutConfig | Nonec                 C  s^  | j }t }|r|jrt|rtdt  t  t }t	|j
j|}|| |r`|jdur;|j
jjt|j |jdurK|j
jjt|j |jdur`t|j |j
jjt|j d}	|jdur||jdur||jj|jjdd< t| d}	|	r|jdur|jj||dnd}
t|j|
|d}tt||_ n|}t!j"||| j#|j#|j#|d |S )a  Create NewElement delta, fill it, and enqueue it.

        Parameters
        ----------
        delta_type : str
            The name of the streamlit method being called
        element_proto : proto
            The actual proto in the NewElement type e.g. Alert/Button/Slider
        add_rows_metadata : AddRowsMetadata or None
            Metadata for the add_rows method

        Returns
        -------
        DeltaGenerator
            Return a DeltaGenerator that can be used to modify the newly-created
            element.
        zCalling `st.sidebar` in a function wrapped with `st.fragment` is not supported. To write elements to the sidebar with a fragment, call your fragment function inside a `with st.sidebar` context manager.NFT)r   r   )rz   r   r}   )invoked_dg_id
used_dg_idreturned_dg_idr   )$r   rT   current_fragment_id_writes_directly_to_sidebarrN   rt   rx   rP   
ForwardMsgrv   deltanew_elementCopyFromheightheight_configr+   widthwidth_configr-   text_alignmentr.   text_alignment_configr,   r   r   r   metadata_enqueue_messageget_locked_cursorry   r)   r*   r   rR   save_element_messager   )r   r   r   r   r   r   rw   msgmsg_el_protomsg_was_enqueued
new_cursor	output_dgrr   rr   rs   _enqueue  sj   








	zDeltaGenerator._enqueueblock_protoBlock_pb2.Block | Nonedg_typetype | Nonec                 C  s   |d u rt  }| j}|d}|jd u s|jd u r|S t }|jj|j	jd d < |j
j| tj|jg |jj|jjR d}|d u rHt}td||j|||d}tt||_|jjd d t| tj|| j|j|jd |S )Ntype)rz   parent_pathry   r   )r   )r   r   r   )rO   Blockr   
WhichOneofr   r   rP   r   r   r   r   	add_blockr   r   RunningCursorr   indexry   r   r)   r*   r   r   r   rR   save_block_messager   )r   r   r   r   r   r   block_cursorblock_dgrr   rr   rs   _block'  sD   
zDeltaGenerator._block)
rz   r{   r   r|   r}   r~   r   r   r`   ra   )r`   r   r`   ra   )r   r   r   r   r   r   r`   r   )r`   ry   )r   r   r`   r   )r   r   r`   ry   )r`   r   )r`   r]   )r   r]   r`   r   )r`   r|   )r`   r^   )NN)
r   r   r   rV   r   r   r   r   r`   ry   )r   r   r   r   r`   ry   )__name__r   __qualname____doc__rQ   MAINr   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   rr   rr   rr   rs   ry      sD    3!
5





	
kry   r   c                 C  s,   t dd | jD }tt| j}|o| S )Nc                 s  s    | ]	}|j tjkV  qd S r   )r   rQ   r   )r   r   rr   rr   rs   r   e  s    z._writes_directly_to_sidebar.<locals>.<genexpr>)anyr   r^   listr   )r   
in_sidebarhas_containerrr   rr   rs   r   d  s   
r   r   )r   ry   r`   r^   )r   
__future__r   ro   collections.abcr   r   copyr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   &streamlit.components.v2.bidi_componentr   $streamlit.delta_generator_singletonsr   r   streamlit.elements.alertr   streamlit.elements.arrowr   streamlit.elements.balloonsr   streamlit.elements.bokeh_chartr   streamlit.elements.coder   %streamlit.elements.deck_gl_json_chartr   streamlit.elements.doc_stringr   streamlit.elements.emptyr   streamlit.elements.exceptionr    streamlit.elements.formr!   !streamlit.elements.graphviz_chartr"   streamlit.elements.headingr#   streamlit.elements.htmlr$   streamlit.elements.iframer%   streamlit.elements.imager&   streamlit.elements.jsonr'   streamlit.elements.layoutsr(   !streamlit.elements.lib.form_utilsr)   r*   #streamlit.elements.lib.layout_utilsr+   r,   r-   r.   streamlit.elements.mapr/   streamlit.elements.markdownr0   streamlit.elements.mediar1   streamlit.elements.metricr2   streamlit.elements.pdfr3   streamlit.elements.plotly_chartr4   streamlit.elements.progressr5   streamlit.elements.pyplotr6   streamlit.elements.snowr7   streamlit.elements.spacer8   streamlit.elements.textr9   streamlit.elements.toastr:   streamlit.elements.vega_chartsr;   &streamlit.elements.widgets.audio_inputr<   !streamlit.elements.widgets.buttonr=   'streamlit.elements.widgets.button_groupr>   'streamlit.elements.widgets.camera_inputr?   streamlit.elements.widgets.chatr@   #streamlit.elements.widgets.checkboxrA   'streamlit.elements.widgets.color_pickerrB   &streamlit.elements.widgets.data_editorrC   (streamlit.elements.widgets.file_uploaderrD   &streamlit.elements.widgets.multiselectrE   'streamlit.elements.widgets.number_inputrF    streamlit.elements.widgets.radiorG   (streamlit.elements.widgets.select_sliderrH   $streamlit.elements.widgets.selectboxrI   !streamlit.elements.widgets.sliderrJ   'streamlit.elements.widgets.text_widgetsrK   'streamlit.elements.widgets.time_widgetsrL   streamlit.elements.writerM   streamlit.errorsrN   streamlit.protorO   rP   !streamlit.proto.RootContainer_pb2rQ   streamlit.runtimerR   streamlit.runtime.scriptrunnerrS   r   rT   typesrU   google.protobuf.messagerV   streamlit.cursorrW   +streamlit.elements.lib.built_in_chart_utilsrX   rY   rZ   __annotations__r[   r   r\   r]   r_   rt   rx   ry   r   rr   rr   rr   rs   <module>   sj  ($	

	
 !"#$%&'()*+,-./01   :