U
    \	¸aÿ$  ã                   @   sv   d Z ddlZddlmZmZmZmZmZ	 ddl
mZ ddlmZ dddd	d
dœZddddddœZejjZddd„ZdS )zHModule that provides a GUI-based editor for Matplotlib's figure options.é    N)ÚcbookÚcmÚcolorsÚmarkersÚimage)ÚQtGui)Ú_formlayoutZSolidZDashedZDashDotZDottedÚNone)ú-z--z-.ú:r	   ZDefaultzSteps (Pre)zSteps (Mid)zSteps (Post))Údefaultz	steps-preZstepsz	steps-midz
steps-postc                    s¬  d}t tˆ  ¡ ƒ\}}t tˆ  ¡ ƒ\}}dˆ  ¡ f|dd|fd|fdˆ  ¡ fdˆ  ¡ dd	d
gf|dd|fd|fdˆ  ¡ fdˆ  ¡ dd	d
gf|dg}ˆ j	j
‰ˆ jj
‰	ˆ j	 ¡ ‰ˆ j ¡ ‰
dd„ }i ‰ˆ  ¡ D ]}	|	 ¡ }
|
dkràqÊ|	ˆ|
< qÊg }dd„ }tˆ|d‰ˆD ]à}
ˆ|
 }	tjt |	 ¡ |	 ¡ ¡dd}tjt |	 ¡ |	 ¡ ¡dd}tjt |	 ¡ |	 ¡ ¡dd}d|
f|dd|t|	 ¡ ƒfd|t|	 ¡ ƒfd|	 ¡ fd|f|dd|t|	 ¡ ƒfd|	 ¡ fd|fd |fg}| ||
d!g¡ qt |ƒ‰i ‰ˆ j!ˆ j"•D ]2}| ¡ }
|
dks | #¡ d"kr(q |ˆ|
< q tˆ|d‰g }d#d$„ tt$j% &¡ ƒD ƒ}ˆD ]®}
ˆ|
 }| '¡ }|t$j% (¡ kr”||j)ff|•}| *¡ \}}d|
