o
    ]i~                     @   sJ   d dl mZmZ d dlmZ d dlmZ ddlmZ G dd dej	Z
dS )	    )LiteralUnion)warn)Color   )	xmlwriterc                       sF  e Zd ZdZddՇ fddZdefddZddd	ZddeddfddZ	de
eef ddfddZddeddfddZddeddfddZdded ddfddZddeddfddZdd ed! ddfd"d#Zdd$eddfd%d&Zdd'eddfd(d)Zd*eddfd+d,Zdd-eddfd.d/Zdd0eddfd1d2Zd3ed4 ddfd5d6Zddd8d9Zdd:eddfd;d<Zd=eddfd>d?Zdd@eddfdAdBZddCeddfdDdEZddFeddfdGdHZddIeddfdJdKZ dLe
eef ddfdMdNZ!dOe
eef ddfdPdQZ"ddReddfdSdTZ#dUe
eef ddfdVdWZ$ddXeddfdYdZZ%d[e
eef ddfd\d]Z&dd^ed_ ddfd`daZ'ddbeddfdcddZ(dee
eef ddfdfdgZ)ddheddfdidjZ*dke
eef ddfdldmZ+ddneddfdodpZ,dqe
eef ddfdrdsZ-dte
eef ddfdudvZ.ddweddfdxdyZ/ddzeddfd{d|Z0dd}eddfd~dZ1ddeddfddZ2ddeddfddZ3deddfddZ4deddfddZ5deddfddZ6deddfddZ7deddfddZ8deddfddZ9ddeddfddZ:ded4 ddfddZ;deddfddZ<deddfddZ=deddfddZ>deddfddZ?deddfddZ@deddfddZAddeddfddZBded ddfddZCddeddfddZDdeddfddZEdeddfddZFde
eef ddfddZGddÄ ZHddń ZIddǄ ZJddɄ ZKdd˄ ZLdd̈́ ZMddτ ZNddф ZOddӄ ZP  ZQS )Formatz;
    A class for writing the Excel XLSX Format file.


    Nreturnc                    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__ V/var/www/html/stock_analysis/be/venv/lib/python3.10/site-packages/xlsxwriter/format.pyr       s   

zFormat.__init__c                 C   sv   d| j d| j d| j d| j d| j d| j d| jd| j d	| j d
| j	 d| j
 d| j d| j d| j dS )zH
        Return a string representation of the Format instance.
        zFormat(font_name=z, font_size=z, bold=z	, italic=z, underline=z, font_color=z, num_format=z, text_h_align=z, text_v_align=z, fg_color=z, bg_color=z
, pattern=z	, locked=z	, hidden=))r   r   r   r   r   r    r   r/   r1   r4   r5   r6   r.   r-   rV   r^   r^   r_   __repr__{   s<   	
zFormat.__repr__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   rV   r   r^   r^   r_   set_font_name      
zFormat.set_font_namer   r   c                 C   rc   )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   rV   r   r^   r^   r_   set_font_size      
zFormat.set_font_sizer    c                 C      t || _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r   _from_valuer    rV   r    r^   r^   r_   set_font_color      zFormat.set_font_colorTr   c                 C   rc   )z
        Set the Format bold property.

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

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_bold   rk   zFormat.set_boldr   c                 C   rc   )z
        Set the Format italic property.

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

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   
set_italic   rk   zFormat.set_italicr   r   )r   r   !   "   c                 C   rc   )z
        Set the Format underline property.

        Args:
            underline: Default is 1, single underline.

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_underline   rk   zFormat.set_underliner!   c                 C   rc   )z
        Set the Format font_strikeout property.

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

        Returns:
            Nothing.

        N)r!   )rV   r!   r^   r^   r_   set_font_strikeout   rk   zFormat.set_font_strikeoutr$   )r   r   c                 C   rc   )z
        Set the Format font_script property.

        Args:
            font_script: Default is 1, superscript.

        Returns:
            Nothing.

        N)r$   )rV   r$   r^   r^   r_   set_font_script   rk   zFormat.set_font_scriptr"   c                 C   rc   )z
        Set the Format font_outline property.

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

        Returns:
            Nothing.

        N)r"   )rV   r"   r^   r^   r_   set_font_outline   rk   zFormat.set_font_outliner#   c                 C   rc   )z
        Set the Format font_shadow property.

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

        Returns:
            Nothing.

        N)r#   )rV   r#   r^   r^   r_   set_font_shadow  rk   zFormat.set_font_shadowr   c                 C   rc   )z
        Set the Format num_format property such as '#,##0'.

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

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_num_format  rk   zFormat.set_num_formatr.   c                 C   rc   )z
        Set the Format locked property.

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

        Returns:
            Nothing.

        N)r.   )rV   r.   r^   r^   r_   
set_locked'  rk   zFormat.set_lockedr-   c                 C   rc   )z
        Set the Format hidden property.

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

        Returns:
            Nothing.

        N)r-   )rV   r-   r^   r^   r_   
set_hidden4  rk   zFormat.set_hidden	alignment)rD   centrecenterrF   filljustifycenter_acrosscentre_acrossdistributedjustify_distributedr   rH   vcentrevcenterr?   vjustifyvdistributedc                 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.
        rD   r   r   r   r   rF      r      r      r      r   r      r   rH   r   r   r?   r   r   N)lowerset_text_h_alignrN   set_text_v_align)rV   r~   r^   r^   r_   	set_alignA  sH   














zFormat.set_align
align_typec                 C   s   |  d dS )z`
        Set the Format center_across property.

        Returns:
            Nothing.

        r   N)r   )rV   r   r^   r^   r_   set_center_across  s   	zFormat.set_center_acrossr0   c                 C   rc   )z
        Set the Format text_wrap property.

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

        Returns:
            Nothing.

        N)r0   )rV   r0   r^   r^   r_   set_text_wrap  rk   zFormat.set_text_wrapr3   c                 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   r3   )rV   r3   r^   r^   r_   set_rotation  s   

