o
    ȷef                     @   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ddd	Zd
d ZdddZdddZ	dddZ
dddZdddZdddZdddZdd ZdddZdd d!Zd"d# Zdd$d%Zdd&d'Zd(d) Zdd*d+Zdd,d-Zdd.d/Zdd0d1Zd2d3 Zd4d5 Zdd6d7Zd8d9 Zdd:d;Zd<d= Zdd>d?Z dd@dAZ!dBdC Z"ddDdEZ#dFdG Z$ddHdIZ%dJdK Z&dLdM Z'ddNdOZ(ddPdQZ)ddRdSZ*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0ddadbZ1dcdd Z2dedf Z3dgdh Z4didj Z5dkdl Z6dmdn Z7dodp Z8ddqdrZ9dsdt Z:ddudvZ;dwdx Z<dydz Z=d{d| Z>d}d~ Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZI  ZJS )Formatz;
    A class for writing the Excel XLSX Format file.


    Nc                    s  |du 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| _A|B D ]\}}tC| d
| | qd| _DdS )z
        Constructor.

        NGeneralr   Calibri      minorFr   set_)Esuperr   __init__xf_format_indicesdxf_format_indicesxf_index	dxf_index
num_formatnum_format_index
font_indexhas_font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_fillhas_dxf_fill
fill_index
fill_countborder_index
has_borderhas_dxf_borderborder_countbottombottom_colordiag_border
diag_color	diag_typeleft
left_colorrightright_colortop	top_colorindentshrinkmerge_rangereading_orderjust_distribcolor_indexed	font_onlyitemsgetattr_format_key)self
properties
xf_indicesdxf_indiceskeyvalue	__class__ H/var/www/ideatree/venv/lib/python3.10/site-packages/xlsxwriter/format.pyr      s   
zFormat.__init__c                 C   
   || _ 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   rP   r   rX   rX   rY   set_font_namey   s   
zFormat.set_font_namer   c                 C   rZ   )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   rP   r   rX   rX   rY   set_font_size      
zFormat.set_font_sizec                 C      |  || _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   rP   r   rX   rX   rY   set_font_color      zFormat.set_font_colorTc                 C   rZ   )z
        Set the Format bold property.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_bold   ra   zFormat.set_boldc                 C   rZ   )z
        Set the Format italic property.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   
set_italic   ra   zFormat.set_italicr   c                 C   rZ   )z
        Set the Format underline property.

        Args:
            underline: Default is 1, single underline.

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_underline   ra   zFormat.set_underlinec                 C   rZ   )z
        Set the Format font_strikeout property.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_font_strikeout   ra   zFormat.set_font_strikeoutc                 C   rZ   )z
        Set the Format font_script property.

        Args:
            font_script: Default is 1, superscript.

        Returns:
            Nothing.

        N)r    )rP   r    rX   rX   rY   set_font_script   ra   zFormat.set_font_scriptc                 C   rZ   )z
        Set the Format font_outline property.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_font_outline   ra   zFormat.set_font_outlinec                 C   rZ   )z
        Set the Format font_shadow property.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_font_shadow   ra   zFormat.set_font_shadowc                 C   rZ   )z
        Set the Format num_format property such as '#,##0'.

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

        Returns:
            Nothing.

        N)r   )rP   r   rX   rX   rY   set_num_format   ra   zFormat.set_num_formatc                 C   rZ   )z
        Set the Format locked property.

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

        Returns:
            Nothing.

        N)r*   )rP   r*   rX   rX   rY   
set_locked	  ra   zFormat.set_lockedc                 C   rZ   )z
        Set the Format hidden property.

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

        Returns:
            Nothing.

        N)r)   )rP   r)   rX   rX   rY   
