
    G8cv1                     n    d dl mZmZmZmZ  G d d      Z G d de      Z G d d      Z G d d	      Zy
)    )_apibackend_toolscbookwidgetsc                       e Zd ZdZddZy)	ToolEventz)Event for tool manipulation (add/remove).Nc                 <    || _         || _        || _        || _        y N)namesendertooldata)selfr   r   r   r   s        =/usr/lib/python3/dist-packages/matplotlib/backend_managers.py__init__zToolEvent.__init__   s    			    r
   __name__
__module____qualname____doc__r    r   r   r   r      s
    3r   r   c                   $     e Zd ZdZd fd	Z xZS )ToolTriggerEventz/Event to inform that a tool has been triggered.c                 8    t         |   ||||       || _        y r
   )superr   canvasevent)r   r   r   r   r   r   	__class__s         r   r   zToolTriggerEvent.__init__   s    vtT2&r   )NN)r   r   r   r   r   __classcell__)r   s   @r   r   r      s    9' 'r   r   c                       e Zd ZdZd Zy)ToolManagerMessageEventzs
    Event carrying messages from toolmanager.

    Messages usually get displayed to the user by the toolbar.
    c                 .    || _         || _        || _        y r
   )r   r   message)r   r   r   r#   s       r   r   z ToolManagerMessageEvent.__init__   s    	r   Nr   r   r   r   r!   r!      s    
r   r!   c                       e Zd ZdZddZed        Zed        Zej                  d        ZddZ	d Z
d	 Zdd
Zed        Zd Zd Zd Zd Zd Zd ZddZd Zed        ZddZy)ToolManagera  
    Manager for actions triggered by user interactions (key press, toolbar
    clicks, ...) on a Figure.

    Attributes
    ----------
    figure : `.Figure`
    keypresslock : `~matplotlib.widgets.LockDraw`
        `.LockDraw` object to know if the `canvas` key_press_event is locked.
    messagelock : `~matplotlib.widgets.LockDraw`
        `.LockDraw` object to know if the message is available to write.
    Nc                    d | _         i | _        i | _        i | _        t	        j
                         | _        t        j                         | _	        t        j                         | _
        d | _        | j                  |       y r
   )_key_press_handler_id_tools_keys_toggledr   CallbackRegistry
_callbacksr   LockDrawkeypresslockmessagelock_figure
set_figurer   figures     r   r   zToolManager.__init__.   sf    %)"
002 $,,."++-r   c                 H    | j                   sy| j                   j                  S )z Canvas managed by FigureManager.N)r0   canvasr   s    r   r5   zToolManager.canvas>   s     ||||"""r   c                     | j                   S )zFigure that holds the canvas.)r0   r6   s    r   r3   zToolManager.figureE   s     ||r   c                 &    | j                  |       y r
   )r1   r2   s     r   r3   zToolManager.figureJ   s    r   c                     | j                   r%| j                  j                  | j                          || _        |r+| j                  j	                  d| j
                        | _         |r'| j                  j                         D ]	  }||_         yy)z
        Bind the given figure to the tools.

        Parameters
        ----------
        figure : `.Figure`
        update_tools : bool, default: True
            Force tools to update figure.
        key_press_eventN)	r'   r5   mpl_disconnectr0   mpl_connect
_key_pressr(   valuesr3   )r   r3   update_toolsr   s       r   r1   zToolManager.set_figureN   sz     %%KK&&t'A'AB)-)@)@!4??*4D&**, %$% r   c                 :    | j                   j                  ||      S )a  
        Connect event with string *s* to *func*.

        Parameters
        ----------
        s : str
            The name of the event. The following events are recognized:

            - 'tool_message_event'
            - 'tool_removed_event'
            - 'tool_added_event'

            For every tool added a new event is created

            - 'tool_trigger_TOOLNAME', where TOOLNAME is the id of the tool.

        func : callable
            Callback function for the toolmanager event with signature::

                def func(event: ToolEvent) -> Any

        Returns
        -------
        cid
            The callback id for the connection. This can be used in
            `.toolmanager_disconnect`.
        )r,   connect)r   sfuncs      r   toolmanager_connectzToolManager.toolmanager_connectb   s    8 &&q$//r   c                 8    | j                   j                  |      S )z
        Disconnect callback id *cid*.

        Example usage::

            cid = toolmanager.toolmanager_connect('tool_trigger_zoom', onpress)
            #...later
            toolmanager.toolmanager_disconnect(cid)
        )r,   
