L iUdZddlmZddlmZmZddlmZmZm Z ddl m Z erddl mZddlmZddlmZdd lmZGd d Zdd Ze d ZGddeeZeddZded<ddZddZy)z The main purpose of this module (right now at least) is to avoid a dependency cycle between streamlit.delta_generator and some elements. ) annotations) ContextVarToken) TYPE_CHECKINGGenericTypeVar) RootContainer)Callable)DeltaGenerator)Dialog)StatusContainerceZdZUdZdZded<ed dZ ddZe ddZ e ddZ e dd Z e dd Z e dd Ze dd Zy)DeltaGeneratorSingletonaUsed to initialize the DeltaGenerator classes and store them as singletons. This module allows us to avoid circular imports between DeltaGenerator and elements, because elements can import this singleton module instead of DeltaGenerator directly. NzDeltaGeneratorSingleton | None _instancecH|j td|jS)zReturn the singleton DeltaGeneratorSingleton instance. Raise an Error if the DeltaGeneratorSingleton hasn't been created yet. z,DeltaGeneratorSingleton hasn't been created!)r RuntimeError)clss j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/delta_generator_singletons.pyinstancez DeltaGeneratorSingleton.instance+s$ == MN N}}ctj td|t_|tj|_|tj |j |_|tj|j |_ |tj|j |_ ||_ ||_ y)aERegisters and initializes all delta-generator classes. Parameters ---------- delta_generator_cls : type[DeltaGenerator] The main DeltaGenerator class. status_container_cls : type[StatusContainer] The delta-generator class that is used as return value for `st.status`. dialog_container_cls : type[Dialog] The delta-generator class used is used as return value for `st.dialog`. Raises ------ RuntimeError If the DeltaGeneratorSingleton instance already exists. Nz0DeltaGeneratorSingleton instance already exists!)root_container)rparent)rrr_RootContainerMAIN_main_dgSIDEBAR _sidebar_dgEVENT _event_dgBOTTOM _bottom_dg_status_container_cls_dialog_container_cls)selfdelta_generator_clsstatus_container_clsdialog_container_clss r__init__z DeltaGeneratorSingleton.__init__4s, # , , 8QR R,0)+>;N;NO .)11$-- -)//  .)00 &:"%9"rc|jSN)rr%s rmain_dgzDeltaGeneratorSingleton.main_dg[s }}rc|jSr+)rr,s r sidebar_dgz"DeltaGeneratorSingleton.sidebar_dg_src|jSr+)r r,s revent_dgz DeltaGeneratorSingleton.event_dgcs ~~rc|jSr+)r"r,s r bottom_dgz!DeltaGeneratorSingleton.bottom_dggs rc|jS)zStub for StatusContainer. Since StatusContainer inherits from DeltaGenerator, this is used to avoid circular imports. )r#r,s rr'z,DeltaGeneratorSingleton.status_container_clsks)))rc|jS)ztStub for Dialog. Since Dialog inherits from DeltaGenerator, this is used to avoid circular imports. )r$r,s rr(z,DeltaGeneratorSingleton.dialog_container_clsts )))rreturnr)r&ztype[DeltaGenerator]r'type[StatusContainer]r( type[Dialog]r7None)r7r )r7r8)r7r9)__name__ __module__ __qualname____doc__r__annotations__ classmethodrr)propertyr-r/r1r3r'r(rrrr#s 15I-4%:1%:4%:+ %:  %:N  * ****rrc*tjS)z|Return the DeltaGeneratorSingleton instance. Raise an Error if the DeltaGeneratorSingleton hasn't been created yet. )rrrBrrget_dg_singleton_instancerD|s # + + --r_Tc@eZdZdZd dZd dZd dZd dZd dZddZ y)ContextVarWithLazyDefaultaThe dg_stack tracks the currently active DeltaGenerator, and is pushed to when a DeltaGenerator is entered via a `with` block. This is implemented as a ContextVar so that different threads or async tasks can have their own stacks. We have a wrapper around it because ContextVar default cannot be a function, but the default dg (main_dg) might not exist yet when this module is imported. c.||_||_d|_yr+)_name_default _context_var)r%namedefaults rr)z"ContextVarWithLazyDefault.__init__s  37rcXt|j|j|_y)NrM)rrIrJrKr,s r_init_context_varz+ContextVarWithLazyDefault._init_context_vars&tzz4==?Krcn|j|j|jjSr+)rKrPgetr,s rrRzContextVarWithLazyDefault.gets/    $  " " $  $$&&rcp|j|j|jj|Sr+)rKrPset)r%values rrTzContextVarWithLazyDefault.sets1    $  " " $  $$U++rcr|j|j|jj|yr+)rKrPreset)r%tokens rrWzContextVarWithLazyDefault.resets.    $  " " $ &rcn|j|j|jjSr+)rKrP__hash__r,s rrZz"ContextVarWithLazyDefault.__hash__s/    $  " " $  ))++rN)rLstrrMzCallable[[], _T]r7r:)r7r:)r7rE)rUrEr7 Token[_T])rXr\r7r:)r7int) r;r<r=r>r)rPrRrTrWrZrBrrrGrGs&8 L' , ' ,rrGcontext_dg_stackc,tjfSr+)rDr-rBrrr`s-F-H-P-P,RrrOz5ContextVarWithLazyDefault[tuple[DeltaGenerator, ...]]c^t}|j td|jfS)zjGet the default dg_stack value with which the dg_stack should be initialized and reset if needed. zmain_dg is not set)rDrr)rs rget_default_dg_stack_valuerbs3)*H /00    rcRtj}t|dkDr|dSy)zGet the last added DeltaGenerator of the stack in the current context. Returns None if the stack has only one element or is empty for whatever reason. N)r^rRlen) current_stacks r"get_last_dg_added_to_context_stackrhs/ %((*M =AR  rNr6)r7ztuple[DeltaGenerator, ...])r7zDeltaGenerator | None)r> __future__r contextvarsrrtypingrrr!streamlit.proto.RootContainer_pb2r rcollections.abcr streamlit.delta_generatorr streamlit.elements.lib.dialogr /streamlit.elements.lib.mutable_status_containerr rrDrErGr^r?rbrhrBrrrqs #)22M(84OV*V*r. T]#, #,R$RG r