o
    ,hv                     @   s.   d dl mZ ddlmZ G dd dejZdS )    )warn   )	xmlwriterc                       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*ddTdUZ+ddVdWZ,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0d`da Z1dbdc Z2ddedfZ3dgdh Z4didj Z5dkdl Z6dmdn Z7dodp Z8dqdr Z9dsdt Z:ddudvZ;dwdx Z<ddydzZ=d{d| Z>d}d~ Z?dd Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJ  ZKS )Formatz;
    A class for writing the Excel XLSX Format file.


    Nc                    s  |du ri }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| _/d| _0d| _1d| _2d| _3d| _4d| _5d| _6d| _7d| _8d| _9d| _:d| _;d| _<d| _=d| _>d| _?d| _@d| _Ad| _B|C D ]\}}tD| d
| | qd| _EdS )z
        Constructor.

        NGeneralr   FCalibri      minorr   set_)Fsuper__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quote_prefixcheckboxitemsgetattr_format_key)self
properties
xf_indicesdxf_indiceskeyvalue	__class__ G/var/www/html/rh/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   rR   r   rZ   rZ   r[   set_font_name~      
zFormat.set_font_namer   c                 C   r\   )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   rR   r   rZ   rZ   r[   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   rR   r   rZ   rZ   r[   set_font_color      zFormat.set_font_colorTc                 C   r\   )z
        Set the Format bold property.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_bold   rd   zFormat.set_boldc                 C   r\   )z
        Set the Format italic property.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   
set_italic   rd   zFormat.set_italicr   c                 C   r\   )z
        Set the Format underline property.

        Args:
            underline: Default is 1, single underline.

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_underline   rd   zFormat.set_underlinec                 C   r\   )z
        Set the Format font_strikeout property.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_font_strikeout   rd   zFormat.set_font_strikeoutc                 C   r\   )z
        Set the Format font_script property.

        Args:
            font_script: Default is 1, superscript.

        Returns:
            Nothing.

        N)r    )rR   r    rZ   rZ   r[   set_font_script   rd   zFormat.set_font_scriptc                 C   r\   )z
        Set the Format font_outline property.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_font_outline   rd   zFormat.set_font_outlinec                 C   r\   )z
        Set the Format font_shadow property.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_font_shadow   rd   zFormat.set_font_shadowc                 C   r\   )z
        Set the Format num_format property such as '#,##0'.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_num_format  rd   zFormat.set_num_formatc                 C   r\   )z
        Set the Format locked property.

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

        Returns:
            Nothing.

        N)r*   )rR   r*   rZ   rZ   r[   
set_locked  rd   zFormat.set_lockedc                 C   r\   )z
        Set the Format hidden property.

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

        Returns:
            Nothing.

        N)r)   )rR   r)   rZ   rZ   r[   
set_hidden  rd   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)rR   	alignmentrZ   rZ   r[   	set_align(  sH   















zFormat.set_alignc                 C   s   |  d dS )z`
        Set the Format center_across property.

        Returns:
            Nothing.

        r}   N)r   )rR   
