
    g                        d Z ddlZddlZddlZddlZddlmZ ddlZddlm	Z	 ddl
ZddlZddlmZ ddlmZmZ  G d dej$                        ZeZ e       ZdWd	Zd
 ZdZ G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z# G d  d!e      Z$ G d" d#e$      Z% G d$ d%e$      Z& G d& d'e      Z' G d( d)e      Z( G d* d+e(      Z) G d, d-e(      Z* G d. d/e(      Z+ G d0 d1e      Z, G d2 d3e      Z- G d4 d5e      Z. G d6 d7e.      Z/ G d8 d9e.      Z0 G d: d;e      Z1 G d< d=e      Z2i d>e)d?e*d@e+dAe/dBe0dCe,dDe-dEe!dFe"dGe#dHedIe dJe&dKe%dLeee'dMeee1e2dNZ3dOg dPgdQg dRgdSdDdTgggZ4e3fdUZ5e4fdVZ6y)XaR  
Abstract base classes define the primitives for Tools.
These tools are used by `matplotlib.backend_managers.ToolManager`

:class:`ToolBase`
    Simple stateless tool

:class:`ToolToggleBase`
    Tool that has two states, only one Toggle tool can be
    active at any given time for the same
    `matplotlib.backend_managers.ToolManager`
    N)SimpleNamespace)WeakKeyDictionary)Gcf)_apicbookc                       e Zd ZdZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z	 ej
                         Z
 ej
                         Z ej
                         Zy)Cursorsz!Backend-independent cursor types.N)__name__
__module____qualname____doc__enumautoPOINTERHANDSELECT_REGIONMOVEWAITRESIZE_HORIZONTALRESIZE_VERTICAL     K/var/www/html/venv/lib/python3.12/site-packages/matplotlib/backend_tools.pyr	   r	      sa    +diikG499;DDIIKM499;D499;D!		diikOr   r	   c                 l    |t        j                  t        |       S t        j	                  | |f       |S )zBDecorator registering *tool_cls* as a tool class for *canvas_cls*.)	functoolspartial_register_tool_class_tool_registryadd)
canvas_clstool_clss     r   r   r   4   s4      !5zBB
H-.Or   c                 |    | j                   D ],  }t        j                  |      D ]  }||ft        v s|c c S  . |S )z:Find a subclass of *tool_cls* registered for *canvas_cls*.)__mro__r   recursive_subclassesr   )r    r!   canvas_parent
tool_childs       r   _find_tool_classr'   <   sK    #++ "33H= 	"Jz*n<!!	"" Or   viewposc                       e Zd ZdZdZ	 dZ	 dZ	 d Z ed d      Z	 ed d      Z
 ed	 d
      Zd Z ed d d      Zd ZddZy)ToolBasez
    Base tool class.

    A base tool, only implements `trigger` method or no method at all.
    The tool is instantiated by `matplotlib.backend_managers.ToolManager`.
    Nc                 .    || _         || _        d | _        y N)_name_toolmanager_figure)selftoolmanagernames      r   __init__zToolBase.__init__n   s    
'r   c                     | j                   S r,   )r-   r0   s    r   <lambda>zToolBase.<lambda>t   s
    TZZ r   z@The tool id (str, must be unique among tools of a tool manager).)docc                     | j                   S r,   )r.   r5   s    r   r6   zToolBase.<lambda>w   s    T&& r   z+The `.ToolManager` that controls this tool.c                 J    | j                   | j                   j                  S d S r,   )r/   canvasr5   s    r   r6   zToolBase.<lambda>z   s    DLL,DT\\(( $ r   z8The canvas of the figure affected by this tool, or None.c                     || _         y r,   r/   r0   figures     r   
set_figurezToolBase.set_figure}   s	    r   c                     | j                   S r,   r<   r5   s    r   r6   zToolBase.<lambda>   s
    T\\ r   c                 $    | j                  |      S r,   )r?   r=   s     r   r6   zToolBase.<lambda>   s    T__V4 r   z*The Figure affected by this tool, or None.c                 .    t        | j                        S )z
        Return a placeholder object with a single `canvas` attribute.

        This is useful to reuse the implementations of tools already provided
        by the classic Toolbars.
        )r:   )r   r:   r5   s    r   "_make_classic_style_pseudo_toolbarz+ToolBase._make_classic_style_pseudo_toolbar   s     dkk22r   c                      y)at  
        Called when this tool gets used.

        This method is called by `.ToolManager.trigger_tool`.

        Parameters
        ----------
        event : `.Event`
            The canvas event that caused this tool to be called.
        sender : object
            Object that requested the tool to be triggered.
        data : object
            Extra data.
        Nr   r0   sendereventdatas       r   triggerzToolBase.trigger   s     	r   r,   )r
   r   r   r   default_keymapdescriptionimager3   propertyr2   r1   r:   r?   r>   rC   rI   r   r   r   r*   r*   I   s     N K E	
 NPD &9;K NFHF ! 	58:F3r   r*   c                   f     e Zd ZdZdZ	 dZ	 dZ	  fdZd