disconnect)r   cids     r   toolmanager_disconnectz"ToolManager.toolmanager_disconnect   s     ))#..r   c                 b    || }d}t        |||      }| j                  j                  ||       y)z!Emit a `ToolManagerMessageEvent`.Ntool_message_event)r!   r,   process)r   r#   r   rB   events        r   message_eventzToolManager.message_event   s3    >F '67;5)r   c                     | j                   S )zCurrently toggled tools.)r*   r6   s    r   active_togglezToolManager.active_toggle   s     }}r   c                 v    | j                   j                         D cg c]  \  }}||k(  s| }}}|S c c}}w )a  
        Return the keymap associated with the specified tool.

        Parameters
        ----------
        name : str
            Name of the Tool.

        Returns
        -------
        list of str
            List of keys associated with the tool.
        )r)   items)r   r   kikeyss        r   get_tool_keymapzToolManager.get_tool_keymap   s8     #jj..0>daAI>> ?s   55c                 J    | j                  |      D ]  }| j                  |=  y r
   )rU   r)   )r   r   rR   s      r   _remove_keyszToolManager._remove_keys   s'    %%d+ 	A

1	r   c           	      "   || j                   vrt        |d      | j                  |       t        |t              r|g}|D ]J  }|| j
                  v r+t        j                  d| d| j
                  |    d|        || j
                  |<   L y)z
        Set the keymap to associate with the specified tool.

        Parameters
        ----------
        name : str
            Name of the Tool.
        key : str or list of str
            Keys to associate with the tool.
        z not in ToolszKey z changed from z to N)r(   KeyErrorrW   
isinstancestrr)   r   warn_external)r   r   keyrR   s       r   update_keymapzToolManager.update_keymap   s     t{{"dX]344$c3%C 	!ADJJ""1#^DJJqM?$tfEG DJJqM		!r   c                 z   | j                  |      }t        j                  t        j                  j
                  |dd      }| |        t        |dd      r| j                  |d       | j                  |       t        d| |      }| j                  j                  |j                  |       | j                  |= y)z
        Remove tool named *name*.

        Parameters
        ----------
        name : str
            Name of the tool.
        z3.6tool_removed_event)sincealternativeNtoggledFtoolmanager)get_toolr   deprecate_method_overrider   ToolBasedestroygetattrtrigger_toolrW   r   r,   rK   r   r(   )r   r   r   rh   rL   s        r   remove_toolzToolManager.remove_tool   s     }}T"00""**D,. I 4E*dM2$.d;

E2KKr   c                    t        j                  t        | j                        |      }|st	        dt        |      z        || j                  v r$t        j                  d       | j                  |   S |dk(  rE|t         j                  k7  r2t        j                  dd|j                   d|j                   d        || |g|i |}|| j                  |<   |j                  | j                  ||j                         t        |t         j                         rv|j"                  %| j$                  j'                  d	t)                      n&| j$                  j'                  |j"                  d	       |j*                  r| j-                  |d	d	       |j/                  | j0                         t3        d
| |      }| j4                  j7                  |j8                  |       |S )a  
        Add *tool* to `ToolManager`.

        If successful, adds a new event ``tool_trigger_{name}`` where
        ``{name}`` is the *name* of the tool; the event is fired every time the
        tool is triggered.

        Parameters
        ----------
        name : str
            Name of the tool, treated as the ID, has to be unique.
        tool : type
            Class of the tool to be added.  A subclass will be used
            instead if one was registered for the current canvas class.

        Notes
        -----
        args and kwargs get passed directly to the tools constructor.

        See Also
        --------
        matplotlib.backend_tools.ToolBase : The base class for tools.
        zImpossible to find class for %sz;A "Tool class" with the same name already exists, not addedcursorz3.5zOverriding ToolSetCursor with z was only necessary to provide the .set_cursor() method, which is deprecated since %(since)s and will be removed %(removal)s. Please report this to the z author.)r#   Ntool_added_event)r   _find_tool_classtyper5   
