B
    ²ô`ÿ$  ã               @   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 ‰x*ˆ  ¡ D ]}	|	 ¡ }
|
dkrâqÌ|	ˆ|
< qÌW g }dd„ }tˆ|d‰xèˆ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W t |ƒ‰i ‰xBˆ j!ˆ j"•D ]2}| ¡ }
|
dks
| #¡ d"kr2q
|ˆ|
< q
W tˆ|d‰g }d#d$„ tt$j% &¡ ƒD ƒ}x¶ˆ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¡ qnW t |ƒ‰|d+d!fg}|rJ| |d,d!f¡ |r`| |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   úZ/home/dcms/DCMS/lib/python3.7/site-packages/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_data)r   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 ¡  x°t|ƒD ]¤\}}ˆˆ|  }|\	}}}}}}}}}| |¡ | |¡ | |¡ | |¡ t |¡}| d¡ | |¡ |dkr
| |¡ | |¡ | |¡ | |¡ q
W xt|ƒD ]„\}}ˆˆ|  }t|ƒdkrø|\}}} }!}"|  |"¡ nt|ƒdkr|\}}} }!| |¡ | !t" #|¡¡ |j$t%| |!gƒŽ  q¼W |r’d}#d}$ˆ j&dk	rvˆ  '¡ }%|%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	draggabler/   Z
old_legendZ
new_legendÚfigure)ÚaxesÚcurvelabelsÚ	has_curveÚhas_smÚlinedictÚmappabledictÚmappablelabelsÚ
xconverterÚxunitsÚ
yconverterÚyunitsr   r   Úapply_callback¬   s|    






















z#figure_edit.<locals>.apply_callbackzFigure optionsÚimageszqt4_editor_options.svg)rC   ÚparentZiconÚapply)6ÚmapÚfloatr0   r1   Z	get_titleZ
get_xlabelr4   Z
get_ylabelr5   r7   r8   r9   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Úboolr]   Ú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)rQ   r^   ÚseprD   rE   rF   rG   r@   r   rI   r   rA   r$   rJ   ZecZfcZ	curvedatarL   rB   Zcmapsr(   rM   rN   ZmappabledataZinterpolationsZdatalistr\   r?   r   )rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r   Úfigure_edit   s¾    










 R
rm   )N)Ú__doc__r   Z
matplotlibr   r   r   r;   r   r   rk   Zmatplotlib.backends.qt_compatr   Zmatplotlib.backends.qt_editorr   rc   rd   ZMarkerStylere   rm   r   r   r   r   Ú<module>   s   