
    P/Ph.                         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d
S )    )_apibackend_toolscbookwidgetsc                       e Zd ZdZddZdS )	ToolEventz)Event for tool manipulation (add/remove).Nc                 >    || _         || _        || _        || _        d S N)namesendertooldata)selfr   r   r   r   s        [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/matplotlib/backend_managers.py__init__zToolEvent.__init__   s"    					    r
   __name__
__module____qualname____doc__r    r   r   r   r      s.        3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.Nc                 ^    t                                          ||||           || _        d S r
   )superr   canvasevent)r   r   r   r   r   r   	__class__s         r   r   zToolTriggerEvent.__init__   s/    vtT222&r   )NN)r   r   r   r   r   __classcell__)r   s   @r   r   r      sC        99' ' ' ' ' ' ' ' ' 'r   r   c                       e Zd ZdZd ZdS )ToolManagerMessageEventzs
    Event carrying messages from toolmanager.

    Messages usually get displayed to the user by the toolbar.
    c                 0    || _         || _        || _        d S 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dS )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 | _        |                     |           d S r
   )_key_press_handler_id_tools_keys_toggledr   CallbackRegistry
_callbacksr   LockDrawkeypresslockmessagelock_figure
set_figurer   figures     r   r   zToolManager.__init__.   sr    %)"
022 $,.."+--r   c                 ,    | j         sdS | j         j        S )z Canvas managed by FigureManager.N)r0   canvasr   s    r   r5   zToolManager.canvas>   s     | 	4|""r   c                     | j         S )zFigure that holds the canvas.)r0   r6   s    r   r3   zToolManager.figureE   s     |r   c                 0    |                      |           d S r
   )r1   r2   s     r   r3   zToolManager.figureJ   s    r   Tc                     | j         r| j                            | j                    || _        |r%| j                            d| j                  | _         |r#| j                                        D ]}||_        
dS dS )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   s     % 	CK&&t'ABBB 	4)-)@)@!4?*4 *4D& 	%**,, % %$	% 	%% %r   c                 8    | 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                 6    | 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                 j    || }d}t          |||          }| j                            ||           dS )z!Emit a `ToolManagerMessageEvent`.Ntool_message_event)r!   r,   process)r   r#   r   rB   events        r   message_eventzToolManager.message_event   s@    >F '67;;5)))))r   c                     | j         S )zCurrently toggled tools.)r*   r6   s    r   active_togglezToolManager.active_toggle   s     }r   c                 R    fd| j                                         D             }|S )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.
        c                 &    g | ]\  }}|k    |S r   r   ).0kir   s      r   
<listcomp>z/ToolManager.get_tool_keymap.<locals>.<listcomp>   s"    >>>daAIIIIIr   )r)   items)r   r   keyss    ` r   get_tool_keymapzToolManager.get_tool_keymap   s1     ?>>>dj..00>>>r   c                 F    |                      |          D ]
}| j        |= d S r
   )rX   r)   )r   r   rS   s      r   _remove_keyszToolManager._remove_keys   s4    %%d++ 	 	A
1	 	r   c           	         || j         vrt          |d          |                     |           t          |t                    r|g}|D ]=}|| j        v r(t          j        d| d| j        |          d|            || j        |<   >dS )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(   KeyErrorrZ   
isinstancestrr)   r   warn_external)r   r   keyrS   s       r   update_keymapzToolManager.update_keymap   s     t{""d333444$c3 	%C 	! 	!ADJ"E1EEDJqMEEtEEG G G DJqMM		! 	!r   c                    |                      |          }t          |dd          r|                     |d           |                     |           t	          d| |          }| j                            |j        |           | j        |= dS )z
        Remove tool named *name*.

        Parameters
        ----------
        name : str
            Name of the tool.
        toggledFtoolmanagertool_removed_eventN)	get_toolgetattrtrigger_toolrZ   r   r,   rK   r   r(   )r   r   r   rL   s       r   remove_toolzToolManager.remove_tool   s     }}T""4E** 	3dM222$.d;;
E222Kr   c                     t          j        t          | j                  |          }|st	          dt          |          z            || j        v r!t          j        d           | j        |         S  || |g|R i |}|| j        |<   |j	        | 
                    ||j	                   t          |t           j                  rm|j        (| j                            dt!                                 n | j                            |j        d           |j        r|                     |dd           |                    | j                   t+          d| |          }| j                            |j        |           |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.
        *args, **kwargs
            Passed to the *tool*'s 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 addedNtool_added_event)r   _find_tool_classtyper5   
ValueErrorr^   r(   r   r_   default_keymapra   r]   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   . !1$t{2C2CTJJ 	L>TJKKK4;  3 4 4 4;t$$8D$888888$D".tX%<=== h <== 
	: #+((suu5555(()=tDDD  :##HdD999DK(((,dH==
E222r   c                    |j         }|a|j        | j        d         v r&| j        d                             |j                   n%| j        d                             |j                   dS | j        |         |j        k    rd}n?| j        |         |j        }n*|                     | j        |         | ||           |j        }|| j        |<   dS )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)rq   r   r*   removeaddrh   )r   r   r   r   rq   rc   s         r   rt   zToolManager._handle_toggle  s     & yDM$///d#**495555d#''	222F =%22GG ];'/iGG dmK8")"$ $ $ iG &-k"""r   c                 6   |                      |          }|dS || }t          |t          j                  r|                     |||           |                    |||           d|z  }t          |||||          }| j                            ||           dS )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)	rf   r]   r   rp   rt   triggerr   r,   rK   )r   r   r   r   r   r   rB   rL   s           r   rh   zToolManager.trigger_tool;  s     }}T""<F>FdM899 	9k4888V[$///$ FD+tDD5)))))r   c                     |j         | j                                        rd S | j                            |j         d           }|d S |                     ||           d S )N)r   )r`   r.   lockedr)   getrh   )r   rL   r   s      r   r=   zToolManager._key_pressZ  sc    9 1 8 8 : :Fz~~ei..<F$E22222r   c                     | j         S )z,A dict mapping tool name -> controlled tool.)r(   r6   s    r   toolszToolManager.toolsc  s     {r   c                     t          |t          j                  r|j        | j        v r|S || j        vr|rt          j        d|           dS | 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)r]   r   ToolBaser   r(   r   r_   )r   r   warns      r   rf   zToolManager.get_toolh  sx    & t]344 	I,,Kt{"" C"AAAC C C4{4  r   r
   )T)NNN)r   r   r   r   r   propertyr5   r3   setterr1   rD   rH   rM   rO   rX   rZ   ra   ri   ry   rt   rh   r=   r   rf   r   r   r   r%   r%       s                 # # X#   X ]    ] % % % %(0 0 0<
/ 
/ 
/* * * *   X  $  ! ! !,  "7 7 7r)- )- )-V* * * *>3 3 3   X! ! ! ! ! !r   r%   N)	
matplotlibr   r   r   r   r   r   r!   r%   r   r   r   <module>r      s    : : : : : : : : : : : :       ' ' ' ' 'y ' ' '	 	 	 	 	 	 	 	c! c! c! c! c! c! c! c! c! c!r   