fd%|j)g| fd&|fd'|fg}t+|d(ƒrüd)d$„ tt,j-ƒD ƒ}| d*| .¡ f|•f¡ | ||
d!g¡ q`t |ƒ‰|d+d!fg}|r:| |d,d!f¡ |rP| |d-d!f¡ ‡ ‡‡‡‡‡‡‡‡‡	‡
fd.d/„}t/j0|d0|t1 2t3t4 5d1d2¡ƒ¡|d3}|d"k	r¨||ƒ d"S )4zEdit matplotlib figure options)NNZTitle)Nz<b>X-Axis</b>ZLeftZRightZLabelZScaleZlinearÚlogZlogit)Nz<b>Y-Axis</b>ZBottomZTop)z(Re-)Generate automatic legendFc                 S   s4   t  d| ¡}|r(| d¡t| d¡ƒfS | dfS d S )Nz(_line|_image)(\d+)é   é   r   )ÚreÚmatchÚgroupÚint)Úlabelr   © r   úO/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/backends/qt_editor/figureoptions.pyÚcmp_key=   s    zfigure_edit.<locals>.cmp_keyZ
_nolegend_c                 S   sb   || kr| |t |ƒi–} dd„ |  ¡ D ƒ}dd„ | ¡ D ƒ}|| |  }|gt| ¡ dd„ d S )aâ  
        Prepare entry for FormLayout.

        *d* is a mapping of shorthands to style names (a single style may
        have multiple shorthands, in particular the shorthands `None`,
        `"None"`, `"none"` and `""` are synonyms); *init* is one shorthand
        of the initial style.

        This function returns an list suitable for initializing a
        FormLayout combobox, namely `[initial_name, (shorthand,
        style_name), (shorthand, style_name), ...]`.
        c                 S   s   i | ]\}}||“qS r   r   )Ú.0ÚshortÚnamer   r   r   Ú
<dictcomp>^   s      z5figure_edit.<locals>.prepare_data.<locals>.<dictcomp>c                 S   s   i | ]\}}||“qS r   r   )r   r   r   r   r   r   r   `   s      c                 S   s   | d S )Nr   r   )Zshort_and_namer   r   r   Ú<lambda>f   ó    z3figure_edit.<locals>.prepare_data.<locals>.<lambda>©Úkey)ÚstrÚitemsÚsorted)ÚdÚinitZ
name2shortZ
short2nameZcanonical_initr   r   r   Úprepare_dataM   s    ÿÿz!figure_edit.<locals>.prepare_datar   T)Z
keep_alpha)Nz<b>Line</b>z
Line stylez
Draw styleZWidthzColor (RGBA))Nz<b>Marker</b>ÚStyleÚSizezFace color (RGBA)zEdge color (RGBA)Ú Nc                 S   s   g | ]\}}||f‘qS r   r   )r   r   Úcmapr   r   r   Ú
<listcomp>   s     zfigure_edit.<locals>.<listcomp>ZColormapz
Min. valuez
Max. valueÚget_interpolationc                 S   s   g | ]}||f‘qS r   r   )r   r   r   r   r   r*      s    ÚInterpolationZAxesZCurveszImages, etc.c           (   
      sÈ  ˆ   ¡ }ˆ  ¡ }|  d¡}ˆr(|  d¡ng }ˆr:|  d¡ng }| rJtdƒ‚|\
}}}}	}
}}}}}ˆ  ¡ |
krxˆ  |
¡ ˆ  ¡ |krŽˆ  |¡ ˆ  |¡ ˆ  	||¡ ˆ  
|	¡ ˆ  ||¡ ˆ  |¡ ˆˆ j_ˆ	ˆ j_ˆ j ˆ¡ ˆ j ˆ
¡ ˆ j ¡  ˆ j ¡  t|ƒD ]¤\}}ˆˆ|  }|\	}}}}}}}}}| |¡ | |¡ | |¡ | |¡ t |¡}| d¡ | |¡ |dkr| |¡ | |¡ | |¡ | |¡ qt|ƒD ]„\}}ˆˆ|  }t|ƒdkrò|\}}} }!}"|  |"¡ nt|ƒdkr|\}}} }!| |¡ | !t" #|¡¡ |j$t%| |!gƒŽ  q¶|rŠd}#d}$ˆ j&dk	rnˆ  '¡ }%|%j(dk	}#|%j)}$ˆ j*|$d}&|&rŠ|& +|#¡ ˆ  ,¡ }'|'j- .¡  ˆ   ¡ |kr¸ˆ  ¡ |ksÄ|'j-j/ 0¡  dS )	zA callback to apply changes.r   zUnexpected fieldNÚnoneé   é   r   )Úncol)1Úget_xlimÚget_ylimÚpopÚ
ValueErrorÚ
get_xscaleZ
set_xscaleÚ
get_yscaleZ
set_yscaleÚ	set_titleZset_xlimZ
set_xlabelZset_ylimZ
set_ylabelÚxaxisÚ	converterÚyaxisZ	set_unitsZ_update_axisinfoÚ	enumerateZ	set_labelZset_linestyleZset_drawstyleZset_linewidthÚmcolorsÚto_rgbaZ	set_alphaZ	set_colorZ
set_markerZset_markersizeZset_markerfacecolorZset_markeredgecolorÚlenZset_interpolationZset_cmapr   Úget_cmapZset_climr"   Zlegend_Z
get_legendZ
_draggableZ_ncolZlegendZset_draggableZ
get_figureZcanvasZdrawZtoolbarZpush_current)(ÚdataZ	orig_xlimZ	orig_ylimÚgeneralÚcurvesÚ	mappablesÚtitleÚxminÚxmaxZxlabelZxscaleÚyminÚymaxZylabelZyscaleZgenerate_legendÚindexZcurveÚliner   Z	linestyleZ	drawstyleZ	linewidthÚcolorÚmarkerZ
markersizeZmarkerfacecolorZmarkeredgecolorZrgbaZmappable_settingsÚmappabler)   ÚlowÚhighÚinterpolationZ	draggabler0   Z
old_legendZ
new_legendÚfigure©ÚaxesZcurvelabelsZ	has_curveZhas_smZlinedictZmappabledictZmappablelabelsZ
xconverterZxunitsZ
yconverterZyunitsr   r   Úapply_callback¬   s†    
ÿ






ÿ 














z#figure_edit.<locals>.apply_callbackzFigure optionsÚimageszqt4_editor_options.svg)rD   ÚparentZiconÚapply)6ÚmapÚfloatr1   r2   Z	get_titleZ
get_xlabelr5   Z
get_ylabelr6   r8   r9   r:   Z	get_unitsÚ	get_linesZ	get_labelr"   r<   Zto_hexr=   Z	get_colorZ	get_alphaZget_markeredgecolorZget_markerfacecolorÚ
LINESTYLESZget_linestyleÚ
DRAWSTYLESZget_drawstyleZget_linewidthÚMARKERSZ
get_markerZget_markersizeÚappendÚboolrU   ÚcollectionsZ	get_arrayr   Z_cmap_registryr!   r?   Úvaluesr   Zget_climÚhasattrÚmimageZinterpolations_namesr+   r   Zfeditr   ZQIconr    r   Z_get_data_path)rS   rV   ÚseprE   rF   rG   rH   rA   r   rJ   r   rB   r%   rK   ZecZfcZ	curvedatarM   rC   Zcmapsr)   rN   rO   ZmappabledataZinterpolationsZdatalistrT   r@   r   rR   r   Úfigure_edit   sÜ    
 
 
ô


þþþ

óüÿþ R  ÿü
re   )N)Ú__doc__r   Z
matplotlibr   r   r   r<   r   r   rc   Zmatplotlib.backends.qt_compatr   Zmatplotlib.backends.qt_editorr   r[   r\   ZMarkerStyler]   re   r   r   r   r   Ú<module>   s$   ü ü