
    	i4                         d dl mZ d dlmZmZmZ g dg dg dg dg dg dg d	g d
g dg dg
Z G d de          Z G d d          ZdS )    )Enum)ListTupleUnion))bg1r   r   )r   s r   )r   L r   )r   $ r   )r     r   )r   P  r   ))tx1r   r   )r   r   r   )r   r   i  )r   r
   a  )r   r	   i:  )r   r   i  ))bg2r   r   )r   i_ r   )r   r
   r   )r   r   r   )r   r   r   )r   i'  r   ))tx2r   r   )r    N  8 )r   @  `  )r   r   r   )r   r
   r   )r   r   r   ))accent1r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   ))accent2r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   ))accent3r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   ))accent4r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   ))accent5r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   ))accent6r   r   )r   r   r   )r   r   r   )r   r   r   )r   r
   r   )r   r   r   c                       e Zd ZdZdZdZdS )
ColorTypesz4
    Enum to represent different types of URLS.
          N)__name__
__module____qualname____doc__RGBTHEME     H/srv/django_bis/venv311/lib/python3.11/site-packages/xlsxwriter/color.pyr   r   l   s$          CEEEr&   r   c                   v   e Zd ZdZdeeeeeef         f         ddfdZdefdZ	e
ded ef         dd fd            Ze
dedd fd	            Ze
dedd fd
            Ze
dededd fd            Ze
dd            ZdeddfdZdefdZdefdZdefdZdeeeef                  fdZdeeeef         fdZdS )Colorz/
    A class to represent an Excel color.

    colorreturnNc                    d| _         t          j        | _        d| _        d| _        t          |t                    r(|                     |           t          j        | _        dS t          |t                    r/|dk    rt          d          || _         t          j        | _        dS t          |t                    r|t          |          dk    rit          d |D                       rP|d         dk    rt          d	          |d
         dk    rt          d          || _        t          j        | _        dS t          d          )z
        Initialize a Color instance.

        Args:
            color (Union[str, int, Tuple[int, int]]): The value of the color
            (e.g., a hex string, an integer, or a tuple of two integers).
        r   )r   r   F 3RGB color must be in the range 0x000000 - 0xFFFFFF.r   c              3   @   K   | ]}t          |t                    V  d S )N)
isinstanceint).0vs     r'   	<genexpr>z!Color.__init__.<locals>.<genexpr>   s,      661Jq#&&666666r&   	   %Theme color must be in the range 0-9.r      %Theme shade must be in the range 0-5.z9Invalid color value. Must be a string, integer, or tuple.N)
_rgb_valuer   r#   _type_theme_color_is_automaticr0   str_parse_string_colorr1   
ValueErrortuplelenallr$   )selfr*   s     r'   __init__zColor.__init__{   s<     (!+
-3#(eS!! 	$$U+++#DJJJs## 	x !VWWW#DO#DJJJue$$	E

a6666666   Qx!|| !HIIIQx!|| !HIII %D#)DJJJK  r&   c                     | j         t          j        k    rd| j        d}nd| j        d          d| j        d          d}d| d	| j         j         d
| j         dS )zG
        Return a string representation of the Color instance.
        0x06XzTheme(r   z, r   )zColor(value=z, type=z, is_automatic=)r:   r   r#   r9   r;   namer<   )rC   values     r'   __repr__zColor.__repr__   s     :''....EELT.q1LLT5Fq5ILLLE22 2JO2 2 !.2 2 2	
r&   rJ   c                     t          | t                    r| S t          | t                    rt          |           S t          d          )a  
        Internal method to convert a string to a Color instance or return the
        Color instance if already provided. This is mainly used for backward
        compatibility support in the XlsxWriter API.

        Args:
            value (Union[Color, str]): A Color instance or a string representing
            a color.

        Returns:
            Color: A Color instance.
        z+Value must be a Color instance or a string.)r0   r)   r=   	TypeError)rJ   s    r'   _from_valuezColor._from_value   sH     eU## 	LeS!! 	 <<EFFFr&   c                      t          |           S )a  
        Create a user-defined RGB color from a Html color string.

        Args:
            color (int): An RGB value in the range 0x000000 (black) to 0xFFFFFF (white).

        Returns:
            Color: A Color object representing an Excel RGB color.
        )r)   r*   s    r'   rgbz	Color.rgb   s     U||r&   c                 J    | dk    rt          d          t          |           S )a  
        Create a user-defined RGB color from an integer value.

        Args:
            color (int): An RGB value in the range 0x000000 (black) to 0xFFFFFF (white).

        Returns:
            Color: A Color object representing an Excel RGB color.
        r-   r.   r?   r)   rP   s    r'   rgb_integerzColor.rgb_integer   s*     8RSSSU||r&   shadec                 x    | dk    rt          d          |dk    rt          d          t          | |f          S )z
        Create a theme color.

        Args:
            color (int): The theme color index (0-9).
            shade (int): The theme shade index (0-5).

        Returns:
            Color: A Color object representing an Excel Theme color.
        r5   r6   r7   r8   rS   )r*   rU   s     r'   themezColor.theme   sF     199DEEE199DEEEeU^$$$r&   c                  2    t          d          } d| _        | S )a  
        Create an Excel color representing an "Automatic" color.

        The Automatic color for an Excel property is usually the same as the
        Default color but can vary according to system settings. This method and
        color type are rarely used in practice but are included for completeness.

        Returns:
            Color: A Color object representing an Excel Automatic color.
        r   T)r)   r<   rP   s    r'   	automaticzColor.automatic   s     h"r&   c                    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!k    rd"| _        d| _        d%S ||v r||         | _        d%S 	 t	          |d#          | _        d%S # t
          $ r}t          d$|           |d%}~ww xY w)&zx
        Convert a hex string or named color to an RGB value.

        Returns:
            int: The RGB value.
        redi   blue   cyani  grayi limei   navy   pinki  blackr   browni   greeni   whiter-   orangei f purplei  silveri yellowi  magenta#rY   T   zInvalid color value: N)lstriplowerr<   r9   r1   r?   )rC   rJ   named_colorsr*   es        r'   r>   zColor._parse_string_color  sr   
