
    G@d                         d Z ddlZddlZddlmZmZmZ ddlZddlZ ej	        e
          Zd Z G d d          Z edd          Z ed	d
          Z edd          Z edd          ZdS )zFSpyder global registries for actions, toolbuttons, toolbars and menus.    N)AnyOptionalDictc                     g }t          j                    D ]A}|j        r|j        d         }nd}| |v r$|                    |j         d|j                    Bd                    |          }|S )zr
    Get file and line where the methods that create actions, toolbuttons,
    toolbars and menus are called.
    r    :, )inspectstackcode_contextappendfilenamelinenojoin)funcframesframer   s       7lib/python3.11/site-packages/spyder/utils/registries.py
get_callerr      s    
 F > > 	 -a0LLL<MMU^<<el<<===YYvFM    c                       e Zd ZdZddedefdZ	 	 	 dded	ed
ee         dee         dee         f
dZ		 	 dd	ed
ee         dee         defdZ
	 	 dd
ee         dee         deeef         fdZd ZdefdZdS )SpyderRegistryz>General registry for global references (per plugin) in Spyder.r   creation_funcobj_typec                 0    i | _         || _        || _        d S N)registry_mapr   r   )selfr   r   s      r   __init__zSpyderRegistry.__init__(   s     *r   NFobjid_plugincontext	overwritec                    ||nd}||nd}| j                             |i           }|                    |t          j                              }||v r^	 t	          | j                  }|s/t          j        d||          d| d| d| d| d	| d
|            n# t          t          f$ r Y nw xY wt                              d| d| d| d|            |||<   |||<   || j         |<   dS )a  
        Register a reference `obj` for a given plugin name on a given context.

        Parameters
        ----------
        obj: Any
            Object to register as a reference.
        id_: str
            String identifier used to store the object reference.
        plugin: Optional[str]
            Plugin name used to store the reference. Should belong to
            :class:`spyder.api.plugins.Plugins`. If None, then the object will
            be stored under the global `main` key.
        context: Optional[str]
            Additional key used to store and identify the object reference.
            In any Spyder plugin implementation, this context may refer to an
            identifier of a widget. This context enables plugins to define
            multiple actions with the same key that live on different widgets.
            If None, this context will default to the special `__global`
            identifier.
        Nmain__globalz!There already exists a reference z	 with id z under the context z of plugin z. The new reference z. will overwrite the previous reference. Hint: z" should have a different id_. See zRegistering z (z) under context z for plugin )r   getweakrefWeakValueDictionaryr   r   warningswarnRuntimeErrorKeyErrorloggerdebug)	r   r    r!   r"   r#   r$   plugin_contextscontext_referencesr   s	            r   register_referencez!SpyderRegistry.register_reference-   s   2 "-6$0''j+//;;,00W0224 4 $$$#D$677  FME%7%<E E#&E E;BE E &,E E BEE E DG	E E
 =CE EF F F !(+    
 	 (C ( (3 ( ( ( (%( ( 	) 	) 	)"%3#5 $3&!!!s   AB B.-B.returnc                 T    ||nd}||nd}| j         |         }||         }||         S )a  
        Retrieve a stored object reference under a given id of a specific
        context of a given plugin name.

        Parameters
        ----------
        id_: str
            String identifier used to retrieve the object.
        plugin: Optional[str]
            Plugin name used to store the reference. Should belong to
            :class:`spyder.api.plugins.Plugins`. If None, then the object will
            be retrieved from the global `main` key.
        context: Optional[str]
            Additional key that was used to store the object reference.
            In any Spyder plugin implementation, this context may refer to an
            identifier of a widget. This context enables plugins to define
            multiple actions with the same key that live on different widgets.
            If None, this context will default to the special `__global`
            identifier.

        Returns
        -------
        obj: Any
            The object that was stored under the given identifier.

        Raises
        ------
        KeyError
            If neither of `id_`, `plugin` or `context` were found in the
            registry.
        Nr&   r'   r   )r   r!   r"   r#   r1   r2   s         r   get_referencezSpyderRegistry.get_referencec   sD    D "-6$0''j+F3,W5!#&&r   c                     ||nd}||nd}| j                             |i           }|                    |t          j                              }|S )a  
        Retrieve all stored object references under the context of a
        given plugin name.

        Parameters
        ----------
        plugin: Optional[str]
            Plugin name used to store the reference. Should belong to
            :class:`spyder.api.plugins.Plugins`. If None, then the object will
            be retrieved from the global `main` key.
        context: Optional[str]
            Additional key that was used to store the object reference.
            In any Spyder plugin implementation, this context may refer to an
            identifier of a widget. This context enables plugins to define
            multiple actions with the same key that live on different widgets.
            If None, this context will default to the special `__global`
            identifier.

        Returns
        -------
        objs: Dict[str, Any]
            A dict that contains the actions mapped by their corresponding
            identifiers.
        Nr&   r'   )r   r(   r)   r*   )r   r"   r#   r1   r2   s        r   get_referenceszSpyderRegistry.get_references   sb    4 "-6$0''j+//;;,00W0224 4!!r   c                     i | _         d S r   r6   r   s    r   reset_registryzSpyderRegistry.reset_registry   s    r   c                 (    d| j          d| j         dS )NzSpyderRegistry[r	   ])r   r   r;   s    r   __str__zSpyderRegistry.__str__   s     FFF$2CFFFFr   )r   )NNF)NN)__name__
__module____qualname____doc__strr   r   r   boolr3   r7   r   r9   r<   r?    r   r   r   r   %   s]       HH+ +c +S + + + + 48487<44 44c 44 44#+C=44$,SM44 '/tn44 44 44 44n /3/3'' '' ''&sm'''}''8;'' '' '' ''R 6:04 "  "Xc]  " ( "9=c3h "  "  "  "D  G G G G G G Gr   r   create_actionSpyderActioncreate_toolbuttonQToolButtoncreate_toolbarQToolBarcreate_menu
SpyderMenu)rC   r
   loggingtypingr   r   r   r+   r)   	getLoggerr@   r/   r   r   ACTION_REGISTRYTOOLBUTTON_REGISTRYTOOLBAR_REGISTRYMENU_REGISTRYrF   r   r   <module>rV      s    M L   & & & & & & & & & &  		8	$	$  "MG MG MG MG MG MG MG MG` !..AA$n%8-HH !>"2J?? }l;;r   