o
    ~ôj.  ã                   @   sV   d dl mZmZmZ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Úbackend_toolsÚcbookÚwidgetsc                   @   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   úl/var/www/html/academy/tools/voices/clone/sv-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d*d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!d"„Zd#d$„ Zed%d&„ ƒZd*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                 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*   E   ó   zToolManager.figurec                 C   s   |   |¡ d S r   )r(   r)   r   r   r   r*   J   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*   Zupdate_toolsr
   r   r   r   r(   N   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_connectb   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   sT   |   |¡}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_toolrH   r   r#   r<   r   r   )r   r   r
   r=   r   r   r   Úremove_toolÆ   s   
	
zToolManager.remove_toolc                 O   sö   t  t| jƒ|¡}|stdt|ƒ ƒ‚|| jv r"t d¡ | j| S || |g|¢R i |¤Ž}|| j|< |j	dur?|  
||j	¡ t|t jƒre|jdu rS| j dtƒ ¡ n| j |jd¡ |jre|  |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Útyper+   Ú
ValueErrorrK   r   r   rL   Údefault_keymaprN   rJ   ÚToolToggleBaseÚradio_groupr!   Ú
setdefaultÚsetrO   Ú_handle_toggler(   r*   r   r#   r<   r   )r   r   r
   ÚargsÚkwargsÚtool_clsZtool_objr=   r   r   r   Úadd_tool×   s(   





zToolManager.add_toolc                 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 )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)r\   r   r!   ÚremoveÚaddrT   )r   r
   r   r   r\   rO   r   r   r   r_     s$   ÿýzToolManager._handle_togglec                 C   st   |   |¡}|du rdS |du r| }t|tjƒ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   rJ   r   r[   r_   Útriggerr   r#   r<   )r   r   r	   r   r   r
   r5   r=   r   r   r   rT   ;  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    ÚgetrT   )r   r=   r   r   r   r   r2   Z  s   zToolManager._key_pressc                 C   r-   )z,A dict mapping tool name -> controlled tool.)r   r,   r   r   r   Útoolsc  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   r   ÚToolBaser   r   r   rL   )r   r   Úwarnr   r   r   rR   h  s   
ÿ
zToolManager.get_toolr   )T)NNN)r   r   r   r   r   Úpropertyr+   r*   Úsetterr(   r7   r:   r>   r?   rG   rH   rN   rU   rc   r_   rT   r2   ri   rR   r   r   r   r   r       s4    





	
9
+	
r   N)	Ú
matplotlibr   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s
    	