8
H
 H
 H	

 H
 H
 H
 X
 X
 X
 X
 h
 h
 h
 h
  x!
& S!!''))K!%D&DOOOl""*51DOOOI"%eR.. I I I !@!@!@AAqHIs   B 
B=%B88B=c                 T    | j         rdS | j        t          j        k    rdS | j        dS )zx
        Get the RGB hex value for the color.

        Returns:
            str: The RGB hex value as a string.
        000000rG   )r<   r:   r   r$   r9   rC   s    r'   _rgb_hex_valuezColor._rgb_hex_value1  s7      	8:)))8/'''r&   c                 f    | j         rdS d|                                                                  S )z
        Get the RGB hex value for a VML fill color in "#rrggbb" format.

        Returns:
            str: The RGB hex value as a string.
        z#ffffe1rm   )r<   rv   rp   ru   s    r'   _vml_rgb_hex_valuezColor._vml_rgb_hex_valueB  s:      	924&&((..00222r&   c                 0    d|                                   S )z
        Get the ARGB hex value for the color. The alpha channel is always FF.

        Returns:
            str: The ARGB hex value as a string.
        FF)rv   ru   s    r'   _argb_hex_valuezColor._argb_hex_valueO  s     ,D''))+++r&   c                 :   | j         t          j        k    rX| j        \  }}|dk    r|dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |d	k    rdt	          |          fd
gS |dk    rdt	          |          fdgS dt	          |          fgS |dk    r|dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |d	k    rdt	          |          fdgS |dk    rdt	          |          fdgS dt	          |          fgS |dk    r|dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |d	k    rdt	          |          fdgS |dk    rdt	          |          fdgS dt	          |          fgS |dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |dk    rdt	          |          fdgS |d	k    rdt	          |          fdgS |dk    rdt	          |          fdgS dt	          |          fgS | j         t          j        k    rd|                                 fgS g S )z
        Convert the color into a set of "rgb" or "theme/tint" attributes used in
        color-related Style XML elements.

        Returns:
            list[tuple[str, str]]: A list of key-value pairs representing the
            attributes.
        r   r   rW   )tintz-4.9989318521683403E-2r   )r}   z-0.14999847407452621   )r}   z-0.249977111117893   )r}   z-0.34998626667073579r7   )r}   z-0.499984740745262)r}   z0.499984740745262)r}   z0.34998626667073579)r}   z0.249977111117893)r}   z0.14999847407452621)r}   z4.9989318521683403E-2)r}   z-9.9978637043366805E-2)r}   z-0.749992370372631)r}   z-0.89999084444715716)r}   z0.79998168889431442)r}   z0.59999389629810485)r}   z0.39997558519241921rQ   )r:   r   r$   r;   r=   r#   r{   )rC   r*   rU   s      r'   _attributeszColor._attributesX  sA    :))),LE5 zzA::$c%jj13UVVaZZ$c%jj13STTaZZ$c%jj13QRRaZZ$c%jj13STTaZZ$c%jj13QRR$c%jj122!A::$c%jj13PQQaZZ$c%jj13RSSaZZ$c%jj13PQQaZZ$c%jj13RSSaZZ$c%jj13TUU$c%jj122!A::$c%jj13UVVaZZ$c%jj13QRRaZZ$c%jj13QRRaZZ$c%jj13QRRaZZ$c%jj13STT$c%jj122 A::$c%jj13RSSaZZ$c%jj13RSSaZZ$c%jj13RSSaZZ$c%jj13QRRaZZ$c%jj13QRR$c%jj122 Z:>))D0022344 	r&   c                 T    t           | j        d                  | j        d                  S )z
        Return the chart theme based on color and shade.

        Returns:
            Tuple[str, int, int]: The corresponding tuple of values from CHART_THEMES.

        r   r   )CHART_THEMESr;   ru   s    r'   _chart_schemezColor._chart_scheme  s$     D-a01$2CA2FGGr&   )r+   r)   )r   r    r!   r"   r   r=   r1   r   rD   rK   staticmethodrN   rQ   rT   rW   rY   r>   rv   rx   r{   r   r   r   r%   r&   r'   r)   r)   u   s3        
%eCeCHo$=> %4 % % % %N
# 
 
 
 
  G5#. G7 G G G \G* 
3 
7 
 
 
 \
 3 7    \ %S % % % % % \%"    \ (I (I (I (I (I (IT( ( ( ( ("3C 3 3 3 3, , , , ,MT%S/2 M M M M^HuS#s]3 H H H H H Hr&   r)   N)	enumr   typingr   r   r   r   r   r)   r%   r&   r'   <module>r      sG         % % % % % % % % % %                    g[|       zH zH zH zH zH zH zH zH zH zHr&   