o
    tBh4                     @   s^   d dl mZmZmZ d dlmZ G dd dZG dd deZG dd dZ	G d	d
 d
Z
dS )    )_apicbookwidgetsNc                   @   s   e Zd ZdZdddZdS )	ToolEventz)Event for tool manipulation (add/remove).Nc                 C   s   || _ || _|| _|| _d S N)namesendertooldata)selfr   r   r	   r
    r   r/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/matplotlib/backend_managers.py__init__   s   
zToolEvent.__init__r   __name__
__module____qualname____doc__r   r   r   r   r   r      s    r   c                       s"   e Zd ZdZd fdd	Z  ZS )ToolTriggerEventz/Event to inform that a tool has been triggered.Nc                    s   t  |||| || _d S r   )superr   canvasevent)r   r   r   r	   r   r
   	__class__r   r   r      s   
zToolTriggerEvent.__init__)NN)r   r   r   r   r   __classcell__r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )ToolManagerMessageEventzs
    Event carrying messages from toolmanager.

    Messages usually get displayed to the user by the toolbar.
    c                 C   s   || _ || _|| _d S r   )r   r   message)r   r   r   r   r   r   r   r      s   
z ToolManagerMessageEvent.__init__Nr   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZd/ddZedd Zedd Zejd	d Zd0ddZ	dd Z
dd Zd/ddZedd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd1d%d&Zd1d'd(Zd)d* Zed+d, Zd0d-d.ZdS )2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                 C   sJ   d | _ i | _i | _i | _t | _t | _	t | _
d | _| | d S r   )_key_press_handler_id_tools_keys_toggledr   CallbackRegistry
_callbacksr   LockDrawkeypresslockmessagelock_figure
set_figurer   figurer   r   r   r   /   s   


zToolManager.__init__c                 C   s   | j sdS | j jS )z Canvas managed by FigureManager.N)r&   canvasr   r   r   r   r*   ?   s   zToolManager.canvasc                 C      | j S )zFigure that holds the canvas.)r&   r+   r   r   r   r)   F      zToolManager.figurec                 C   s   |  | d S r   )r'   r(   r   r   r   r)   K   s   Tc                 C   sR   | j r
| j| j  || _|r| jd| j| _ |r%| j D ]}||_q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   r*   mpl_disconnectr&   mpl_connect
_key_pressr   valuesr)   )r   r)   update_toolsr	   r   r   r   r'   O   s   
zToolManager.set_figurec                 C   s   | 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funcr   r   r   toolmanager_connectc   s   zToolManager.toolmanager_connectc                 C   s   | 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   cidr   r   r   toolmanager_disconnect   s   
z"ToolManager.toolmanager_disconnectc                 C   s.   |du r| }d}t |||}| j|| dS )z!Emit a `ToolManagerMessageEvent`.Ntool_message_event)r   r"   process)r   r   r   r5   eventr   r   r   message_event   s
   zToolManager.message_eventc                 C   r,   )zCurrently toggled tools.)r    r+   r   r   r   active_toggle   r-   zToolManager.active_togglec                    s    fd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                    s   g | ]
\}}| kr|qS r   r   ).0kir   r   r   
<listcomp>   s    z/ToolManager.get_tool_keymap.<locals>.<listcomp>)r   items)r   r   keysr   rC   r   get_tool_keymap   s   zToolManager.get_tool_keymapc                 C   s   |  |D ]}| j|= qd S r   )rG   r   )r   r   rA   r   r   r   _remove_keys   s   
zToolManager._remove_keysc              	   C   sv   || j vrt| d| | t|tr|g}|D ]}|| jv r3td| d| j|  d|  || j|< q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   KeyErrorrH   
isinstancestrr   r   warn_external)r   r   keyrA   r   r   r   update_keymap   s   



zToolManager.update_keymapc                 C   s^   |  |}|  t|ddr| |d | | d}t|| |}| j|| | j|= dS )z
        Remove tool named *name*.

        Parameters
        ----------
        name : str
            Name of the tool.
        toggledFtoolmanagertool_removed_eventN)	get_tooldestroygetattrtrigger_toolrH   r   r"   r<   r   )r   r   r	   r5   r=   r   r   r   remove_tool   s   


zToolManager.remove_toolc                 O   s  |  |}|stdt| || jv rtd | j| S |dkr7|tjkr7tjdd|j	 d|j
 dd || |g|R i |}|| j|< |jd	urT| ||j t|tjr{|jd	u rh| jd	t  n| j|jd	 |jr{| |d	d	d	 || 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 : class_like, i.e. str or type
            Reference to find the class of the Tool to added.

        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)_get_cls_to_instantiate
ValueErrorrK   r   r   rL   toolsSetCursorBasewarn_deprecatedr   r   default_keymaprN   rJ   ToolToggleBaseradio_groupr    
setdefaultsetrO   _handle_toggler'   r)   _tool_added_event)r   r   r	   argskwargstool_clstool_objr   r   r   add_tool   s6   



	



zToolManager.add_toolc                 C   s"   d}t || |}| j|| d S )Ntool_added_event)r   r"   r<   )r   r	   r5   r=   r   r   r   rc   "  s   zToolManager._tool_added_eventc                 C   s   |j }|du r%|j| jd v r| jd |j dS | jd |j dS | j| |jkr0d}n| j| du r;|j}n| | j| | || |j}|| j|< dS )a  
        Toggle tools, need to untoggle prior to using other Toggle tool.
        Called from trigger_tool.

        Parameters
        ----------
        tool : `.ToolBase`
        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.
        N)r_   r   r    removeaddrU   )r   r	   r   r   r
   r_   rO   r   r   r   rb   '  s$   zToolManager._handle_togglec                 C   sV   t |tr#|t v rt | }nd}t|t t |gd}t||d}t|r)|S d S )Nbackend_tools   F)rJ   rK   globals
__import__localsrT   callable)r   callback_classmodcurrent_moduler   r   r   rX   T  s   

z#ToolManager._get_cls_to_instantiatec                 C   s\   |  |}|du rdS |du r| }| |||| d| }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)rR   _trigger_toolr   r"   r<   )r   r   r   r   r
   r	   r5   r=   r   r   r   rU   e  s   
zToolManager.trigger_toolc                 C   s8   |  |}t|tjr| |||| |||| dS )zActually trigger a tool.N)rR   rJ   rZ   r^   rb   trigger)r   r   r   r   r
   r	   r   r   r   ru     s   
zToolManager._trigger_toolc                 C   sF   |j d u s
| j rd S | j|j d }|d u rd S | j||d d S )N)r   )rM   r$   lockedr   getrU   )r   r=   r   r   r   r   r1     s   zToolManager._key_pressc                 C   r,   )z,A dict mapping tool name -> controlled tool.)r   r+   r   r   r   rZ     r-   zToolManager.toolsc                 C   sH   t |tjr|j| jv r|S || jvr|rt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)rJ   rZ   ToolBaser   r   r   rL   )r   r   warnr   r   r   rR     s   

zToolManager.get_toolr   )T)NNN)r   r   r   r   r   propertyr*   r)   setterr'   r7   r:   r>   r?   rG   rH   rN   rV   rh   rc   rb   rX   rU   ru   r1   rZ   rR   r   r   r   r   r   !   s:    





	
B-

	
r   )
matplotlibr   r   r   matplotlib.backend_toolsrl   rZ   r   r   r   r   r   r   r   r   <module>   s    	