B
    ±ªt\uf  ã               @   s.   d dl mZ ddlmZ G dd„ dejƒZdS )é   )Ú	xmlwriteré    )Úwarnc                   s‚  e Zd ZdZd“‡ fdd„	Zdd„ Zd”dd	„Zd
d„ Zd•dd„Zd–dd„Z	d—dd„Z
d˜dd„Zd™dd„Zdšdd„Zd›dd„Zdd„ Zdœdd„Zdd d!„Zd"d#„ Zdžd$d%„ZdŸd&d'„Zd(d)„ Zd d*d+„Zd¡d,d-„Zd¢d.d/„Zd£d0d1„Zd2d3„ Zd4d5„ Zd¤d6d7„Zd8d9„ Zd¥d:d;„Zd<d=„ Zd¦d>d?„Z d§d@dA„Z!dBdC„ Z"d¨dDdE„Z#dFdG„ Z$d©dHdI„Z%dJdK„ Z&dLdM„ Z'dªdNdO„Z(d«dPdQ„Z)d¬dRdS„Z*dTdU„ Z+dVdW„ Z,dXdY„ Z-dZd[„ Z.d\d]„ Z/d^d_„ Z0d­dadb„Z1dcdd„ Z2dedf„ Z3dgdh„ Z4didj„ Z5dkdl„ Z6dmdn„ Z7dodp„ Z8d®dqdr„Z9dsdt„ Z:d¯dudv„Z;dwdx„ Z<dydz„ Z=d{d|„ Z>d}d~„ Z?dd€„ Z@dd‚„ ZAdƒd„„ ZBd…d†„ ZCd‡dˆ„ ZDd‰dŠ„ ZEd‹dŒ„ ZFddŽ„ ZGdd„ ZHd‘d’„ ZI‡  ZJS )°ÚFormatz;
    A class for writing the Excel XLSX Format file.


    Nc                sÈ  |dkri }t t| ƒ ¡  || _|| _d| _d| _d| _d| _d| _	d| _
d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d	| _d| _ d| _!d| _"d| _#d| _$d| _%d| _&d| _'d| _(d| _)d| _*d| _+d| _,d| _-d| _.d| _/d| _0d| _1d| _2d| _3d| _4d| _5d| _6d| _7d| _8d| _9d| _:d| _;d| _<d| _=d| _>d| _?d| _@d| _Ax(| B¡ D ]\}}tC| d
| ƒ|ƒ qžW d| _DdS )z
        Constructor.

        NZGeneralr   ZCalibrié   é   ÚminorFr   Zset_)EÚsuperr   Ú__init__Úxf_format_indicesÚdxf_format_indicesÚxf_indexÚ	dxf_indexÚ
num_formatÚnum_format_indexÚ
font_indexÚhas_fontZhas_dxf_fontÚboldÚ	underlineÚitalicÚ	font_nameÚ	font_sizeÚ
font_colorÚfont_strikeoutÚfont_outlineÚfont_shadowÚfont_scriptÚfont_familyÚfont_charsetÚfont_schemeÚfont_condenseÚfont_extendÚthemeÚ	hyperlinkÚxf_idÚhiddenÚlockedÚtext_h_alignÚ	text_wrapÚtext_v_alignÚtext_justlastÚrotationÚfg_colorÚbg_colorÚpatternÚhas_fillZhas_dxf_fillZ
fill_indexZ
fill_countZborder_indexZ
has_borderZhas_dxf_borderZborder_countÚbottomÚbottom_colorÚdiag_borderÚ
diag_colorÚ	diag_typeÚleftÚ
left_colorÚrightÚright_colorÚtopÚ	top_colorÚindentÚshrinkZmerge_rangeÚreading_orderÚjust_distribÚcolor_indexedÚ	font_onlyÚitemsÚgetattrÚ_format_key)ÚselfZ
propertiesZ
xf_indicesZdxf_indicesÚkeyÚvalue)Ú	__class__© ú0lib/python3.7/site-packages/xlsxwriter/format.pyr
      sŠ    zFormat.__init__c             C   s
   || _ dS )zï
        Set the Format font_name property such as 'Time New Roman'. The
        default Excel font is 'Calibri'.

        Args:
            font_name: String with the font name. No default.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_namex   s    zFormat.set_font_namer   c             C   s
   || _ dS )zÅ
        Set the Format font_size property. The default Excel font size is 11.

        Args:
            font_size: Int with font size. No default.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_size†   s    zFormat.set_font_sizec             C   s   |   |¡| _dS )zÈ
        Set the Format font_color property. The Excel default is black.

        Args:
            font_color: String with the font color. No default.

        Returns:
            Nothing.

        N)Ú