zFormat.set_rotationrJ   c                 C   rc   )z
        Set the Format indent property.

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

        Returns:
            Nothing.

        N)rJ   )rV   rJ   r^   r^   r_   
set_indent  rk   zFormat.set_indentrK   c                 C   rc   )z
        Set the Format shrink property.

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

        Returns:
            Nothing.

        N)rK   )rV   rK   r^   r^   r_   
set_shrink  rk   zFormat.set_shrinkr2   c                 C   rc   )z
        Set the Format text_justlast property.

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

        Returns:
            Nothing.

        N)r2   )rV   r2   r^   r^   r_   set_text_justlast  rk   zFormat.set_text_justlastr6   c                 C   rc   )z
        Set the Format pattern property.

        Args:
            pattern: Default is 1, solid fill.

        Returns:
            Nothing.

        N)r6   )rV   r6   r^   r^   r_   set_pattern  rk   zFormat.set_patternr5   c                 C   rl   )z
        Set the Format bg_color property.

        Args:
            bg_color: Background color. No default.

        Returns:
            Nothing.

        N)r   rn   r5   )rV   r5   r^   r^   r_   set_bg_color  rq   zFormat.set_bg_colorr4   c                 C   rl   )z
        Set the Format fg_color property.

        Args:
            fg_color: Foreground color. No default.

        Returns:
            Nothing.

        N)r   rn   r4   )rV   r4   r^   r^   r_   set_fg_color  rq   zFormat.set_fg_colorstylec                 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)rV   r   r^   r^   r_   
set_border	     


