o
    g$                     @   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)_formlayoutSolidDashedDashDotDottedNone)-z--z-.:r   DefaultzSteps (Pre)zSteps (Mid)zSteps (Post))defaultz	steps-pre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rpqe|	|
< qeg }dd }t|dD ]o}
|
 }	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 qt |i g  j! j"D ]}| }
|
dks|# d"u rq||
< qt|dg }d#d$ tt$j%& D }D ]W}
|
 }|' }|t$j%( vrK||j)fg|}|* \}}d|
fd%|j)g| fd&|fd'|fg}t+|d(rd)d$ tt,j-D }|d*|. g|f |||
d!g q1t ||d+d!fg}|r||d,d!f |r||d-d!f  	
fd.d/}t/j0|d0|t12t3t45d1d2|d3}|d"ur|| d"S d"S )4zEdit matplotlib figure options)NNTitle)Nz<b>X-Axis</b>LeftRightLabelScalelinearloglogit)Nz<b>Y-Axis</b>BottomTop)z(Re-)Generate automatic legendFc                 S   s0   t d| }|r|dt|dfS | dfS )Nz(_line|_image)(\d+)      r   )rematchgroupint)labelr     r$   i/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/matplotlib/backends/qt_editor/figureoptions.pycmp_key=   s   zfigure_edit.<locals>.cmp_key
_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$   ).0shortnamer$   r$   r%   
<dictcomp>^       z5figure_edit.<locals>.prepare_data.<locals>.<dictcomp>c                 S   r(   r$   r$   )r)   r+   r*   r$   r$   r%   r,   `   r-   c                 S   s   | d S )Nr   r$   )short_and_namer$   r$   r%   <lambda>f   s    z3figure_edit.<locals>.prepare_data.<locals>.<lambda>key)stritemssorted)dinit
name2short
short2namecanonical_initr$   r$   r%   prepare_dataM   s   z!figure_edit.<locals>.prepare_datar0   T)
keep_alpha)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%   
<listcomp>   s    zfigure_edit.<locals>.<listcomp>Colormapz
Min. valuez
Max. valueget_interpolationc                 S   s   g | ]}||fqS r$   r$   )r)   r+   r$   r$   r%   rA      s    InterpolationAxesCurveszImages, etc.c           (   
      s     }  }| d}r| dng }r| dng }| r%td|\
}}}}	}
}}}}}  |
kr< |
   |krG |  |  	||  
|	  ||  |  j_	 j_ j  j
  j   j  t|D ]P\}}|  }|\	}}}}}}}}}|| || || || t|}|d || |dkr|| || || || qt|D ]@\}}|  }t|dkr|\}}} }!}"| |" nt|dkr|\}}} }!|| |!t"#| |j$t%| |!g  q|rAd}#d}$ j&dur3 ' }%|%j(du}#|%j)}$ j*|$d}&|&rA|&+|#  , }'|'j-.     |krX  |ks`|'j-j/0  dS dS )	zA callback to apply changes.r   zUnexpected fieldNnone      r   )ncol)1get_xlimget_ylimpop
ValueError
get_xscale
set_xscale
get_yscale
set_yscale	set_titleset_xlim
set_xlabelset_ylim
set_ylabelxaxis	converteryaxis	set_units_update_axisinfo	enumerate	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_cmapr   get_cmapset_climr4   legend_
get_legend
_draggable_ncollegendset_draggable
get_figurecanvasdrawtoolbarpush_current)(data	orig_xlim	orig_ylimgeneralcurves	mappablestitlexminxmaxxlabelxscaleyminymaxylabelyscalegenerate_legendindexcurveliner#   	linestyle	drawstyle	linewidthcolormarker
markersizemarkerfacecolormarkeredgecolorrgbamappable_settingsmappabler@   lowhighinterpolation	draggablerJ   
old_legend
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)r   parenticonapply)6mapfloatrK   rL   	get_title
get_xlabelrO   
get_ylabelrQ   rX   rY   rZ   	get_units	get_lines	get_labelr4   rb   to_hexrc   	get_color	get_alphaget_markeredgecolorget_markerfacecolor
LINESTYLESget_linestyle
DRAWSTYLESget_drawstyleget_linewidthMARKERS
get_markerget_markersizeappendboolr   collections	get_arrayr   _cmap_registryr3   rm   valuesr+   get_climhasattrmimageinterpolations_namesrC   r   feditr   QIconr2   r   _get_data_path)r   r   sepr   r   r   r   r}   r&   r   r#   r~   r:   r   ecfc	curvedatar   r   cmapsr@   r   r   mappabledatainterpolationsdatalistr   rz   r$   r   r%   figure_edit   s   







 R
r   )N)__doc__r   
matplotlibr   r   r   rb   r   r   r   matplotlib.backends.qt_compatr   matplotlib.backends.qt_editorr   r   r   MarkerStyler   r   r$   r$   r$   r%   <module>   s$   