
    Je                         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y)zFSpyder global registries for actions, toolbuttons, toolbars and menus.    N)AnyOptionalDictc                     g }t        j                         D ]O  }|j                  r|j                  d   }nd}| |v s&|j                  |j                   d|j
                          Q dj                  |      }|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       9/usr/lib/python3/dist-packages/spyder/utils/registries.py
get_callerr      sy    
 F > --a0LL<MMU^^,Aell^<=> 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y)SpyderRegistryz>General registry for global references (per plugin) in Spyder.creation_funcobj_typec                 .    i | _         || _        || _        y N)registry_mapr   r   )selfr   r   s      r   __init__zSpyderRegistry.__init__(   s     *r   Nobjid_plugincontext	overwritec                    ||nd}||nd}| j                   j                  |i       }|j                  |t        j                               }||v rE	 t	        | j
                        }|s-t        j                  d||    d| d| d| d| d	| d
|        t        j                  d| d| d| d|        |||<   |||<   || j                   |<   y# t        t        f$ r Y Lw xY w)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-   sD   2 "-6$0'j++//;,00W0024 $$#D$6$67 MM%%7%<$= >##&%':7) D%%+H,@ FCCF% H<<B8EF 	|C53%/?y I%h( 	)"%3#5 $3&! !(+  s   AC C#"C#returnc                 L    ||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.
        r&   r'   r   )r   r!   r"   r#   r1   r2   s         r   get_referencezSpyderRegistry.get_referencec   sC    D "-6$0'j++F3,W5!#&&r   c                     ||nd}||nd}| j                   j                  |i       }|j                  |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.
        r&   r'   )r   r(   r)   r*   )r   r"   r#   r1   r2   s        r   get_referenceszSpyderRegistry.get_references   sY    4 "-6$0'j++//;,00W0024!!r   c                     i | _         y 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"     r$2C2C1DAFFr   )r   )NNF)NN)__name__
__module____qualname____doc__strr   r   r   boolr3   r7   r   r9   r<   r?    r   r   r   r   %   s    H+c +S + 48487<44c 44 44#+C=44$,SM44 '/tn44n /3/3'' ''&sm'''}''8;''R 6:04 "Xc]  " ( "9=c3h "D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   & &  			8	$"MG MG` !.A$%8-H !"2J? }l;r   