set_hidden  ra   zFormat.set_hiddenc                 C   s>  |  }|dkr| d |dkr| d |dkr| d |dkr(| d |dkr1| d	 |d
kr:| d |dkrC| d |dkrL| d |dkrU| d |dkr^| d |dkred| _|dkrn| d |dkrw| d |dkr| d |dkr| d |dkr| d	 |dkr| d dS dS )z
        Set the Format cell alignment.

        Args:
            alignment: String representing alignment. No default.

        Returns:
            Nothing.
        r@   r   centrer	   centerrB      fill   justify   center_across   centre_acrossdistributed   justify_distributedrD   vcentrevcenterr;   vjustifyvdistributedN)lowerset_text_h_alignrJ   set_text_v_align)rP   	alignmentrX   rX   rY   	set_align#  sH   















zFormat.set_alignc                 C   s   |  d dS )z`
        Set the Format center_across property.

        Returns:
            Nothing.

        rz   N)r   )rP   
align_typerX   rX   rY   set_center_acrossV  s   zFormat.set_center_acrossc                 C   rZ   )z
        Set the Format text_wrap property.

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

        Returns:
            Nothing.

        N)r,   )rP   r,   rX   rX   rY   set_text_wrap`  ra   zFormat.set_text_wrapc                 C   sX   t |}|dkrd}nd|  krdkr!n n
|dk r | d }ntd dS || _dS )z
        Set the Format rotation property.

        Args:
            rotation: Rotation angle. No default.

        Returns:
            Nothing.

        i     iZ   r   z3Rotation rotation outside range: -90 <= angle <= 90N)intr   r/   )rP   r/   rX   rX   rY   set_rotationm  s   

zFormat.set_rotationc                 C   rZ   )z
        Set the Format indent property.

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

        Returns:
            Nothing.

        N)rF   )rP   rF   rX   rX   rY   
set_indent  ra   zFormat.set_indentc                 C   rZ   )z
        Set the Format shrink property.

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

        Returns:
            Nothing.

        N)rG   )rP   rG   rX   rX   rY   
set_shrink  ra   zFormat.set_shrinkc                 C   rZ   )z
        Set the Format text_justlast property.

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

        Returns:
            Nothing.

        N)r.   )rP   r.   rX   rX   rY   set_text_justlast  ra   zFormat.set_text_justlastc                 C   rZ   )z
        Set the Format pattern property.

        Args:
            pattern: Default is 1, solid fill.

        Returns:
            Nothing.

        N)r2   )rP   r2   rX   rX   rY   set_pattern  ra   zFormat.set_patternc                 C   rb   )z
        Set the Format bg_color property.

        Args:
            bg_color: Background color. No default.

        Returns:
            Nothing.

        N)rd   r1   )rP   r1   rX   rX   rY   set_bg_color  rg   zFormat.set_bg_colorc                 C   rb   )z
        Set the Format fg_color property.

        Args:
            fg_color: Foreground color. No default.

        Returns:
            Nothing.

        N)rd   r0   )rP   r0   rX   rX   rY   set_fg_color  rg   zFormat.set_fg_colorc                 C   ,   |  | | | | | | | 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)rP   stylerX   rX   rY   
set_border     


