3
$ßL]  ã               @   s4   d Z ddlZddlZG dd„ deƒZej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 j|dƒ}|dk	r | j|ƒ |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	   úA/tmp/pip-install-edjban26/matplotlib/matplotlib/_pylab_helpers.pyÚget_fig_manager   s    
zGcf.get_fig_managerc             C   sP   | j |ƒsdS | j| }|jj|jƒ | jj|ƒ | j|= |jƒ  tj	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jƒ D ƒdƒ}|dk	r0| j|ƒ 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jƒ ƒD ]}|jj|jƒ |jƒ  qW g | _| jj	ƒ  |j
dƒ d S )Nr   r   )r   Úlistr   r   r   r   r   r   r   Úclearr   )r   r   r   r	   r	   r
   Údestroy_allB   s    
zGcf.destroy_allc             C   s
   || j kS )z7
        Return *True* if figure *num* exists.
        )r   )r   r   r	   r	   r
   r   O   s    zGcf.has_fignumc             C   s   t | jjƒ ƒS )z3
        Return a list of figure managers.
        )r   r   r   )r   r	   r	   r
   Úget_all_fig_managersV   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   Nr   éÿÿÿÿ)r!   r   )r   r	   r	   r
   Ú
get_actived   s    zGcf.get_activec                s>   | j dd… }‡ fdd„|D ƒ| _ | j jˆ ƒ ˆ | jˆ j< dS )zL
        Make the figure corresponding to *manager* the active one.
        Nc                s   g | ]}|ˆ kr|‘qS r	   r	   )r   Úm)r   r	   r
   ú
<listcomp>t   s    z"Gcf.set_active.<locals>.<listcomp>)r   Úappendr   r   )r   r   ZoldQuer	   )r   r
   r   n   s    zGcf.set_activeFc             C   s.   x(| j ƒ D ]}|s|jjjr
|jjƒ  q
W dS )zV
        Redraw all figures registered with the pyplot
        state machine.
        N)r    r   r   ÚstaleZ	draw_idle)r   ÚforceZf_mgrr	   r	   r
   Údraw_allx   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   Úobjectr   Úregisterr   r	   r	   r	   r
   Ú<module>   s   y