
    Cj                       S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
  SSKJrJr  SSKrSSKJr  \(       a  SSKJr  \	" S5      r\
\\/\\   4   \\/\4   4   r " S	 S
\5      r\R0                  R3                  SS9 " S S\\   5      5       rg)z
Signals are a simple pub-sub mechanism.

DOMNodes can subscribe to a signal, which will invoke a callback when the signal is published.

    )annotations)TYPE_CHECKINGAny	AwaitableCallableGenericTypeVarUnion)WeakKeyDictionaryrefN)log)DOMNodeSignalTc                      \ rS rSrSrSrg)SignalError   zRaised for Signal errors. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       `/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/signal.pyr   r      s    #r   r   T)angularc                  r    \ rS rSrSrSS jrSS jr\SS j5       r S       SS jjr	SS jr
SS jrS	rg
)Signal   zfA signal that a widget may subscribe to, in order to invoke callbacks when an associated event occurs.c                N    [        U5      U l        X l        [        5       U l        g)zqInitialize a signal.

Args:
    owner: The owner of this signal.
    name: An identifier for debugging purposes.
N)r   _owner_namer   _subscriptions)selfownernames      r   __init__Signal.__init__#   s$     %j
  	r   c              #     #    SU R                   4v   SU R                  4v   S[        U R                  R	                  5       5      4v   g 7f)Nr%   r&   subscriptions)r%   r"   listr#   keysr$   s    r   __rich_repr__Signal.__rich_repr__0   sB     tzz!!djj  tD$7$7$<$<$>???s   A	Ac                "    U R                  5       $ )z9The owner of this Signal, or `None` if there is no owner.)r!   r-   s    r   r%   Signal.owner5   s     {{}r   c                   ^^ TR                   (       d  [        ST S35      eU(       a	  SU4S jjnO	SUU4S jjnU R                  R                  T/ 5      nUR	                  U5        g)a  Subscribe a node to this signal.

When the signal is published, the callback will be invoked.

Args:
    node: Node to subscribe.
    callback: A callback function which takes a single argument and returns anything (return type ignored).
    immediate: Invoke the callback immediately on publish if `True`, otherwise post it to the DOM node to be
        called once existing messages have been processed.

Raises:
    SignalError: Raised when subscribing a non-mounted widget.
z3Node must be running to subscribe to a signal (has z been mounted)?c                   > T" U 5        g)z Invoke the callback immediately.Nr   )datacallbacks    r   signal_callback)Signal.subscribe.<locals>.signal_callbackT   s
    r   c                *   > TR                  TU 5        g)z>Post the callback to the node, to call at the next opertunity.N)	call_next)r4   r5   nodes    r   r6   r7   Z   s    x.r   Nr4   r   returnNone)
is_runningr   r#   
setdefaultappend)r$   r:   r5   	immediater6   	callbackss    ``   r   	subscribeSignal.subscribe:   sf    & EdV?[   / / ''224<	)r   c                <    U R                   R                  US5        g)zKUnsubscribe a node from this signal.

Args:
    node: Node to unsubscribe,
N)r#   pop)r$   r:   s     r   unsubscribeSignal.unsubscribea   s     	d+r   c                d   U R                   (       d  gU R                  nUc  gUR                  (       a  UR                  (       a  gUR                   H  nUR
                  (       a  M    g   [        U R                   R                  5       5       Hg  u  pEUR
                  (       a"  UR                  (       a  UR                  (       a  U R                   R                  U5        MU  U H  n U" U5        M     Mi     g! [         a*  n[        R                  " SU SU SU 35         SnAMD  SnAff = f)zjPublish the signal (invoke subscribed callbacks).

Args:
    data: An argument to pass to the callbacks.

Nzerror publishing signal to z ignored (callback=z); )r#   r%   is_attached_pruningancestors_with_selfr>   r+   itemsrF   	Exceptionr   error)r$   r4   r%   ancestor_noder:   rB   r5   rO   s           r   publishSignal.publishi   s     ""

=  ENN"66M +++ 7  $D$7$7$=$=$?@ODOO(8(8T]]##''- !*H  !*  A % 		9$?RS[R\\_`e_fg s   *C;;
D/D**D/)r"   r!   r#   N)r%   r   r&   strr<   r=   )r<   zrich.repr.Result)r<   zDOMNode | None)F)r:   r   r5   zSignalCallbackType[SignalT]rA   boolr<   r=   )r:   r   r<   r=   r;   )r   r   r   r   r   r'   r.   propertyr%   rC   rG   rQ   r   r   r   r   r   r      s_    p @
    	%*%* .%* 	%*
 
%*N, r   r   )r   
__future__r   typingr   r   r   r   r   r	   r
   weakrefr   r   	rich.reprrichtextualr   textual.domr   r   SignalCallbackTyperN   r   reprautor   r   r   r   <module>r`      s    # S S S *  #
)
gY	#&'7)S.)AA 
$) $ iWW i ir   