zFormat.set_borderc                 C   r   )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)rP   colorrX   rX   rY   set_border_color  r   zFormat.set_border_colorc                 C   rZ   r   )r;   )rP   r;   rX   rX   rY   r     ra   zFormat.set_bottomc                 C   rb   )z
        Set the Format bottom_color property.

        Args:
            bottom_color: Color string. No default.

        Returns:
            Nothing.

        N)rd   r<   )rP   r<   rX   rX   rY   r     rg   zFormat.set_bottom_colorc                 C   rZ   )z
        Set the Format diag_type property.

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

        Returns:
            Nothing.

        N)r?   )rP   r?   rX   rX   rY   set_diag_type  ra   zFormat.set_diag_typec                 C   rZ   )z
        Set the Format left property.

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

        Returns:
            Nothing.

        N)r@   )rP   r@   rX   rX   rY   r     ra   zFormat.set_leftc                 C   rb   )z
        Set the Format left_color property.

        Args:
            left_color: Color string. No default.

        Returns:
            Nothing.

        N)rd   rA   )rP   rA   rX   rX   rY   r   *  rg   zFormat.set_left_colorc                 C   rZ   )z
        Set the Format right property.

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

        Returns:
            Nothing.

        N)rB   )rP   rB   rX   rX   rY   r   7  ra   zFormat.set_rightc                 C   rb   )z
        Set the Format right_color property.

        Args:
            right_color: Color string. No default.

        Returns:
            Nothing.

        N)rd   rC   )rP   rC   rX   rX   rY   r   D  rg   zFormat.set_right_colorc                 C   rZ   )z
        Set the Format top property.

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

        Returns:
            Nothing.

        N)rD   )rP   rD   rX   rX   rY   r   Q  ra   zFormat.set_topc                 C   rb   )z
        Set the Format top_color property.

        Args:
            top_color: Color string. No default.

        Returns:
            Nothing.

        N)rd   rE   )rP   rE   rX   rX   rY   r   ^  rg   zFormat.set_top_colorc                 C   rb   )z
        Set the Format diag_color property.

        Args:
            diag_color: Color string. No default.

        Returns:
            Nothing.

        N)rd   r>   )rP   r>   rX   rX   rY   set_diag_colork  rg   zFormat.set_diag_colorc                 C   rZ   )z
        Set the Format diag_border property.

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

        Returns:
            Nothing.

        N)r=   )rP   r=   rX   rX   rY   set_diag_borderx  ra   zFormat.set_diag_borderc                 C   
   || _ d S N)r   )rP   r   rX   rX   rY   set_has_font     
zFormat.set_has_fontc                 C   r   r   )r3   )rP   r3   rX   rX   rY   set_has_fill  r   zFormat.set_has_fillc                 C   r   r   )r   )rP   r   rX   rX   rY   set_font_index  r   zFormat.set_font_indexc                 C   r   r   )r   )rP   r   rX   rX   rY   set_xf_index  r   zFormat.set_xf_indexc                 C   r   r   )r   )rP   r   rX   rX   rY   set_dxf_index  r   zFormat.set_dxf_indexc                 C   r   r   )r   )rP   r   rX   rX   rY   set_num_format_index  r   zFormat.set_num_format_indexc                 C   r   r   )r+   )rP   r+   rX   rX   rY   r     r   zFormat.set_text_h_alignc                 C   r   r   )r-   )rP   r-   rX   rX   rY   r     r   zFormat.set_text_v_alignr   c                 C   r   r   )rI   )rP   	directionrX   rX   rY   set_reading_order  r   zFormat.set_reading_orderc                 C   s   |  | d S r   )r   )rP   alignrX   rX   rY   
set_valign  s   zFormat.set_valignc                 C   r   r   )r!   )rP   r!   rX   rX   rY   set_font_family  r   zFormat.set_font_familyc                 C   r   r   )r"   )rP   r"   rX   rX   rY   set_font_charset  r   zFormat.set_font_charsetc                 C   r   r   )r#   )rP   r#   rX   rX   rY   set_font_scheme  r   zFormat.set_font_schemec                 C   r   r   )r$   )rP   r$   rX   rX   rY   set_font_condense  r   zFormat.set_font_condensec                 C   r   r   )r%   )rP   r%   rX   rX   rY   set_font_extend  r   zFormat.set_font_extendc                 C   r   r   )r&   )rP   r&   rX   rX   rY   	set_theme  r   zFormat.set_themec                 C   s$   d| _ | d | d || _d S )Nr   
   )r(   rj   r   r'   )rP   r'   rX   rX   rY   set_hyperlink  s   


zFormat.set_hyperlinkc                 C   r   r   )rK   )rP   color_indexrX   rX   rY   set_color_indexed  r   zFormat.set_color_indexedc                 C   r   r   )rL   )rP   rL   rX   rX   rY   set_font_only  r   zFormat.set_font_onlyc                 C   r   r   r[   r\   rX   rX   rY   set_font  r   zFormat.set_fontc                 C   r   r   r^   r_   rX   rX   rY   set_size  r   zFormat.set_sizec                 C   s   |  || _d S r   rc   re   rX   rX   rY   	set_color  s   zFormat.set_colorc                 C   s8  d}g }| j s| js| js| js| js| js| jrd}n||fS | jr5| j dkr5| j dkr5| j dkr5d| _ | jr;d| _| j dkrCd| _| j dkrKd| _| j dkrSd| _| j dkr[d| _| jrad| _d}| j dkrm|d | j d	krw|d
 | j dkr|d | j dkr|d | j dkr|d | j dkr|d|f | j dkr|d | jr|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r|d | jd	kr|d ||fS )Nr   r   rt   r}   rv   rx   centerContinuous)