align_typerZ   rZ   r[   set_center_across[  s   	zFormat.set_center_acrossc                 C   r\   )z
        Set the Format text_wrap property.

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

        Returns:
            Nothing.

        N)r,   )rR   r,   rZ   rZ   r[   set_text_wrapf  rd   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/   )rR   r/   rZ   rZ   r[   set_rotations  s   

zFormat.set_rotationc                 C   r\   )z
        Set the Format indent property.

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

        Returns:
            Nothing.

        N)rF   )rR   rF   rZ   rZ   r[   
set_indent  rd   zFormat.set_indentc                 C   r\   )z
        Set the Format shrink property.

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

        Returns:
            Nothing.

        N)rG   )rR   rG   rZ   rZ   r[   
set_shrink  rd   zFormat.set_shrinkc                 C   r\   )z
        Set the Format text_justlast property.

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

        Returns:
            Nothing.

        N)r.   )rR   r.   rZ   rZ   r[   set_text_justlast  rd   zFormat.set_text_justlastc                 C   r\   )z
        Set the Format pattern property.

        Args:
            pattern: Default is 1, solid fill.

        Returns:
            Nothing.

        N)r2   )rR   r2   rZ   rZ   r[   set_pattern  rd   zFormat.set_patternc                 C   re   )z
        Set the Format bg_color property.

        Args:
            bg_color: Background color. No default.

        Returns:
            Nothing.

        N)rg   r1   )rR   r1   rZ   rZ   r[   set_bg_color  rj   zFormat.set_bg_colorc                 C   re   )z
        Set the Format fg_color property.

        Args:
            fg_color: Foreground color. No default.

        Returns:
            Nothing.

        N)rg   r0   )rR   r0   rZ   rZ   r[   set_fg_color  rj   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)rR   stylerZ   rZ   r[   
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)rR   colorrZ   rZ   r[   set_border_color  r   zFormat.set_border_colorc                 C   r\   r   )r;   )rR   r;   rZ   rZ   r[   r     rd   zFormat.set_bottomc                 C   re   )z
        Set the Format bottom_color property.

        Args:
            bottom_color: Color string. No default.

        Returns:
            Nothing.

        N)rg   r<   )rR   r<   rZ   rZ   r[   r   	  rj   zFormat.set_bottom_colorc                 C   r\   )z
        Set the Format diag_type property.

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

        Returns:
            Nothing.

        N)r?   )rR   r?   rZ   rZ   r[   set_diag_type  rd   zFormat.set_diag_typec                 C   r\   )z
        Set the Format left property.

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

        Returns:
            Nothing.

        N)r@   )rR   r@   rZ   rZ   r[   r   #  rd   zFormat.set_leftc                 C   re   )z
        Set the Format left_color property.

        Args:
            left_color: Color string. No default.

        Returns:
            Nothing.

        N)rg   rA   )rR   rA   rZ   rZ   r[   r   0  rj   zFormat.set_left_colorc                 C   r\   )z
        Set the Format right property.

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

        Returns:
            Nothing.

        N)rB   )rR   rB   rZ   rZ   r[   r   =  rd   zFormat.set_rightc                 C   re   )z
        Set the Format right_color property.

        Args:
            right_color: Color string. No default.

        Returns:
            Nothing.

        N)rg   rC   )rR   rC   rZ   rZ   r[   r   J  rj   zFormat.set_right_colorc                 C   r\   )z
        Set the Format top property.

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

        Returns:
            Nothing.

        N)rD   )rR   rD   rZ   rZ   r[   r   W  rd   zFormat.set_topc                 C   re   )z
        Set the Format top_color property.

        Args:
            top_color: Color string. No default.

        Returns:
            Nothing.

        N)rg   rE   )rR   rE   rZ   rZ   r[   r   d  rj   zFormat.set_top_colorc                 C   re   )z
        Set the Format diag_color property.

        Args:
            diag_color: Color string. No default.

        Returns:
            Nothing.

        N)rg   r>   )rR   r>   rZ   rZ   r[   set_diag_colorq  rj   zFormat.set_diag_colorc                 C   r\   )z
        Set the Format diag_border property.

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

        Returns:
            Nothing.

        N)r=   )rR   r=   rZ   rZ   r[   set_diag_border~  rd   zFormat.set_diag_borderc                 C   r\   )z
        Set the Format quote prefix property.

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

        Returns:
            Nothing.

        N)rM   )rR   rM   rZ   rZ   r[   set_quote_prefix  rd   zFormat.set_quote_prefixc                 C   r\   )a  
        Set the Format property to show a checkbox in a cell.

        This format property can be used with a cell that contains a boolean
        value to display it as a checkbox. This property isn't required very
        often and it is generally easier to create a checkbox using the
        ``worksheet.insert_checkbox()`` method.

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

        Returns:
            Nothing.

        N)rN   )rR   rN   rZ   rZ   r[   set_checkbox  s   
zFormat.set_checkboxc                 C   r\   )z
        Set the property to indicate the format has a font.

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

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_has_font  rd   zFormat.set_has_fontc                 C   r\   )z
        Set the property to indicate the format has a fill.

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

        Returns:
            Nothing.

        N)r3   )rR   r3   rZ   rZ   r[   set_has_fill  rd   zFormat.set_has_fillc                 C   r\   )z
        Set the unique font index property.

        Args:
            font_index: The unique font index.

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_font_index  rd   zFormat.set_font_indexc                 C   r\   )z
        Set the unique format index property.

        Args:
            xf_index: The unique Excel format index.

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_xf_index  rd   zFormat.set_xf_indexc                 C   r\   )z
        Set the unique conditional format index property.

        Args:
            dxf_index: The unique Excel conditional format index.

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_dxf_index  rd   zFormat.set_dxf_indexc                 C   r\   )z
        Set the number format_index property.

        Args:
            num_format_index: The unique number format index.

        Returns:
            Nothing.

        N)r   )rR   r   rZ   rZ   r[   set_num_format_index  rd   zFormat.set_num_format_indexc                 C   r\   )z
        Set the horizontal text alignment property.

        Args:
            text_h_align: Horizontal text alignment.

        Returns:
            Nothing.

        N)r+   )rR   r+   rZ   rZ   r[   r     rd   zFormat.set_text_h_alignc                 C   r\   )z
        Set the vertical text alignment property.

        Args:
            text_h_align: Vertical text alignment.

        Returns:
            Nothing.

        N)r-   )rR   r-   rZ   rZ   r[   r     rd   zFormat.set_text_v_alignr   c                 C   r\   )z
        Set the reading order property.

        Args:
            direction: Default is 0, left to right.

        Returns:
            Nothing.

        N)rI   )rR   	directionrZ   rZ   r[   set_reading_order  r`   zFormat.set_reading_orderc                 C   s   |  | dS )a  
        Set vertical cell alignment property.

        This is required by the constructor properties dict to differentiate
        between the vertical and horizontal properties.

        Args:
            align: Alignment property.

        Returns:
            Nothing.

        N)r   )rR   alignrZ   rZ   r[   
set_valign'  s   zFormat.set_valignc                 C   r\   )z
        Set the font family property.

        Args:
            font_family: Font family number.

        Returns:
            Nothing.

        N)r!   )rR   r!   rZ   rZ   r[   set_font_family:  rd   zFormat.set_font_familyc                 C   r\   )z
        Set the font character set property.

        Args:
            font_charset: The font character set number.

        Returns:
            Nothing.

        N)r"   )rR   r"   rZ   rZ   r[   set_font_charsetG  rd   zFormat.set_font_charsetc                 C   r\   )z
        Set the font scheme property.

        Args:
            font_scheme: The font scheme.

        Returns:
            Nothing.

        N)r#   )rR   r#   rZ   rZ   r[   set_font_schemeT  rd   zFormat.set_font_schemec                 C   r\   )z
        Set the font condense property.

        Args:
            font_condense: The font condense property.

        Returns:
            Nothing.

        N)r$   )rR   r$   rZ   rZ   r[   set_font_condensea  rd   zFormat.set_font_condensec                 C   r\   )z
        Set the font extend property.

        Args:
            font_extend: The font extend property.

        Returns:
            Nothing.

        N)r%   )rR   r%   rZ   rZ   r[   set_font_extendn  rd   zFormat.set_font_extendc                 C   r\   )z
        Set the theme property.

        Args:
            theme: Format theme.

        Returns:
            Nothing.

        N)r&   )rR   r&   rZ   rZ   r[   	set_theme{  rd   zFormat.set_themec                 C   s$   d| _ | d | d || _dS )z
        Set the properties for the hyperlink style.

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

        Returns:
            Nothing.

        r   
   N)r(   rm   r   r'   )rR   r'   rZ   rZ   r[   set_hyperlink  s   


zFormat.set_hyperlinkc                 C   r\   )z
        Set the color index property. Some fundamental format properties use an
        indexed color instead of a rbg or theme color.

        Args:
            color_index: Generally 0 or 1.

        Returns:
            Nothing.

        N)rK   )rR   color_indexrZ   rZ   r[   set_color_indexed  r`   zFormat.set_color_indexedc                 C   r\   )z
        Set property to indicate that the format is used for fonts only.

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

        Returns:
            Nothing.

        N)rL   )rR   rL   rZ   rZ   r[   set_font_only  rd   zFormat.set_font_onlyc                 C   r\   )z(Deprecated: Use set_font_name() instead.Nr]   r^   rZ   rZ   r[   set_font     
zFormat.set_fontc                 C   r\   )z(Deprecated: Use set_font_size() instead.Nra   rb   rZ   rZ   r[   set_size  r   zFormat.set_sizec                 C   re   )z)Deprecated: Use set_font_color() instead.Nrf   rh   rZ   rZ   r[   	set_color  s   zFormat.set_colorc                 C   sZ  d}g }| j s| js| js| js| js| js| jrd}n||fS | jrD| j dkrD| j dkrD| j dkrD| jdkrD| jdkrD| jdkrDd| _ | jrJd| _| j dkrRd| _| j dkrZd| _| j dkrbd| _| j dkrjd| _| jrpd| _d}| j dkr||d | j d	kr|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   rw   r   r{   ry   centerContinuous)
horizontalr@   r	   )r   rv   )r   rB   )r   rx   )r   rz   r}   r   )r   r   )justifyLastLiner   )verticalrD   )r   rv   )r   rz   )r   r   textRotationrF   )wrapTextr   )shrinkToFitr   )readingOrderr   )r   r	   )	r+   r-   rF   r/   r,   rG   rI   rJ   append)rR   changedr   
continuousrZ   rZ   r[   _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)   )rR   
attributesrZ   rZ   r[   _get_protection_properties)  s   