zFormat.set_bordercolorc                 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)rV   r   r^   r^   r_   set_border_color  r   zFormat.set_border_colorr?   c                 C   rc   r   )r?   )rV   r?   r^   r^   r_   r   *  rk   zFormat.set_bottomr@   c                 C   rl   )z
        Set the Format bottom_color property.

        Args:
            bottom_color: Color string. No default.

        Returns:
            Nothing.

        N)r   rn   r@   )rV   r@   r^   r^   r_   r   7  rq   zFormat.set_bottom_colorrC   )r   r   r   c                 C   rc   )z
        Set the Format diag_type property.

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

        Returns:
            Nothing.

        N)rC   )rV   rC   r^   r^   r_   set_diag_typeD  rk   zFormat.set_diag_typerD   c                 C   rc   )z
        Set the Format left property.

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

        Returns:
            Nothing.

        N)rD   )rV   rD   r^   r^   r_   r   Q  rk   zFormat.set_leftrE   c                 C   rl   )z
        Set the Format left_color property.

        Args:
            left_color: Color string. No default.

        Returns:
            Nothing.

        N)r   rn   rE   )rV   rE   r^   r^   r_   r   ^  rq   zFormat.set_left_colorrF   c                 C   rc   )z
        Set the Format right property.

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

        Returns:
            Nothing.

        N)rF   )rV   rF   r^   r^   r_   r   k  rk   zFormat.set_rightrG   c                 C   rl   )z
        Set the Format right_color property.

        Args:
            right_color: Color string. No default.

        Returns:
            Nothing.

        N)r   rn   rG   )rV   rG   r^   r^   r_   r   x  rq   zFormat.set_right_colorrH   c                 C   rc   )z
        Set the Format top property.

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

        Returns:
            Nothing.

        N)rH   )rV   rH   r^   r^   r_   r     rk   zFormat.set_toprI   c                 C   rl   )z
        Set the Format top_color property.

        Args:
            top_color: Color string. No default.

        Returns:
            Nothing.

        N)r   rn   rI   )rV   rI   r^   r^   r_   r     rq   zFormat.set_top_colorrB   c                 C   rl   )z
        Set the Format diag_color property.

        Args:
            diag_color: Color string. No default.

        Returns:
            Nothing.

        N)r   rn   rB   )rV   rB   r^   r^   r_   set_diag_color  rq   zFormat.set_diag_colorrA   c                 C   rc   )z
        Set the Format diag_border property.

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

        Returns:
            Nothing.

        N)rA   )rV   rA   r^   r^   r_   set_diag_border  rk   zFormat.set_diag_borderrQ   c                 C   rc   )z
        Set the Format quote prefix property.

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

        Returns:
            Nothing.

        N)rQ   )rV   rQ   r^   r^   r_   set_quote_prefix  rk   zFormat.set_quote_prefixrR   c                 C   rc   )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)rR   )rV   rR   r^   r^   r_   set_checkbox  s   
zFormat.set_checkboxr   c                 C   rc   )z
        Set the property to indicate the format has a font.

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

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_has_font  rk   zFormat.set_has_fontr7   c                 C   rc   )z
        Set the property to indicate the format has a fill.

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

        Returns:
            Nothing.

        N)r7   )rV   r7   r^   r^   r_   set_has_fill  rk   zFormat.set_has_fillr   c                 C   rc   )z
        Set the unique font index property.

        Args:
            font_index: The unique font index.

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_font_index  rk   zFormat.set_font_indexr   c                 C   rc   )z
        Set the unique format index property.

        Args:
            xf_index: The unique Excel format index.

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_xf_index  rk   zFormat.set_xf_indexr   c                 C   rc   )z
        Set the unique conditional format index property.

        Args:
            dxf_index: The unique Excel conditional format index.

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_dxf_index  rk   zFormat.set_dxf_indexr   c                 C   rc   )z
        Set the number format_index property.

        Args:
            num_format_index: The unique number format index.

        Returns:
            Nothing.

        N)r   )rV   r   r^   r^   r_   set_num_format_index   rk   zFormat.set_num_format_indexr/   c                 C   rc   )z
        Set the horizontal text alignment property.

        Args:
            text_h_align: Horizontal text alignment.

        Returns:
            Nothing.

        N)r/   )rV   r/   r^   r^   r_   r   -  rk   zFormat.set_text_h_alignr1   c                 C   rc   )z
        Set the vertical text alignment property.

        Args:
            text_h_align: Vertical text alignment.

        Returns:
            Nothing.

        N)r1   )rV   r1   r^   r^   r_   r   :  rk   zFormat.set_text_v_alignr   	directionc                 C   rc   )z
        Set the reading order property.

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

        Returns:
            Nothing.

        N)rM   )rV   r   r^   r^   r_   set_reading_orderG  rg   zFormat.set_reading_orderalignc                 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   )rV   r   r^   r^   r_   