_get_colorr   )rD   r   rH   rH   rI   Úset_font_color“   s    zFormat.set_font_colorTc             C   s
   || _ dS )zœ
        Set the Format bold property.

        Args:
            bold: Default is True, turns property on.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_bold    s    zFormat.set_boldc             C   s
   || _ dS )z 
        Set the Format italic property.

        Args:
            italic: Default is True, turns property on.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Ú
set_italic­   s    zFormat.set_italicr   c             C   s
   || _ dS )z¢
        Set the Format underline property.

        Args:
            underline: Default is 1, single underline.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_underlineº   s    zFormat.set_underlinec             C   s
   || _ dS )z°
        Set the Format font_strikeout property.

        Args:
            font_strikeout: Default is True, turns property on.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_strikeoutÇ   s    zFormat.set_font_strikeoutc             C   s
   || _ dS )z¡
        Set the Format font_script property.

        Args:
            font_script: Default is 1, superscript.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_scriptÔ   s    zFormat.set_font_scriptc             C   s
   || _ dS )z¬
        Set the Format font_outline property.

        Args:
            font_outline: Default is True, turns property on.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_outlineá   s    zFormat.set_font_outlinec             C   s
   || _ dS )zª
        Set the Format font_shadow property.

        Args:
            font_shadow: Default is True, turns property on.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_font_shadowî   s    zFormat.set_font_shadowc             C   s
   || _ dS )zÇ
        Set the Format num_format property such as '#,##0'.

        Args:
            num_format: String representing the number format. No default.

        Returns:
            Nothing.

        N)r   )rD   r   rH   rH   rI   Úset_num_formatû   s    zFormat.set_num_formatc             C   s
   || _ dS )z 
        Set the Format locked property.

        Args:
            locked: Default is True, turns property on.

        Returns:
            Nothing.

        N)r&   )rD   r&   rH   rH   rI   Ú
set_locked  s    zFormat.set_lockedc             C   s
   || _ dS )z 
        Set the Format hidden property.

        Args:
            hidden: Default is True, turns property on.

        Returns:
            Nothing.

        N)r%   )rD   r%   rH   rH   rI   Ú
set_hidden  s    zFormat.set_hiddenc             C   sB  |  ¡ }|dkr|  d¡ |dkr,|  d¡ |dkr>|  d¡ |dkrP|  d¡ |dkrb|  d	¡ |d
krt|  d¡ |dkr†|  d¡ |dkr˜|  d¡ |dkrª|  d¡ |dkr¼|  d¡ |dkrÊd| _|dkrÜ|  d¡ |dkrî|  d¡ |dkr|  d¡ |dkr|  d¡ |dkr*|  d	¡ |dkr>|  d¡ dS )z¨
        Set the Format cell alignment.

        Args:
            alignment: String representing alignment. No default.

        Returns:
            Nothing.
        r5   r   Zcentrer   Úcenterr7   é   Úfillé   Újustifyé   Zcenter_acrossé   Zcentre_acrossÚdistributedé   Zjustify_distributedr9   ZvcentreZvcenterr0   ZvjustifyZvdistributedN)ÚlowerÚset_text_h_alignr>   Úset_text_v_align)rD   Z	alignmentrH   rH   rI   Ú	set_align"  sF    



