dZd
dZ	d
dZ
ed        Z fd	Z xZS )ToolToggleBaseac  
    Toggleable tool.

    Every time it is triggered, it switches between enable and disable.

    Parameters
    ----------
    ``*args``
        Variable length argument to be used by the Tool.
    ``**kwargs``
        `toggled` if present and True, sets the initial state of the Tool
        Arbitrary keyword arguments to be consumed by the Tool
    NFc                 f    |j                  d| j                        | _        t        |   |i | y )Ntoggled)popdefault_toggled_toggledsuperr3   r0   argskwargs	__class__s      r   r3   zToolToggleBase.__init__   s-    

9d.B.BC$)&)r   c                     | j                   r| j                  |       n| j                  |       | j                    | _         y)z5Calls `enable` or `disable` based on `toggled` value.N)rT   disableenablerE   s       r   rI   zToolToggleBase.trigger   s/    ==LLKK MM)r   c                      y)zg
        Enable the toggle tool.

        `trigger` calls this method when `toggled` is False.
        Nr   r0   rG   s     r   r\   zToolToggleBase.enable        	r   c                      y)ay  
        Disable the toggle tool.

        `trigger` call this method when `toggled` is True.

        This can happen in different circumstances.

        * Click on the toolbar tool button.
        * Call to `matplotlib.backend_managers.ToolManager.trigger_tool`.
        * Another `ToolToggleBase` derived tool is triggered
          (from the same `.ToolManager`).
        Nr   r^   s     r   r[   zToolToggleBase.disable   s     	r   c                     | j                   S )zState of the toggled tool.)rT   r5   s    r   rQ   zToolToggleBase.toggled   s     }}r   c                     | j                   }|r&| j                  r| j                  | d        nd| _        t        |   |       |r|r| j                  | d        y d| _        y y )NFT)rQ   r>   rI   rT   rU   r?   )r0   r>   rQ   rY   s      r   r?   zToolToggleBase.set_figure   s\    ,,{{T4( !&6"T4( !% r   r,   )r
   r   r   r   radio_groupcursorrS   r3   rI   r\   r[   rM   rQ   r?   __classcell__rY   s   @r   rO   rO      sX     K F0O#**  % %r   rO   c                   >     e Zd ZdZ fdZ fdZd Zd Zd Z xZ	S )ToolSetCursorz
    Change to the current cursor while inaxes.

    This tool, keeps track of all `ToolToggleBase` derived tools, and updates
    the cursor when a tool gets triggered.
    c                    t        |   |i | d | _        d | _        t        j
                  | _        | j                  | _        | j                  j                  d| j                         | j                  j                  j                         D ]<  }| j                  t        j                  j                  d| j                  |             > y )Ntool_added_event)rU   r3   _id_drag_current_toolcursorsr   _default_cursor_last_cursorr1   toolmanager_connect_add_tool_cbktoolsvaluesmplbackend_managers	ToolEvent)r0   rW   rX   toolrY   s       r   r3   zToolSetCursor.__init__   s    $)&)!& 00,,-?-1-?-?	A$$**113 	=Ds33=="D$4$4d < =	=r   c                     | j                   r%| j                  j                  | j                          t        |   |       |r,| j                  j                  d| j                        | _         y y Nmotion_notify_event)rk   r:   mpl_disconnectrU   r?   mpl_connect_set_cursor_cbkr0   r>   rY   s     r   r?   zToolSetCursor.set_figure  sV    ==KK&&t}}56" KK33%t';';=DM r   c                     t        |j                  dd      >| j                  j                  d|j                  j                   | j
                         yy)zProcess every newly added tool.rd   Ntool_trigger_)getattrrw   r1   rp   r2   _tool_trigger_cbkr^   s     r   rq   zToolSetCursor._add_tool_cbk  sJ    5::x.:00

0143I3IK ;r   c                     |j                   j                  r|j                   nd | _        | j                  |j                         y r,   )rw   rQ   rl   r}   canvaseventr^   s     r   r   zToolSetCursor._tool_trigger_cbk  s0    +0::+=+=UZZ4U../r   c                    |r| j                   sy | j                  rt        |dd       r|j                  j	                         ro| j
                  | j                  j                  k7  rK| j                   j                  | j                  j                         | j                  j                  | _        y y | j
                  | j                  k7  r7| j                   j                  | j                         | j                  | _        y y )Ninaxes)	r:   rl   r   r   get_navigatero   rd   
set_cursorrn   r^   s     r   r}   zToolSetCursor._set_cursor_cbk  s    DKK75(D#ALL--/  D$6$6$=$==&&t'9'9'@'@A$($6$6$=$=! > $"6"66KK""4#7#78 $ 4 4D 7r   )
r
   r   r   r   r3   r?   rq   r   r}   re   rf   s   @r   rh   rh      s"    