horizontalr@   r	   )r   rs   )r   rB   )r   ru   )r   rw   rz   r   )r   r|   )justifyLastLiner   )verticalrD   )r   rs   )r   rw   )r   r|   rF   textRotation)wrapTextr   )shrinkToFitr   )readingOrderr   )r   r	   )	r+   r-   rF   r/   r,   rG   rI   rJ   append)rP   changedr   
continuousrX   rX   rY   _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)   )rP   attribsrX   rX   rY   _get_protection_propertiesE  s   

z!Format._get_protection_propertiesc              
      sN    j d u r$d fdd         j j jfD  _  j S )N:c                 3       | ]}  |V  qd S r   
_to_string.0xrP   rX   rY   	<genexpr>S      z)Format._get_format_key.<locals>.<genexpr>)	rO   join_get_font_key_get_border_key_get_fill_key_get_alignment_keyr   r*   r)   r   rX   r   rY   _get_format_keyP  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   r   r   r   r   r   rX   rY   r   `  r   z'Format._get_font_key.<locals>.<genexpr>)r   r   r   r"   r!   r   r    r   r   r   r   r   r   r&   rP   rT   rX   r   rY   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   r   r   r   r   r   rX   rY   r   s  r   z)Format._get_border_key.<locals>.<genexpr>)r   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   r   rX   r   rY   r   q  s   
zFormat._get_border_keyc                    s(   d  fdd j j jfD }|S )Nr   c                 3   r   r   r   r   r   rX   rY   r     r   z'Format._get_fill_key.<locals>.<genexpr>)r   r2   r1   r0   r   rX   r   rY   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   r   r   r   r   r   rX   rY   r     r   z,Format._get_alignment_key.<locals>.<genexpr>)r   r+   r-   rF   r/   r,   rG   rI   r   rX   r   rY   r     s   
	zFormat._get_alignment_keyc                 C   sN   | j d ur| j S |  }|| jv r| j| S dt| j }|| j|< || _ |S )Nr   )r   r   r   lenrP   rT   indexrX   rX   rY   _get_xf_index  s   



zFormat._get_xf_indexc                 C   sJ   | j d ur| j S |  }|| jv r| j| S t| j}|| j|< || _ |S r   )r   r   r   r   r   rX   rX   rY   _get_dxf_index  s   




zFormat._get_dxf_indexc                 C   sx   i 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}||v r:|| }|S ) Nblackz#000000bluez#0000FFbrownz#800000cyanz#00FFFFgrayz#808080greenz#008000limez#00FF00magentaz#FF00FFnavyz#000080orangez#FF6600pinkpurplez#800080redz#FF0000silverz#C0C0C0whitez#FFFFFFyellowz#FFFF00rX   )rP   r   named_colorsrX   rX   rY   rd     sH   	
zFormat._get_colorc                 C   s(   zt |W S  ty   |d Y S w )Nzutf-8)strUnicodeEncodeErrorencode)rP   rU   rX   rX   rY   r     s
   
zFormat._to_string)NNN)r   )T)r   r   )r   )K__name__
__module____qualname____doc__r   r]   r`   rf   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rd   r   __classcell__rX   rX   rV   rY   r      s    ^










3


















T	r   N) r   warningsr   	XMLwriterr   rX   rX   rX   rY   <module>   s   	