z!Format._get_protection_propertiesc                 C   sR   | j d u r&ddd |  |  |  |  | j| j| j| j	| j
f	D | _ | j S )N:c                 s       | ]}t |V  qd S Nstr.0xrZ   rZ   r[   	<genexpr>7  
    
z)Format._get_format_key.<locals>.<genexpr>)rQ   join_get_font_key_get_border_key_get_fill_key_get_alignment_keyr   r*   rN   rM   r)   )rR   rZ   rZ   r[   _get_format_key4  s   


zFormat._get_format_keyc                 C   sL   d dd | j| j| j| j| j| j| j| j| j	| j
| j| j| jfD }|S )Nr   c                 s   r   r   r   r   rZ   rZ   r[   r   J  r   z'Format._get_font_key.<locals>.<genexpr>)r   r   r   r"   r!   r   r    r   r   r   r   r   r   r&   rR   rV   rZ   rZ   r[   r   H  s"   
zFormat._get_font_keyc                 C   sD   d dd | j| j| j| j| j| j| j| j| j	| j
| jfD }|S )Nr   c                 s   r   r   r   r   rZ   rZ   r[   r   a  r   z)Format._get_border_key.<locals>.<genexpr>)r   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   r   rZ   rZ   r[   r   _  s   
zFormat._get_border_keyc                 C   s$   d dd | j| j| jfD }|S )Nr   c                 s   r   r   r   r   rZ   rZ   r[   r   v  s    z'Format._get_fill_key.<locals>.<genexpr>)r   r2   r1   r0   r   rZ   rZ   r[   r   t  s    zFormat._get_fill_keyc              
   C   s4   d dd | j| j| j| j| j| j| jfD }|S )Nr   c                 s   r   r   r   r   rZ   rZ   r[   r   }  r   z,Format._get_alignment_key.<locals>.<genexpr>)r   r+   r-   rF   r/   r,   rG   rI   r   rZ   rZ   r[   r   z  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rR   rV   indexrZ   rZ   r[   _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   rZ   rZ   r[   _get_dxf_index  s   




zFormat._get_dxf_indexc                 C   sv   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d d!}| ||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#FFFF00	automatic	Automatic)get)rR   r   named_colorsrZ   rZ   r[   rg     sH   	
zFormat._get_color)NNN)r   )T)r   r   )r   )L__name__
__module____qualname____doc__r   r_   rc   ri   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   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   r   r   rg   __classcell__rZ   rZ   rX   r[   r      s    a










3



















`r   N)warningsr    r   	XMLwriterr   rZ   rZ   rZ   r[   <module>   s   