ValueErrorr[   r(   r   r\   SetCursorBasewarn_deprecatedr   r   default_keymapr^   rZ   ToolToggleBaseradio_groupr*   
setdefaultsetrc   _handle_toggler1   r3   r   r,   rK   r   )r   r   r   argskwargstool_clstool_objrL   s           r   add_toolzToolManager.add_tool   s   2 !11$t{{2CTJ>TJKK4;;  3 4;;t$$8M,G,G G  )I$,$9$9#: ;K
 %-$7$7#8*BC D$888$D"".tX%<%<= h < <= ##+((su5(()=)=tD ##HdD9DKK(,dH=

E2r   c                    |j                   }|m|j                  | j                  d   v r)| j                  d   j                  |j                         y| j                  d   j	                  |j                         y| j                  |   |j                  k(  rd}nI| j                  |   |j                  }n-| j                  | j                  |   | ||       |j                  }|| j                  |<   y)aO  
        Toggle tools, need to untoggle prior to using other Toggle tool.
        Called from trigger_tool.

        Parameters
        ----------
        tool : `.ToolBase`
        canvasevent : Event
            Original Canvas event or None.
        data : object
            Extra data to pass to the tool when triggering.
        N)rv   r   r*   removeaddrj   )r   r   r   r   rv   rc   s         r   ry   zToolManager._handle_toggle'  s     && yyDMM$//d#**4995  d#''		2 ==%2G ]];'/iiG dmmK8")"$ iiG &-k"r   c                    | j                  |      }|y|| }t        |t        j                        r| j	                  |||       |j                  |||       d|z  }t        |||||      }| j                  j                  ||       y)a  
        Trigger a tool and emit the ``tool_trigger_{name}`` event.

        Parameters
        ----------
        name : str
            Name of the tool.
        sender : object
            Object that wishes to trigger the tool.
        canvasevent : Event
            Original Canvas event or None.
        data : object
            Extra data to pass to the tool when triggering.
        Nztool_trigger_%s)	re   rZ   r   ru   ry   triggerr   r,   rK   )r   r   r   r   r   r   rB   rL   s           r   rj   zToolManager.trigger_toolR  s     }}T"<>FdM889k48V[$/$ FD+tD5)r   c                     |j                   | j                  j                         ry | j                  j	                  |j                   d       }|y | j                  ||       y )N)r   )r]   r.   lockedr)   getrj   )r   rL   r   s      r   r=   zToolManager._key_pressq  sS    99 1 1 8 8 :zz~~eii.<$E2r   c                     | j                   S )z,A dict mapping tool name -> controlled tool.)r(   r6   s    r   toolszToolManager.toolsz  s     {{r   c                     t        |t        j                        r|j                  | j                  v r|S || j                  vr|rt        j                  d|       y| j                  |   S )a  
        Return the tool object with the given name.

        For convenience, this passes tool objects through.

        Parameters
        ----------
        name : str or `.ToolBase`
            Name of the tool, or the tool itself.
        warn : bool, default: True
            Whether a warning should be emitted it no tool with the given name
            exists.

        Returns
        -------
        `.ToolBase` or None
            The tool or None if no tool with the given name exists.
        z"ToolManager does not control tool N)rZ   r   rg   r   r(   r   r\   )r   r   warns      r   re   zToolManager.get_tool  sc    & t]334II,Kt{{"""8AC{{4  r   r
   )T)NNN)r   r   r   r   r   propertyr5   r3   setterr1   rD   rH   rM   rO   rU   rW   r^   rk   r~   ry   rj   r=   r   re   r   r   r   r%   r%       s       # #   ]]   %(0<
/*  $!,8CJ)-V*>3  !r   r%   N)	
matplotlibr   r   r   r   r   r   r!   r%   r   r   r   <module>r      s7    : : 'y '	 	z! z!r   