o
    -h{&                     @   s   d Z ddlm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lmZ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.    )chain)cbookcmcolorsmarkersimage)QtGui)_formlayout)DateConverternum2dateSolidDashedDashDotDottedNone)-z--z-.:r   DefaultzSteps (Pre)zSteps (Mid)zSteps (Post))defaultz	steps-prestepsz	steps-midz
steps-postNc                    sZ  d
dd  j  fdd D d  f
gt
fdd D d	}d
d  D dd  D g   D ]}| }|dkrQqF||f qFg }dd }D ]m\}}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 qat|g 	g  j jD ]}| }|dks| du rq݈	||f qg }dd ttj D }	D ]d\}}| }|jtjvr||jfg|}|  \}}d|fd|jg| fd |fd!|fg}t!|d"rad#d tt"j#D }|d$|$ g|f g d%}|d&|% g|f |||dg qt||d'dfg}|r||d(df |r||d)df  	fd*d+}t&j'|d,|t()t*t+,d-d.|d/ dS )0zEdit matplotlib figure options)NNc                 S   s   t |tr
tt| S tt| S )z.Convert axis limits for correct input editors.)
isinstancer
   mapr   float)lim	converter r   _/var/www/vscode/kcb/lib/python3.10/site-packages/matplotlib/backends/qt_editor/figureoptions.pyconvert_limits#   s   


z#figure_edit.<locals>.convert_limitsc              
      s4   i | ]\}}|t t d | d | qS get_r   )tuplegetattrget_converter.0nameaxis)axesr   r   r   
<dictcomp>+   s    zfigure_edit.<locals>.<dictcomp>Titlec                    sd   g | ].\}}d d|   dfd | d fd | d fd|j fd| d	d
ddgffqS )Nz<b>z	-Axis</b>Minr   Max   LabelScalelinearlogsymloglogit)titlelabelget_text	get_scaler#   )axis_limitssepr   r   
<listcomp>4   s    
zfigure_edit.<locals>.<listcomp>)z(Re-)Generate automatic legendFc                 S      i | ]	\}}||  qS r   )r"   r#   r   r   r   r(   D       c                 S   r:   r   )	get_unitsr#   r   r   r   r(   H   r;   
_nolegend_c                 S   sf   || vri | |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      i | ]\}}||qS r   r   )r$   shortr%   r   r   r   r(   g       z5figure_edit.<locals>.prepare_data.<locals>.<dictcomp>c                 S   r>   r   r   )r$   r%   r?   r   r   r   r(   i   r@   c                 S   s   | d S )Nr,   r   )short_and_namer   r   r   <lambda>o   s    z3figure_edit.<locals>.prepare_data.<locals>.<lambda>)key)stritemssorted)dinit
name2short
short2namecanonical_initr   r   r   prepare_dataV   s   z!figure_edit.<locals>.prepare_dataT)
keep_alphar-   )Nz<b>Line</b>z
Line stylez
Draw style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   r9      s    Colormapz
Min. valuez
Max. valueget_interpolationc                 S   s   g | ]}||fqS r   r   r$   r%   r   r   r   r9      s    Interpolation)datargbaautozInterpolation stageAxesCurveszImages, etc.c           '   
      s   fddD }|  d}r|  dng }r|  dng }| r&td| d} | |  }t D ]P\}\}}	|d|  }
|d| d  }|d| d  }|d| d  }|	 |krot d	| d
| |	j|
|dd |	| |		|  |	
|  q:t|D ]P\}}| d }|\	}}}}}}}}}|| || || || t|}|d || |dkr|| || || || qt|D ]D\}}| d }t|dkr|\}}}}} }!||  ||! nt|dkr|\}}}}|| || |jt||g  q|rPd}"d}# jdurB  }$|$jdu}"|$j }# j!|#d}%|%rP|%"|"  # }&|&j$%  D ]}t d| d || kru|&j$j&'   dS q[dS )zA callback to apply changes.c                    s"   i | ]}|t  d | d qS r   )r!   rU   )r'   r   r   r(      s    z7figure_edit.<locals>.apply_callback.<locals>.<dictcomp>r   zUnexpected field   r,         set_scaleF)rY   Nnone   )ncolsr   r   )(pop
ValueError	set_title	enumeraterE   r6   r!   _set_limset_label_text_set_converter	set_units	set_labelset_linestyleset_drawstyleset_linewidthmcolorsto_rgba	set_alpha	set_color
set_markerset_markersizeset_markerfacecolorset_markeredgecolorlenset_interpolationset_interpolation_stageset_cmapset_climrF   legend_
get_legend
_draggable_ncolslegendset_draggable
get_figurecanvasdrawtoolbarpush_current)'rW   orig_limitsgeneralcurves	mappablesr3   generate_legendir%   r&   axis_minaxis_max
axis_label
axis_scaleindexcurveliner4   	linestyle	drawstyle	linewidthcolormarker
markersizemarkerfacecolormarkeredgecolorrX   mappable_settingsmappablerR   lowhighinterpolationinterpolation_stage	draggablerc   
old_legend
new_legendfigure)r'   axis_converteraxis_map
axis_units	has_curvehas_smlabeled_lineslabeled_mappablesr   r   apply_callback   s   





















z#figure_edit.<locals>.apply_callbackzFigure optionsimageszqt4_editor_options.svg)r3   parenticonapply)-	_axis_maprE   	get_titler   from_iterable	get_lines	get_labelappendrp   to_hexrq   	get_color	get_alphaget_markeredgecolorget_markerfacecolor
LINESTYLESget_linestyle
DRAWSTYLESget_drawstyleget_linewidthMARKERS
get_markerget_markersizeboolr   collections	get_arrayrF   r   
_colormapsget_cmapr%   get_climhasattrmimageinterpolations_namesrT   get_interpolation_stager	   feditr   QIconrD   r   _get_data_path)r'   r   r   r   r4   r   rL   r   ecfc	curvedatar   r   cmapsrR   r   r   mappabledatainterpolationsinterpolation_stagesdatalistr   r   )r'   r   r7   r   r   r   r   r   r   r   r8   r   figure_edit   s   



T
r   )N)__doc__	itertoolsr   
matplotlibr   r   r   rp   r   r   r   matplotlib.backends.qt_compatr   matplotlib.backends.qt_editorr	   matplotlib.datesr
   r   r   r   MarkerStyler   r   r   r   r   r   <module>   s&   