==K0
5r   rh   c                   2     e Zd ZdZ fdZ fdZd Z xZS )ToolCursorPositionz
    Send message with the current pointer position.

    This tool runs in the background reporting the position of the cursor.
    c                 2    d | _         t        |   |i | y r,   )rk   rU   r3   rV   s      r   r3   zToolCursorPosition.__init__1  s    $)&)r   c                     | j                   r%| j                  j                  | j                          t        |   |       |r,| j                  j                  d| j                        | _         y y ry   )rk   r:   r{   rU   r?   r|   send_messager~   s     r   r?   zToolCursorPosition.set_figure5  sV    ==KK&&t}}56" KK33%t'8'8:DM r   c                     | j                   j                  j                         ryddlm} |j                  |      }| j                   j                  ||        y)z=Call `matplotlib.backend_managers.ToolManager.message_event`.Nr   )NavigationToolbar2)r1   messagelocklockedmatplotlib.backend_basesr   _mouse_event_to_messagemessage_event)r0   rG   r   messages       r   r   zToolCursorPosition.send_message=  sF    ''..0?$<<UC&&w5r   )r
   r   r   r   r3   r?   r   re   rf   s   @r   r   r   +  s    
*:6r   r   c                   $    e Zd ZdZddZd Zd Zy)RubberbandBasezDraw and remove a rubberband.Nc                     | j                   j                  j                  j                  |      sy| | j                  |  y| j                          y)z<Call `draw_rubberband` or `remove_rubberband` based on data.N)r>   r:   
widgetlock	availabledraw_rubberbandremove_rubberbandrE   s       r   rI   zRubberbandBase.triggerI  sE    {{!!,,66v> D  $'""$r   c                     t         )zY
        Draw rubberband.

        This method must get implemented per backend.
        )NotImplementedError)r0   rH   s     r   r   zRubberbandBase.draw_rubberbandR  s
     "!r   c                      y)z]
        Remove rubberband.

        This method should get implemented per backend.
        Nr   r5   s    r   r   z RubberbandBase.remove_rubberbandZ  r_   r   r,   )r
   r   r   r   rI   r   r   r   r   r   r   r   G  s    '%"r   r   c                   .    e Zd ZdZdZ ed       ZddZy)ToolQuit/Tool to call the figure manager destroy method.zQuit the figurec                 (    t         j                  d   S )Nzkeymap.quitrt   rcParamsr5   s    r   r6   zToolQuit.<lambda>g      3<<+F r   Nc                 B    t        j                  | j                         y r,   )r   destroy_figr>   rE   s       r   rI   zToolQuit.triggeri  s    $r   r,   r
   r   r   r   rK   rM   rJ   rI   r   r   r   r   r   c  s    9#KFGN%r   r   c                   .    e Zd ZdZdZ ed       ZddZy)ToolQuitAllr   zQuit all figuresc                 (    t         j                  d   S )Nzkeymap.quit_allr   r5   s    r   r6   zToolQuitAll.<lambda>q  s    3<<8I+J r   Nc                 ,    t        j                          y r,   )r   destroy_allrE   s       r   rI   zToolQuitAll.triggers  s    r   r,   r   r   r   r   r   r   m  s    9$KJKNr   r   c                   .    e Zd ZdZdZ ed       ZddZy)ToolGridz-Tool to toggle the major grids of the figure.zToggle major gridsc                 (    t         j                  d   S )Nkeymap.gridr   r5   s    r   r6   zToolGrid.<lambda>{  r   r   Nc                 V   t        t        j                               }t        j                  ||      5  t        j                  d|i      5  t
        j                  j                  || j                  j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nkeyr   struuiduuid4r   _setattr_cmrt   
rc_contextbackend_baseskey_press_handlerr>   r:   r0   rF   rG   rH   sentinels        r   rI   zToolGrid.trigger}  s    tzz|$ 84 	KnnmX67	K//t{{7I7IJ	K 	K 	K 	K 	K 	K#   B5BBB	BB(r,   r   r   r   r   r   r   w  s    7&KFGNKr   r   c                   .    e Zd ZdZdZ ed       ZddZy)ToolMinorGridz7Tool to toggle the major and minor grids of the figure.zToggle major and minor gridsc                 (    t         j                  d   S )Nkeymap.grid_minorr   r5   s    r   r6   zToolMinorGrid.<lambda>      3<<8K+L r   Nc                 V   t        t        j                               }t        j                  ||      5  t        j                  d|i      5  t
        j                  j                  || j                  j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r   r   r   s        r   rI   zToolMinorGrid.trigger  s    tzz|$ 84 	Knn18<=	K//t{{7I7IJ	K 	K 	K 	K 	K 	Kr   r,   r   r   r   r   r   r     s    A0KLMNKr   r   c                   .    e Zd ZdZdZ ed       ZddZy)ToolFullScreenzTool to toggle full screen.zToggle fullscreen modec                 (    t         j                  d   S )Nzkeymap.fullscreenr   r5   s    r   r6   zToolFullScreen.<lambda>  r   r   Nc                 `    | j                   j                  j                  j                          y r,   )r>   r:   managerfull_screen_togglerE   s       r   rI   zToolFullScreen.trigger  s    ""557r   r,   r   r   r   r   r   r     s    %*KLMN8r   r   c                   4     e Zd ZdZd fd	ZddZddZ xZS )AxisScaleBasez3Base Tool to toggle between linear and logarithmic.c                 B    |j                   y t        | 	  |||       y r,   )r   rU   rI   )r0   rF   rG   rH   rY   s       r   rI   zAxisScaleBase.trigger  s     <<t,r   c                     | j                  |j                  d       | j                  j                  j	                          y )Nlog	set_scaler   r>   r:   	draw_idler^   s     r   r\   zAxisScaleBase.enable  s*    u||U+$$&r   c                     | j                  |j                  d       | j                  j                  j	                          y )Nlinearr   r^   s     r   r[   zAxisScaleBase.disable  s*    u||X.$$&r   r,   )r
   r   r   r   rI   r\   r[   re   rf   s   @r   r   r     s    =-
''r   r   c                   ,    e Zd ZdZdZ ed       Zd Zy)
ToolYScalezCTool to toggle between linear and logarithmic scales on the Y axis.zToggle scale Y axisc                 (    t         j                  d   S )Nzkeymap.yscaler   r5   s    r   r6   zToolYScale.<lambda>      3<<+H r   c                 &    |j                  |       y r,   )
set_yscaler0   axscales      r   r   zToolYScale.set_scale      
er   Nr
   r   r   r   rK   rM   rJ   r   r   r   r   r   r         M'KHINr   r   c                   ,    e Zd ZdZdZ ed       Zd Zy)