zFormat.set_alignc             C   s   |   d¡ dS )z`
        Set the Format center_across property.

        Returns:
            Nothing.

        r^   N)rb   )rD   Z
align_typerH   rH   rI   Úset_center_acrossU  s    zFormat.set_center_acrossc             C   s
   || _ dS )z¦
        Set the Format text_wrap property.

        Args:
            text_wrap: Default is True, turns property on.

        Returns:
            Nothing.

        N)r(   )rD   r(   rH   rH   rI   Úset_text_wrap_  s    zFormat.set_text_wrapc             C   sX   t |ƒ}|dkrd}n8d|  kr*dkrBn n|dk rN| d }ntdƒ dS || _dS )zœ
        Set the Format rotation property.

        Args:
            rotation: Rotation angle. No default.

        Returns:
            Nothing.

        i  éÿ   i¦ÿÿÿéZ   r   z3Rotation rotation outside range: -90 <= angle <= 90N)Úintr   r+   )rD   r+   rH   rH   rI   Úset_rotationl  s    zFormat.set_rotationc             C   s
   || _ dS )z£
        Set the Format indent property.

        Args:
            indent: Default is 1, first indentation level.

        Returns:
            Nothing.

        N)r;   )rD   r;   rH   rH   rI   Ú
set_indent…  s    zFormat.set_indentc             C   s
   || _ dS )z 
        Set the Format shrink property.

        Args:
            shrink: Default is True, turns property on.

        Returns:
            Nothing.

        N)r<   )rD   r<   rH   rH   rI   Ú
set_shrink’  s    zFormat.set_shrinkc             C   s
   || _ dS )z®
        Set the Format text_justlast property.

        Args:
            text_justlast: Default is True, turns property on.

        Returns:
            Nothing.

        N)r*   )rD   r*   rH   rH   rI   Úset_text_justlastŸ  s    zFormat.set_text_justlastc             C   s
   || _ dS )z˜
        Set the Format pattern property.

        Args:
            pattern: Default is 1, solid fill.

        Returns:
            Nothing.

        N)r.   )rD   r.   rH   rH   rI   Úset_pattern¬  s    zFormat.set_patternc             C   s   |   |¡| _dS )zž
        Set the Format bg_color property.

        Args:
            bg_color: Background color. No default.

        Returns:
            Nothing.

        N)rL   r-   )rD   r-   rH   rH   rI   Úset_bg_color¹  s    zFormat.set_bg_colorc             C   s   |   |¡| _dS )zž
        Set the Format fg_color property.

        Args:
            fg_color: Foreground color. No default.

        Returns:
            Nothing.

        N)rL   r,   )rD   r,   rH   rH   rI   Úset_fg_colorÆ  s    zFormat.set_fg_colorc             C   s,   |   |¡ |  |¡ |  |¡ |  |¡ dS )z™
        Set the Format bottom property.

        Args:
            bottom: Default is 1, border type 1.

        Returns:
            Nothing.

        N)Ú
set_bottomÚset_topÚset_leftÚ	set_right)rD   ZstylerH   rH   rI   Ú
set_borderÔ  s    


zFormat.set_borderc             C   s,   |   |¡ |  |¡ |  |¡ |  |¡ dS )z•
        Set the Format bottom property.

        Args:
            color: Color string. No default.

        Returns:
            Nothing.

        N)Úset_bottom_colorÚset_top_colorÚset_left_colorÚset_right_color)rD   ÚcolorrH   rH   rI   Úset_border_colorå  s    


zFormat.set_border_colorc             C   s
   || _ dS )z™
        Set the Format bottom property.

        Args:
            bottom: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r0   )rD   r0   rH   rH   rI   rq   õ  s    zFormat.set_bottomc             C   s   |   |¡| _dS )z¢
        Set the Format bottom_color property.

        Args:
            bottom_color: Color string. No default.

        Returns:
            Nothing.

        N)rL   r1   )rD   r1   rH   rH   rI   rv     s    zFormat.set_bottom_colorc             C   s
   || _ dS )zŸ
        Set the Format diag_type property.

        Args:
            diag_type: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r4   )rD   r4   rH   rH   rI   Úset_diag_type  s    zFormat.set_diag_typec             C   s
   || _ dS )z•
        Set the Format left property.

        Args:
            left: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r5   )rD   r5   rH   rH   rI   rs     s    zFormat.set_leftc             C   s   |   |¡| _dS )zž
        Set the Format left_color property.

        Args:
            left_color: Color string. No default.

        Returns:
            Nothing.

        N)rL   r6   )rD   r6   rH   rH   rI   rx   )  s    zFormat.set_left_colorc             C   s
   || _ dS )z—
        Set the Format right property.

        Args:
            right: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r7   )rD   r7   rH   rH   rI   rt   6  s    zFormat.set_rightc             C   s   |   |¡| _dS )z 
        Set the Format right_color property.

        Args:
            right_color: Color string. No default.

        Returns:
            Nothing.

        N)rL   r8   )rD   r8   rH   rH   rI   ry   C  s    zFormat.set_right_colorc             C   s
   || _ dS )z“
        Set the Format top property.

        Args:
            top: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r9   )rD   r9   rH   rH   rI   rr   P  s    zFormat.set_topc             C   s   |   |¡| _dS )zœ
        Set the Format top_color property.

        Args:
            top_color: Color string. No default.

        Returns:
            Nothing.

        N)rL   r:   )rD   r:   rH   rH   rI   rw   ]  s    zFormat.set_top_colorc             C   s   |   |¡| _dS )zž
        Set the Format diag_color property.

        Args:
            diag_color: Color string. No default.

        Returns:
            Nothing.

        N)rL   r3   )rD   r3   rH   rH   rI   Úset_diag_colorj  s    zFormat.set_diag_colorc             C   s
   || _ dS )z£
        Set the Format diag_border property.

        Args:
            diag_border: Default is 1, border type 1.

        Returns:
            Nothing.

        N)r2   )rD   r2   rH   rH   rI   Úset_diag_borderw  s    zFormat.set_diag_borderc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_has_font‹  s    zFormat.set_has_fontc             C   s
   || _ d S )N)r/   )rD   r/   rH   rH   rI   Úset_has_fill  s    zFormat.set_has_fillc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_font_index“  s    zFormat.set_font_indexc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_xf_index—  s    zFormat.set_xf_indexc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_dxf_index›  s    zFormat.set_dxf_indexc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_num_format_indexŸ  s    zFormat.set_num_format_indexc             C   s
   || _ d S )N)r'   )rD   r'   rH   rH   rI   rb   £  s    zFormat.set_text_h_alignc             C   s
   || _ d S )N)r)   )rD   r)   rH   rH   rI   rc   §  s    zFormat.set_text_v_alignr   c             C   s
   || _ d S )N)r=   )rD   Ú	directionrH   rH   rI   Úset_reading_order«  s    zFormat.set_reading_orderc             C   s   |   |¡ d S )N)rd   )rD   ÚalignrH   rH   rI   Ú
set_valign¯  s    zFormat.set_valignc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_font_familyµ  s    zFormat.set_font_familyc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_font_charset¹  s    zFormat.set_font_charsetc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_font_scheme½  s    zFormat.set_font_schemec             C   s
   || _ d S )N)r    )rD   r    rH   rH   rI   Úset_font_condenseÁ  s    zFormat.set_font_condensec             C   s
   || _ d S )N)r!   )rD   r!   rH   rH   rI   Úset_font_extendÅ  s    zFormat.set_font_extendc             C   s
   || _ d S )N)r"   )rD   r"   rH   rH   rI   Ú	set_themeÉ  s    zFormat.set_themec             C   s$   d| _ |  d¡ |  d¡ || _d S )Nr   é
   )r$   rP   rŽ   r#   )rD   r#   rH   rH   rI   Úset_hyperlinkÍ  s    

zFormat.set_hyperlinkc             C   s
   || _ d S )N)r?   )rD   Zcolor_indexrH   rH   rI   Úset_color_indexedÕ  s    zFormat.set_color_indexedc             C   s
   || _ d S )N)r@   )rD   r@   rH   rH   rI   Úset_font_onlyÙ  s    zFormat.set_font_onlyc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_fontÞ  s    zFormat.set_fontc             C   s
   || _ d S )N)r   )rD   r   rH   rH   rI   Úset_sizeâ  s    zFormat.set_sizec             C   s   |   |¡| _d S )N)rL   r   )rD   r   rH   rH   rI   Ú	set_coloræ  s    zFormat.set_colorc             C   sR  d}g }| j s2| js2| js2| js2| js2| js2| jr8d}n||fS | jrj| j dkrj| j dkrj| j dkrjd| _ | jrvd| _| j dkr†d| _| j dkr–d| _| j dkr¦d| _| j dkr¶d| _| jrÂd| _d}| j dkrÚ| d¡ | j d	krî| d
¡ | j dkr| d¡ | j dkr| d¡ | j dkr0| d¡ | j dkrJ| d|f¡ | j dkr`| d¡ | jrr| d¡ | jdkrˆ| d¡ | jd	krž| d¡ | jdkr´| d¡ | jdkrÊ| d¡ | jrâ| d| jf¡ | jrú| d| jf¡ | jr| d¡ | jr| d¡ | jdkr4| d¡ | jd	krJ| d¡ ||fS )Nr   r   rY   r`   r[   r]   ZcenterContinuous)Ú
horizontalr5   r   )r–   rX   )r–   r7   )r–   rZ   )r–   r\   r^   r–   )r–   r_   )ZjustifyLastLiner   )Úverticalr9   )r—   rX   )r—   r\   )r—   r_   r;   ZtextRotation)ZwrapTextr   )ZshrinkToFitr   )ÚreadingOrderr   )r˜   r   )	r'   r)   r;   r+   r(   r<   r=   r>   Úappend)rD   Zchangedr‡   Z
continuousrH   rH   rI   Ú_get_align_propertiesð  s|    























zFormat._get_align_propertiesc             C   s(   g }| j s| d¡ | jr$| d¡ |S )N)r&   r   )r%   r   )r&   r™   r%   )rD   ZattribsrH   rH   rI   Ú_get_protection_propertiesD  s    

z!Format._get_protection_propertiesc          
      sN   ˆ j d krHd ‡ fdd„ˆ  ¡ ˆ  ¡ ˆ  ¡ ˆ  ¡ ˆ jˆ jˆ jfD ƒ¡ˆ _ ˆ j S )Nú:c             3   s   | ]}ˆ   |¡V  qd S )N)Ú
_to_string)Ú.0Úx)rD   rH   rI   ú	<genexpr>R  s    z)Format._get_format_key.<locals>.<genexpr>)	rC   ÚjoinÚ_get_font_keyÚ_get_border_keyÚ_get_fill_keyÚ_get_alignment_keyr   r&   r%   )rD   rH   )rD   rI   Ú_get_format_keyO  s    
zFormat._get_format_keyc                sP   d  ‡ fdd„ˆ jˆ jˆ jˆ jˆ jˆ jˆ jˆ jˆ j	ˆ j
ˆ jˆ jˆ jfD ƒ¡}|S )Nrœ   c             3   s   | ]}ˆ   |¡V  qd S )N)r   )rž   rŸ   )rD   rH   rI   r    _  s    z'Format._get_font_key.<locals>.<genexpr>)r¡   r   r   r   r   r   r   r   r   r   r   r   r   r"   )rD   rE   rH   )rD   rI   r¢   ]  s    zFormat._get_font_keyc                sH   d  ‡ fdd„ˆ jˆ jˆ jˆ jˆ jˆ jˆ jˆ jˆ j	ˆ j
ˆ jfD ƒ¡}|S )Nrœ   c             3   s   | ]}ˆ   |¡V  qd S )N)r   )rž   rŸ   )rD   rH   rI   r    r  s    z)Format._get_border_key.<locals>.<genexpr>)r¡   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   )rD   rE   rH   )rD   rI   r£   p  s    zFormat._get_border_keyc                s(   d  ‡ fdd„ˆ jˆ jˆ jfD ƒ¡}|S )Nrœ   c             3   s   | ]}ˆ   |¡V  qd S )N)r   )rž   rŸ   )rD   rH   rI   r    ƒ  s    z'Format._get_fill_key.<locals>.<genexpr>)r¡   r.   r-   r,   )rD   rE   rH   )rD   rI   r¤     s
    zFormat._get_fill_keyc          
      s8   d  ‡ fdd„ˆ jˆ jˆ jˆ jˆ jˆ jˆ jfD ƒ¡}|S )Nrœ   c             3   s   | ]}ˆ   |¡V  qd S )N)r   )rž   rŸ   )rD   rH   rI   r      s    z,Format._get_alignment_key.<locals>.<genexpr>)r¡   r'   r)   r;   r+   r(   r<   r=   )rD   rE   rH   )rD   rI   r¥   Š  s    zFormat._get_alignment_keyc             C   sR   | j d k	r| j S |  ¡ }|| jkr,| j| S dt| jƒ }|| j|< || _ |S d S )Nr   )r   r¦   r   Úlen)rD   rE   ÚindexrH   rH   rI   Ú_get_xf_index˜  s    



zFormat._get_xf_indexc             C   sN   | j d k	r| j S |  ¡ }|| jkr,| j| S t| jƒ}|| j|< || _ |S d S )N)r   r¦   r   r§   )rD   rE   r¨   rH   rH   rI   Ú_get_dxf_index¬  s    




zFormat._get_dxf_indexc             C   s:   ddddddddd	d
dddddddœ}||kr6|| }|S )Nz#000000z#0000FFz#800000z#00FFFFz#808080z#008000z#00FF00z#FF00FFz#000080z#FF6600z#800080z#FF0000z#C0C0C0z#FFFFFFz#FFFF00)ZblackZblueZbrownZcyanZgrayZgreenZlimeZmagentaZnavyZorangeZpinkZpurpleZredZsilverZwhiteZyellowrH   )rD   rz   Znamed_colorsrH   rH   rI   rL   ¿  s&    zFormat._get_colorc             C   s(   yt |ƒS  tk
r"   | d¡S X d S )Nzutf-8)ÚstrÚUnicodeEncodeErrorÚencode)rD   rF   rH   rH   rI   r   Û  s    zFormat._to_string)NNN)r   )T)T)r   )T)r   )T)T)T)T)N)T)r   )T)T)r   )r   )r   )r   )r   )r   )r   )r   )T)T)r   )T)T)KÚ__name__Ú
__module__Ú__qualname__Ú__doc__r
   rJ   rK   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rd   re   rf   rj   rk   rl   rm   rn   ro   rp   ru   r{   rq   rv   r|   rs   rx   rt   ry   rr   rw   r}   r~   r   r€   r   r‚   rƒ   r„   rb   rc   r†   rˆ   r‰   rŠ   r‹   rŒ   r   rŽ   r   r‘   r’   r“   r”   r•   rš   r›   r¦   r¢   r£   r¤   r¥   r©   rª   rL   r   Ú__classcell__rH   rH   )rG   rI   r      sŽ   ^









3



















T	r   N)Ú r   Úwarningsr   Z	XMLwriterr   rH   rH   rH   rI   Ú<module>	   s   