B
    ]”t\È  ã               @   s<   d Z ddlZddlZddlZG dd„ deƒZe ej¡ dS )z&
Manage figures for pyplot interface.
é    Nc               @   s’   e Zd ZdZg Zi Zedd„ ƒZedd„ ƒZedd„ ƒZ	edd	„ ƒZ
ed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZeddd„ƒZdS )ÚGcfaÉ  
    Singleton to manage a set of integer-numbered figures.

    This class is never instantiated; it consists of two class
    attributes (a list and a dictionary), and a set of static
    methods that operate on those attributes, accessing them
    directly as class attributes.

    Attributes:

        *figs*:
          dictionary of the form {*num*: *manager*, ...}

        *_activeQue*:
          list of *managers*, with active one at the end

    c             C   s$   | j  |d¡}|dk	r |  |¡ |S )z„
        If figure manager *num* exists, make it the active
        figure and return the manager; otherwise return *None*.
        N)ÚfigsÚgetÚ
set_active)ÚclsÚnumÚmanager© r	   ú8lib/python3.7/site-packages/matplotlib/_pylab_helpers.pyÚget_fig_manager   s    
zGcf.get_fig_managerc             C   sP   |   |¡sdS | j| }|j |j¡ | j |¡ | j|= | ¡  t 	d¡ dS )z¤
        Try to remove all traces of figure *num*.

        In the interactive backends, this is bound to the
        window "destroy" and "delete" events.
        Né   )
Ú
has_fignumr   ÚcanvasÚmpl_disconnectÚ_cidgcfÚ
_activeQueÚremoveÚdestroyÚgcÚcollect)r   r   r   r	   r	   r
   r   *   s    

zGcf.destroyc                s4   t ‡ fdd„| j ¡ D ƒdƒ}|dk	r0|  |¡ dS )z*fig* is a Figure instancec             3   s    | ]}|j jˆ kr|jV  qd S )N)r   Úfigurer   )Ú.0r   )Úfigr	   r
   ú	<genexpr>>   s    z"Gcf.destroy_fig.<locals>.<genexpr>N)Únextr   Úvaluesr   )r   r   r   r	   )r   r
   Údestroy_fig;   s    zGcf.destroy_figc             C   sT   dd l }x,t| j ¡ ƒD ]}|j |j¡ | ¡  qW g | _| j 	¡  | 
d¡ d S )Nr   r   )r   Úlistr   r   r   r   r   r   r   Úclearr   )r   r   r   r	   r	   r
   Údestroy_allC   s    
zGcf.destroy_allc             C   s
   || j kS )z7
        Return *True* if figure *num* exists.
        )r   )r   r   r	   r	   r
   r   P   s    zGcf.has_fignumc             C   s   t | j ¡ ƒS )z3
        Return a list of figure managers.
        )r   r   r   )r   r	   r	   r
   Úget_all_fig_managersW   s    zGcf.get_all_fig_managersc             C   s
   t | jƒS )z=
        Return the number of figures being managed.
        )Úlenr   )r   r	   r	   r
   Úget_num_fig_managers^   s    zGcf.get_num_fig_managersc             C   s    t | jƒdkrdS | jd S dS )zE
        Return the manager of the active figure, or *None*.
        r   Néÿÿÿÿ)r!   r   )r   r	   r	   r
   Ú
get_activee   s    zGcf.get_activec             C   sR   | j dd… }g | _ x |D ]}||kr| j  |¡ qW | j  |¡ || j|j< dS )zL
        Make the figure corresponding to *manager* the active one.
        N)r   Úappendr   r   )r   r   ZoldQueÚmr	   r	   r
   r   o   s    
zGcf.set_activeFc             C   s.   x(|   ¡ D ]}|s|jjjr
|j ¡  q
W dS )zV
        Redraw all figures registered with the pyplot
        state machine.
        N)r    r   r   ZstaleZ	draw_idle)r   ZforceZf_mgrr	   r	   r
   Údraw_all|   s    zGcf.draw_allN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úclassmethodr   r   r   r   r   r    r"   r$   r   r'   r	   r	   r	   r
   r   
   s   
r   )r+   Úatexitr   ÚsysÚobjectr   Úregisterr   r	   r	   r	   r
   Ú<module>   s
   |