ToolXScalezCTool to toggle between linear and logarithmic scales on the X axis.zToggle scale X axisc                 (    t         j                  d   S )Nzkeymap.xscaler   r5   s    r   r6   zToolXScale.<lambda>  r   r   c                 &    |j                  |       y r,   )
set_xscaler   s      r   r   zToolXScale.set_scale  r   r   Nr   r   r   r   r   r     r   r   r   c                   \     e Zd ZdZ fdZd Zd Zd ZddZd Z	ddZ
d	 Zd
 Zd Z xZS )ToolViewsPositionsa%  
    Auxiliary Tool to handle changes in views and positions.

    Runs in the background and should get used by all the tools that
    need to access the figure's history of views and positions, e.g.

    * `ToolZoom`
    * `ToolPan`
    * `ToolHome`
    * `ToolBack`
    * `ToolForward`
    c                 ~    t               | _        t               | _        t               | _        t	        |   |i | y r,   )r   views	positions
home_viewsrU   r3   rV   s      r   r3   zToolViewsPositions.__init__  s3    &(
*,+-$)&)r   c                      | j                   vrt        j                          j                   |<   t        j                          j                  |<   t	                j
                  |<    j                  |       |j                   fd       yy)z;Add the current figure to the stack of views and positions.c                 &    j                  |       S r,   )update_home_views)figr0   s    r   r6   z/ToolViewsPositions.add_figure.<locals>.<lambda>  s    d.D.DS.I r   N)r   r   _Stackr   r   r   push_currentadd_axobserverr=   s   ` r   
add_figurezToolViewsPositions.add_figure  sl     #!&DJJv%*\\^DNN6"&7&9DOOF#f%!!"IJ $r   c                     || j                   v rh| j                   |   j                          | j                  |   j                          | j                  |   j                          | j	                          yy)zReset the Axes stack.N)r   clearr   r   r   r=   s     r   r   zToolViewsPositions.clear  s^    TZZJJv$$&NN6"((*OOF#))+""$	  r   c                 &    | j                   | j                            }|y | j                  | j                            }|y| j                  | j                     }| j                  j	                         }|D ]"  }||v r||   }n||   }|j                  |       $ t        |      j                  |      r7|D ]2  }|j                  ||   d   d       |j                  ||   d   d       4 | j                  j                  j                          y)a  
        Update the view limits and position for each Axes from the current
        stack position. If any Axes are present in the figure that aren't in
        the current stack position, use the home view limits for those Axes and
        don't update *any* positions.
        Nr   original   active)r   r>   r   r   get_axes	_set_viewsetissubset_set_positionr:   r   )r0   r   posr   all_axesacur_views          r   update_viewzToolViewsPositions.update_view  s    (

4;;')=)dnnT[[)+;__T[[1
;;'') 	"AEz 8%a=KK!	" x=!!#& 5Aq	:6Aq	845
 	$$&r   c                 8   |s| j                   }t               }t               }|j                         D ])  }|j                         ||<   | j	                  |      ||<   + | j
                  |   j                  |       | j                  |   j                  |       y)zY
        Push the current view limits and position onto their respective stacks.
        N)r>   r   r   	_get_view	_axes_posr   pushr   )r0   r>   r   r  r  s        r   r   zToolViewsPositions.push_current  s     [[F!#!" 	'A{{}E!H^^A&CF	' 	

6&v##C(r   c                 |    |j                  d      j                         |j                         j                         fS )aY  
        Return the original and modified positions for the specified Axes.

        Parameters
        ----------
        ax : matplotlib.axes.Axes
            The `.Axes` to get the positions for.

        Returns
        -------
        original_position, modified_position
            A tuple of the original and modified positions.
        T)get_positionfrozen)r0   r   s     r   r  zToolViewsPositions._axes_pos  s6     %,,.!((*, 	,r   c                     |s| j                   }|j                         D ]4  }|| j                  |   vs|j                         | j                  |   |<   6 y)zm
        Make sure that ``self.home_views`` has an entry for all Axes present
        in the figure.
        N)r>   r   r   r  )r0   r>   r  s      r   r   z$ToolViewsPositions.update_home_views+  sP     [[F" 	;A//-.[[]'*	;r   c                     | j                   | j                     j                          | j                  | j                     j                          y)z2Recall the first view and position from the stack.N)r   r>   homer   r5   s    r   r  zToolViewsPositions.home7  4    

4;;$$&t{{#((*r   c                     | j                   | j                     j                          | j                  | j                     j                          y)z2Back one step in the stack of views and positions.N)r   r>   backr   r5   s    r   r  zToolViewsPositions.back<  r  r   c                     | j                   | j                     j                          | j                  | j                     j                          y)z5Forward one step in the stack of views and positions.N)r   r>   forwardr   r5   s    r   r  zToolViewsPositions.forwardA  s4    

4;;'')t{{#++-r   r,   )r
   r   r   r   r3   r   r   r  r   r  r   r  r  r  re   rf   s   @r   r   r     s;    *
K%'>),$
;+
+
.r   r   c                       e Zd ZdZdZddZy)ViewsPositionsBasez8Base class for `ToolHome`, `ToolBack` and `ToolForward`.Nc                 >   | j                   j                  t              j                  | j                          t        | j                   j                  t              | j                                | j                   j                  t              j                          y r,   )r1   get_tool_views_positionsr   r>   r   _on_triggerr  rE   s       r   rI   zViewsPositionsBase.triggerL  sr    !!"23>>t{{K	"  ))*:;  	" 	$!!"23??Ar   r,   )r
   r   r   r   r  rI   r   r   r   r  r  G  s    BKBr   r  c                   .    e Zd ZdZdZdZ ed       ZdZy)ToolHomez!Restore the original view limits.zReset original viewzmpl-data/images/homec                 (    t         j                  d   S )Nzkeymap.homer   r5   s    r   r6   zToolHome.<lambda>X  r   r   r  N	r
   r   r   r   rK   rL   rM   rJ   r  r   r   r   r  r  S  s    +'K"EFGNKr   r  c                   .    e Zd ZdZdZdZ ed       ZdZy)ToolBackz#Move back up the view limits stack.zBack to previous viewzmpl-data/images/backc                 (    t         j                  d   S )Nzkeymap.backr   r5   s    r   r6   zToolBack.<lambda>a  r   r   r  Nr  r   r   r   r   r   \  s    -)K"EFGNKr   r   c                   .    e Zd ZdZdZdZ ed       ZdZy)ToolForwardz#Move forward in the view lim stack.zForward to next viewzmpl-data/images/forwardc                 (    t         j                  d   S )Nzkeymap.forwardr   r5   s    r   r6   zToolForward.<lambda>j  s    3<<8H+I r   r  Nr  r   r   r   r#  r#  e  s    -(K%EIJNKr   r#  c                       e Zd ZdZdZdZy)ConfigureSubplotsBasez,Base tool for the configuration of subplots.zConfigure subplotszmpl-data/images/subplotsN)r
   r   r   r   rK   rL   r   r   r   r&  r&  n  s    6&K&Er   r&  c                   *    e Zd ZdZdZdZ ed       Zy)SaveFigureBasezBase tool for figure saving.zSave the figurezmpl-data/images/filesavec                 (    t         j                  d   S )Nzkeymap.saver   r5   s    r   r6   zSaveFigureBase.<lambda>z  r   r   N)r
   r   r   r   rK   rL   rM   rJ   r   r   r   r(  r(  u  s    &#K&EFGNr   r(  c                   D     e Zd ZdZ fdZddZddZd fd	Zd Z xZ	S )ZoomPanBasez(Base class for `ToolZoom` and `ToolPan`.c                     t        |   |  d | _        d | _        d | _        d | _        d | _        d| _        d| _        t        j                         | j                  z
  | _
        y )Ng       @g      ?)rU   r3   _button_pressed_xypress_idPress
_idRelease	_idScroll
base_scalescrollthreshtime
lastscrollr0   rW   rY   s     r   r3   zZoomPanBase.__init__  s[    $#))+d&7&77r   c                    | j                   j                  j                  |        | j                   j                  j                  d| j                        | _        | j                   j                  j                  d| j                        | _        | j                   j                  j                  d| j                        | _	        y)z1Connect press/release events and lock the canvas.button_press_eventbutton_release_eventscroll_eventN)
r>   r:   r   r|   _pressr/  _releaser0  scroll_zoomr1  r^   s     r   r\   zZoomPanBase.enable  s    %%d+**66 $++/++,,88"DMM3++77D,,.r   c                    | j                          | j                  j                  j                  j	                  |        | j                  j                  j                  | j                         | j                  j                  j                  | j                         | j                  j                  j                  | j                         y)z7Release the canvas and disconnect press/release events.N)	_cancel_actionr>   r:   r   releaser{   r/  r0  r1  r^   s     r   r[   zZoomPanBase.disable  s    %%--d3))$--8))$//:))$..9r   c                 @   | j                   j                  t              j                  | j                         t
        |   |||       | j                  r| j                  j                         nd }| j                  j                  D ]  }|j                  |        y r,   )r1   r  r  r   r>   rU   rI   rQ   r2   upperaxesset_navigate_mode)r0   rF   rG   rH   new_navigate_moder   rY   s         r   rI   zZoomPanBase.trigger  sx    !!"23>>t{{Kt,15DIIOO-4++"" 	4B  !23	4r   c                    |j                   y |j                  dk(  r| j                  }n!|j                  dk(  rd| j                  z  }nd}|j                   }|j                  |j                  |j
                  |g       t        j                         | j                  z
  | j                  k  r-| j                  j                  t              j                          | j                  j                  j                          t        j                         | _        | j                  j                  t              j!                          y )Nupdownr   )r   buttonr2  _set_view_from_bboxxyr4  r5  r3  r1   r  r  r  r>   r:   r   r   )r0   rG   sclr   s       r   r=  zZoomPanBase.scroll_zoom  s    <<<<4//C\\V#DOO#C C\\
#67 IIK'4+<+<<%%&67<<>$$&))+!!"23@@Br   r,   )
r
   r   r   r   r3   r\   r[   rI   r=  re   rf   s   @r   r+  r+  }  s     2	8.:4Cr   r+  c                   |     e Zd ZdZdZdZ ed       Zej                  Z
dZ fdZd Zd Zd	 Zd
 Zd Zd Z xZS )ToolZoomz.A Tool for zooming using a rectangle selector.zZoom to rectanglezmpl-data/images/zoom_to_rectc                 (    t         j                  d   S )Nzkeymap.zoomr   r5   s    r   r6   zToolZoom.<lambda>  r   r   defaultc                 ,    t        |   |  g | _        y r,   )rU   r3   	_ids_zoomr6  s     r   r3   zToolZoom.__init__  s    $r   c                    | j                   D ]'  }| j                  j                  j                  |       ) | j                  j                  d|        | j                  j                  j                          d | _        d | _        g | _         y )N
rubberband)	rS  r>   r:   r{   r1   trigger_toolr   r.  r-  )r0   zoom_ids     r   r?  zToolZoom._cancel_action  sr    ~~ 	7GKK--g6	7%%lD9$$&#r   c           	      t   | j                   r| j                          |j                  dk(  rd| _        n(|j                  dk(  rd| _        n| j                          y|j                  |j
                  }}g | _        t        | j                  j                               D ]m  \  }}|	||j                  |      s|j                         s/|j                         s@| j                  j                  |||||j                         f       o | j                  j                  j!                  d| j"                        }| j                  j                  j!                  d| j$                        }| j                  j                  j!                  d| j&                        }|||f| _         |j(                  | _        y)z<Callback for mouse button presses in zoom-to-rectangle mode.r      Nrz   key_press_eventkey_release_event)rS  r?  rI  r-  rK  rL  r.  	enumerater>   r   in_axesr   can_zoomappendr  r:   r|   _mouse_move_switch_on_zoom_mode_switch_off_zoom_moder   
_zoom_mode)	r0   rG   rK  rL  ir  id1id2id3s	            r   r;  zToolZoom._press  sa   
 >>!<<1#$D \\Q#$D !ww1dkk2245 	BDAq!-AIIe4DNN$$$aAq!++-%@A	B
 kk  ,,!4#3#35kk  ,,t88:kk  ,,!;!;= c3))r   c                 H    |j                   | _        | j                  |       y r,   )r   rc  r`  r^   s     r   ra  zToolZoom._switch_on_zoom_mode  s    ))r   c                 4    d | _         | j                  |       y r,   )rc  r`  r^   s     r   rb  zToolZoom._switch_off_zoom_mode  s    r   c                    | j                   r|j                  |j                  }}| j                   d   \  }}}}}t        j                  ||g||gg|j
                  j                  |j
                  j                        \  \  }	}
\  }}| j                  dk(  r|j
                  j                  \  }
}n(| j                  dk(  r|j
                  j                  \  }	}| j                  j                  d| |	|
||f       yy)z3Callback for mouse moves in zoom-to-rectangle mode.r   rK  rL  rU  )rH   N)r.  rK  rL  npclipbboxminmaxrc  	intervaly	intervalxr1   rV  )r0   rG   rK  rL  lastxlastyr  indviewx1y1x2y2s                r   r`  zToolZoom._mouse_move  s     ==77EGGqA)-q)9&E5!S$!#!Q(!&&**affjj"BHRhr2#%))BC'))B))d"b"b)9 * ; r   c                    | j                   D ]'  }| j                  j                  j                  |       ) g | _         | j                  s| j                          yg }| j                  D ]  }|j                  |j                  }}|\  }}}	}
t        ||z
        dk  st        ||z
        dk  r| j                           yt        fd|D              }t        fd|D              }|j                         | j                  dk(  rd}n| j                  dk(  rd}nj                  ||||f|| j                  ||        d| _        | j                  j                  t               j#                          | j                          y)	z=Callback for mouse button releases in zoom-to-rectangle mode.N   c              3   ^   K   | ]$  }j                         j                  |       & y wr,   )get_shared_x_axesjoined.0a1r  s     r   	<genexpr>z$ToolZoom._release.<locals>.<genexpr>&  '     N++-44Q;N   *-c              3   ^   K   | ]$  }j                         j                  |       & y wr,   )get_shared_y_axesr~  r  s     r   r  z$ToolZoom._release.<locals>.<genexpr>'  r  r  r   inrY  out)rS  r>   r:   r{   r.  r?  rK  rL  absanyr_  r-  rJ  rc  r1   r  r  r   )r0   rG   rW  done_axcur_xypressrK  rL  rr  rs  _indru  twinxtwiny	directionr  s                 @r   r<  zToolZoom._release  sg    ~~ 	7GKK--g6	7}}!== 	AK77EGGqA*5'E5!T41u9~!SU^a%7##% NgNNENgNNENN1##q( 	%%*!	!!5%A"6	"&//5%A)	A. !!"23@@Br   )r
   r   r   r   rK   rL   rM   rJ   rm   r   rd   rc   r3   r?  r;  ra  rb  r`  r<  re   rf   s   @r   rO  rO    sO    8%K*EFGN""FK $D  ;&r   rO  c                   p     e Zd ZdZ ed       ZdZdZej                  Z
dZ fdZd Zd Zd	 Zd
 Z xZS )ToolPanz*Pan Axes with left mouse, zoom with right.c                 (    t         j                  d   S )Nz
keymap.panr   r5   s    r   r6   zToolPan.<lambda><  s    3<<+E r   z)Pan axes with left mouse, zoom with rightzmpl-data/images/moverQ  c                 ,    t        |   |  d | _        y r,   )rU   r3   rk   r6  s     r   r3   zToolPan.__init__B  s    $r   c                    d | _         g | _        | j                  j                  j	                  | j
                         | j                  j                  j                  |        | j                  j                  j                          y r,   )
r-  r.  r>   r:   r{   rk   r1   r   r@  r   r5   s    r   r?  zToolPan._cancel_actionF  s]    #))$--8$$,,T2$$&r   c                    |j                   dk(  rd| _        n(|j                   dk(  rd| _        n| j                          y |j                  |j                  }}g | _        t        | j                  j                               D ]  \  }}|	||j                  |      s|j                         s/|j                         s@|j                  |||j                          | j
                  j                  ||f       | j                  j                  |        | j                  j                   j#                  d| j$                        | _         y )Nr   rY  rz   )rI  r-  r?  rK  rL  r.  r\  r>   r   r]  r   can_pan	start_panr_  r1   r   r:   r|   r`  rk   )r0   rG   rK  rL  rd  r  s         r   r;  zToolPan._pressM  s   <<1#$D \\Q#$D !ww1dkk2245 	=DAq!-AIIe4DNN$Aq%,,/$$aV,  ,,T2 $ 2 2 > >)4+;+;!=	=r   c                    | j                   | j                          y | j                  j                  j	                  | j
                         | j                  j                  j                  |        | j                  D ]  \  }}|j                           | j                  s| j                          y | j                  j                  t              j                          | j                          y r,   )r-  r?  r>   r:   r{   rk   r1   r   r@  r.  end_panr  r  r   r0   rG   r  r  s       r   r<  zToolPan._releaseb  s    '!))$--8$$,,T2}} 	GAtIIK	}}!!!"23@@Br   c                     | j                   D ]A  \  }}|j                  | j                  |j                  |j                  |j
                         C | j                  j                  j                          y r,   )	r.  drag_panr-  r   rK  rL  r1   r:   r   r  s       r   r`  zToolPan._mouse_moves  s[    }} 	JGAt JJt++UYYI	J 	))+r   )r
   r   r   r   rM   rJ   rK   rL   rm   r   rd   rc   r3   r?  r;  r<  r`  re   rf   s   @r   r  r  9  sB    4EFN=K"E\\FK'=*",r   r  c                   N    e Zd ZdZ ed       ZdZed        Zd Z	d Z
