
    AHj	                    `    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Zy	)    )annotations)Callable)events)invoke)DOMNodeDuplicateKeyHandlers)MessagePumpc                `  K   dd}d}d}|j                   }|sy	 	 	 	 	 	 	 	 dd}	 | j                  }|j                  D ]W  } || |      x}	|r |||j                  |	j                         ||j
                  s |S t        |	|       d{   du}|	}Y |S # t        $ r d}Y uw xY w7 w)a  Dispatch a key event to method.

    This function will call the method named 'key_<event.key>' on a node if it exists.
    Some keys have aliases. The first alias found will be invoked if it exists.
    If multiple handlers exist that match the key, an exception is raised.

    Args:
        event: A key event.

    Returns:
        True if key was handled, otherwise False.

    Raises:
        DuplicateKeyHandlers: When there's more than 1 handler that could handle this key.
    c                F    t        | d| d      xs t        | d| d      S )z@Look for the public and private handler methods by name on self.key_N_key_)getattr)pumpkeys     M/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/_dispatch_key.pyget_key_handlerz%dispatch_key.<locals>.get_key_handler   s,    ttC5\40VGDE#-QU4VV    FNc           	     ,    t        d| d|d|d      )znRaise exception for case where user presses a key and there are multiple candidate key handler methods for it.z Multiple handlers for key press z.
We found both z and zO, and didn't know which to call.
Consider combining them into a single handler.r   )key_namefirst_handlersecond_handlers      r   #_raise_duplicate_key_handlers_errorz9dispatch_key.<locals>._raise_duplicate_key_handlers_error'   s5     #.xl ;*-U>2D E=>
 	
r   )r   r
   r   strreturnzCallable | None)r   r   r   r   r   r   r   None)namescreen	Exceptionname_aliases__name__	is_activer   )
nodeeventr   handledinvoked_methodr   r   r   key_method_name
key_methods
             r   dispatch_keyr)      s     "W GNzzH	
	
&)	
;>	
		
 !-- ()$@@JM3n55z7J7J !&*:*: N $J66uDG'N( N!   7s:   $B.B B.A B.B,B.B)&B.(B))B.N)r#   r   r$   z
events.Keyr   bool)
__future__r   typingr   textualr   textual._callbackr   textual.domr   textual.errorsr	   textual.message_pumpr
   r)    r   r   <module>r3      s    "   $  / ,8r   