set_valignU  s   &zFormat.set_valignr%   c                 C   rc   )z
        Set the font family property.

        Args:
            font_family: Font family number.

        Returns:
            Nothing.

        N)r%   )rV   r%   r^   r^   r_   set_font_family}  rk   zFormat.set_font_familyr&   c                 C   rc   )z
        Set the font character set property.

        Args:
            font_charset: The font character set number.

        Returns:
            Nothing.

        N)r&   )rV   r&   r^   r^   r_   set_font_charset  rk   zFormat.set_font_charsetr'   c                 C   rc   )z
        Set the font scheme property.

        Args:
            font_scheme: The font scheme.

        Returns:
            Nothing.

        N)r'   )rV   r'   r^   r^   r_   set_font_scheme  rk   zFormat.set_font_schemer(   c                 C   rc   )z
        Set the font condense property.

        Args:
            font_condense: The font condense property.

        Returns:
            Nothing.

        N)r(   )rV   r(   r^   r^   r_   set_font_condense  rk   zFormat.set_font_condenser)   c                 C   rc   )z
        Set the font extend property.

        Args:
            font_extend: The font extend property.

        Returns:
            Nothing.

        N)r)   )rV   r)   r^   r^   r_   set_font_extend  rk   zFormat.set_font_extendr*   c                 C   rc   )z
        Set the theme property.

        Args:
            theme: Format theme.

        Returns:
            Nothing.

        N)r*   )rV   r*   r^   r^   r_   	set_theme  rk   zFormat.set_themer+   c                 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,   rv   r   r+   )rV   r+   r^   r^   r_   set_hyperlink  s   


zFormat.set_hyperlinkcolor_index)r   r   c                 C   rc   )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)rO   )rV   r   r^   r^   r_   set_color_indexed  rg   zFormat.set_color_indexedrP   c                 C   rc   )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)rP   )rV   rP   r^   r^   r_   set_font_only  rk   zFormat.set_font_onlyr   c                 C   rc   )z(Deprecated: Use set_font_name() instead.Nrd   re   r^   r^   r_   set_font     
zFormat.set_fontc                 C   rc   )z(Deprecated: Use set_font_size() instead.Nrh   ri   r^   r^   r_   set_size  r   zFormat.set_sizec                 C   rl   )z)Deprecated: Use set_font_color() instead.Nrm   ro   r^   r^   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   r   r   r   r   centerContinuous)
horizontalrD   r   )r   r   )r   rF   )r   r   )r   r   r   r   )r   r   )justifyLastLiner   )verticalrH   )r   r   )r   r   )r   r   textRotationrJ   )wrapTextr   )shrinkToFitr   )readingOrderr   )r   r   )	r/   r1   rJ   r3   r0   rK   rM   rN   append)rV   changedr   
continuousr^   r^   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-   )rV   
attributesr^   r^   r_   _get_protection_propertiesl  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xr^   r^   r_   	<genexpr>z  
    
z)Format._get_format_key.<locals>.<genexpr>)rU   join_get_font_key_get_border_key_get_fill_key_get_alignment_keyr   r.   rR   rQ   r-   ra   r^   r^   r_   _get_format_keyw  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   r^   r^   r_   r     r   z'Format._get_font_key.<locals>.<genexpr>)r   r   r    r&   r%   r"   r$   r#   r!   r   r   r   r   r*   rV   rZ   r^   r^   r_   r     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   r^   r^   r_   r     r   z)Format._get_border_key.<locals>.<genexpr>)r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   r   r^   r^   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   r^   r^   r_   r     s    z'Format._get_fill_key.<locals>.<genexpr>)r   r6   r5   r4   r   r^   r^   r_   r     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   r^   r^   r_   r     r   z,Format._get_alignment_key.<locals>.<genexpr>)r   r/   r1   rJ   r3   r0   rK   rM   r   r^   r^   r_   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rV   rZ   indexr^   r^   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   r^   r^   r_   _get_dxf_index  s   




zFormat._get_dxf_index)NNN)r	   N)r   )T)r   r   )r   Nr	   N)r   )R__name__
__module____qualname____doc__r   r   rb   rf   r   rj   r   r   rp   boolrr   rs   r   rv   rw   rx   ry   rz   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   r   r   r   __classcell__r^   r^   r\   r_   r      s    [

H
(
`r   N)typingr   r   warningsr   xlsxwriter.colorr    r   	XMLwriterr   r^   r^   r^   r_   <module>   s
   