d Zd Zy	)
ToolHelpBasez*Print tool list, shortcuts and descriptionc                 (    t         j                  d   S )Nzkeymap.helpr   r5   s    r   r6   zToolHelpBase.<lambda>}  r   r   zmpl-data/images/helpc                 l    t        |       dk(  r| S t        j                  dd|       j                         S )z
        Convert a shortcut string from the notation used in rc config to the
        standard notation for displaying shortcuts, e.g. 'ctrl+a' -> 'Ctrl+A'.
        r   z\+[A-Z]z+Shift\g<0>)lenresubtitle)key_sequences    r   format_shortcutzToolHelpBase.format_shortcut  s8     !$L 1Q 6 	Jz><@FFH	Jr   c                 n      j                   j                  |      }dj                   fd|D              S )Nz, c              3   @   K   | ]  }j                  |        y wr,   )r  )r  keymapr0   s     r   r  z3ToolHelpBase._format_tool_keymap.<locals>.<genexpr>  s     L&--f5Ls   )r1   get_tool_keymapjoin)r0   r2   keymapss   `  r   _format_tool_keymapz ToolHelpBase._format_tool_keymap  s.    ""2248yyLGLLLr   c                     t        | j                  j                  j                               D cg c]/  \  }}|j                  r|| j                  |      |j                  f1 c}}S c c}}w r,   )sortedr1   rr   itemsrK   r  )r0   r2   rw   s      r   _get_help_entrieszToolHelpBase._get_help_entries  sa    "()9)9)?)?)E)E)G"H%D$## t//5t7G7GH % 	% %s   4A)c                     | j                         }|D cg c]  } dj                  |  }}dj                  |      S c c}w )Nz
{}: {}
	{}
)r  formatr  )r0   entriesentrys      r   _get_help_textzToolHelpBase._get_help_text  sF    ((*>EFU(>((%0FFyy!! Gs   >c                     d}|j                  ddd      g}|| j                         D cg c]  } |j                   |  c}z  }d|d   z   dj                  |dd        z   d	z   S c c}w )
Nz*<tr><td>{}</td><td>{}</td><td>{}</td></tr>z<b>Action</b>z<b>Shortcuts</b>z<b>Description</b>z2<style>td {padding: 0px 4px}</style><table><thead>r   z</thead><tbody>r   z</tbody></table>)r  r  r  )r0   fmtrowsrows       r   _get_help_htmlzToolHelpBase._get_help_html  s    :

/1EG HT-C-C-EFcS!FF!#'7+.$tABx.)+=> 	? Gs   A%N)r
   r   r   rK   rM   rJ   rL   staticmethodr  r  r  r  r  r   r   r   r  r  {  s@    >KFGN"EJ JM%
"
?r   r  c                   ,    e Zd ZdZdZ ed       Zd Zy)ToolCopyToClipboardBasez)Tool to copy the figure to the clipboard.z#Copy the canvas figure to clipboardc                 (    t         j                  d   S )Nzkeymap.copyr   r5   s    r   r6   z ToolCopyToClipboardBase.<lambda>  r   r   c                 @    d}| j                   j                  ||        y )NzCopy tool is not available)r1   r   )r0   rW   rX   r   s       r   rI   zToolCopyToClipboardBase.trigger  s    .&&w5r   Nr   r   r   r   r  r    s    37KFGN6r   r  r  r  r  zoompansubplotssavegrid
grid_minor
fullscreenquitquit_allxscaleyscalepositionrd   )rU  helpcopy
navigation)r  r  r  zoompan)r  r  r  ior  c                 X    |j                         D ]  \  }}| j                  ||        y)aM  
    Add multiple tools to a `.ToolManager`.

    Parameters
    ----------
    toolmanager : `.backend_managers.ToolManager`
        Manager to which the tools are added.
    tools : {str: class_like}, optional
        The tools to add in a {name: tool} dict, see
        `.backend_managers.ToolManager.add_tool` for more info.
    N)r  add_tool)r1   rr   r2   rw   s       r   add_tools_to_managerr    s-     kkm )
dT4()r   c                 d    |D ]+  \  }}t        |      D ]  \  }}| j                  |||        - y)a  
    Add multiple tools to the container.

    Parameters
    ----------
    container : Container
        `.backend_bases.ToolContainerBase` object that will get the tools
        added.
    tools : list, optional
        List in the form ``[[group1, [tool1, tool2 ...]], [group2, [...]]]``
        where the tools ``[tool1, tool2, ...]`` will display in group1.
        See `.backend_bases.ToolContainerBase.add_tool` for details.
    N)r\  r  )	containerrr   group
grouptoolsr  rw   s         r   add_tools_to_containerr    sB     # 6z'
3 	6NHdtUH5	66r   r,   )7r   r   r   r  r4  typesr   r   weakrefr   numpyrk  
matplotlibrt   matplotlib._pylab_helpersr   r   r   IntEnumr	   rm   r   r   r   r'   r  r*   rO   rh   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r#  r&  r(  r+  rO  r  r  r  default_toolsdefault_toolbar_toolsr  r  r   r   r   <module>r     s     	  !  %   ) ""dll "    V VrT%X T%n/5H /5d6 68X 8%x %( Kx KKH K8X 8'N '"  @. @.F	B 	B! ! $ 'H 'HX H@C. @CFv{ vr?,k ?,D#?8 #?L6h 6 68 Y #('2  	
 } ~  [ : : / "#5 =  .%0!& '(CD#%@A 013 
 -: )" -B 6r   