U
    ª…7h•-  ã                   @   s`   d dl mZmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZ G dd„ dƒZG dd„ dejƒZd	S )
é    )ÚDictÚListÚOptionalÚUnioné   )Ú	xmlwriter)Ú_preserve_whitespaceÚ	_xl_colorÚxl_cell_to_rowcolÚxl_rowcol_to_cellc                   @   sr   e Zd ZdZdeeeeeeeeee	f f  dœdd„Z
deeeeeee	f f  dœdd„Zeed	œd
d„ZdS )ÚCommentTypez@
    A class to represent a comment in an Excel worksheet.

    N)ÚrowÚcolÚtextÚoptionsc                 C   sŠ   || _ || _|| _d| _d| _d| _d| _d| _d| _d| _	d| _
d| _d| _d| _d| _d| _d	| _g | _|  | j | j¡ |  |¡ dS )
a  
        Initialize a Comment instance.

        Args:
            row (int): The row number of the comment.
            col (int): The column number of the comment.
            text (str): The text of the comment.
            options (dict): Additional options for the comment.
        Nz#ffffe1r   é€   éJ   r   é   ZTahomaé   )r   r   r   ÚauthorÚcolorÚ	start_rowÚ	start_colÚ
is_visibleÚwidthÚheightÚx_scaleÚy_scaleÚx_offsetÚy_offsetÚ	font_sizeÚ	font_nameÚfont_familyZverticesÚset_offsetsÚ_set_user_options)Úselfr   r   r   r   © r&   úM/var/www/formularioweb/env/lib/python3.8/site-packages/xlsxwriter/comments.pyÚ__init__    s(    zCommentType.__init__)r   c                 C   s^  |dkrdS |  d¡}|r.t|ttfƒr.|| _|  d¡}|rPt|ttfƒrP|| _|  d¡}|rnt|tƒrn|| _|  d¡}|rŒt|tƒrŒ|| _|  d¡}|rªt|tƒrª|| _|  d¡}|rÈt|tƒrÈ|| _	|  d¡}|rêt|ttfƒrê|| _
|  d	¡}	|	rt|	tƒr|	| _|  d
¡}
|
r.t|
tƒr.|
| _|  d¡}|rPt|tƒrP|| _|  d¡}|dk	rvt|tƒrv|| _|  d¡}|r®t|tƒr®t|ƒ ¡ }| ddd¡| _|  d¡}|rât|tƒrât|ƒ\}}|| _	|| _|  d¡}|rt|ttfƒr| j| | _|  d¡}|r:t|ttfƒr:| j| | _td| j ƒ| _td| j ƒ| _dS )zh
        This method handles the additional optional parameters to
        ``write_comment()``.
        Nr   r   r   r   r   r   r    r!   r"   r   Úvisibler   Úffú#r   Ú
start_cellr   r   g      à?)ÚgetÚ
isinstanceÚintÚfloatr   r   r   r   r   r   r    Ústrr!   r"   r   Úboolr   r	   ÚlowerÚreplacer   r
   )r%   r   r   r   r   r   r   r   r    r!   r"   r   r)   r   r,   r   r   r&   r&   r'   r$   P   sh    














zCommentType._set_user_options)r   r   c                 C   s  d}d}| j dkr d| _d| _np| j |d kr@d| _|d | _nP| j |d kr`d| _|d | _n0| j |d	 kr€d
| _|d | _nd| _|d	 | _| j|d kr°d| _|d | _nP| j|d krÐd| _|d | _n0| j|d	 krðd| _|d | _nd| _|d	 | _dS )zÚ
        Set the default start cell and offsets for the comment. These are
        generally a fixed offset relative to the parent cell. However there are
        some edge cases for cells at the, well, edges.
        i   i @  r   r   é   é   é   é   r   é   é   é
   é1   é   é   N)r   r   r   r   r   r   )r%   r   r   Zrow_maxZcol_maxr&   r&   r'   r#   ¤   s6    

zCommentType.set_offsets)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r1   r   r   r   r0   r(   r$   r#   r&   r&   r&   r'   r      s   
 ûû1 ÿÿTr   c                       sì   e Zd ZdZ‡ fdd„Zd*eee  dœdd„Zdd	„ Z	ee d
œdd„Z
edœdd„Zee d
œdd„Zeedœdd„Zedœdd„Zedœdd„Zedœdd„Zedœdd„Zedœd d!„Zd"d#„ Zed$œd%d&„Zed'œd(d)„Z‡  ZS )+ÚCommentsz=
    A class for writing the Excel XLSX Comments file.


    c                    s   t ƒ  ¡  i | _dS )z
        Constructor.

        N)Úsuperr(   Ú
author_ids)r%   ©Ú	__class__r&   r'   r(   Ý   s    
zComments.__init__N)Úcomments_datac                 C   sF   |d krg }|   ¡  |  ¡  |  |¡ |  |¡ |  d¡ |  ¡  d S )NÚcomments)Z_xml_declarationÚ_write_commentsÚ_write_authorsÚ_write_comment_listÚ_xml_end_tagZ
_xml_close)r%   rH   r&   r&   r'   Ú_assemble_xml_fileì   s    


zComments._assemble_xml_filec                 C   s   d}d|fg}|   d|¡ d S )Nz9http://schemas.openxmlformats.org/spreadsheetml/2006/mainÚxmlnsrI   )Ú_xml_start_tag)r%   rO   Ú
attributesr&   r&   r'   rJ   	  s    
zComments._write_comments)Úcomment_datac                 C   sZ   d}|   d¡ |D ]8}|j}|d k	r|| jkr|| j|< |d7 }|  |¡ q|  d¡ d S )Nr   Zauthorsr   )rP   r   rE   Ú_write_authorrM   )r%   rR   Zauthor_countÚcommentr   r&   r&   r'   rK     s    

zComments._write_authors)Údatac                 C   s   |   d|¡ d S )Nr   )Ú_xml_data_element)r%   rU   r&   r&   r'   rS   $  s    zComments._write_authorc                 C   sH   |   d¡ |D ]*}d}|jd k	r,| j|j }|  ||¡ q|  d¡ d S )NZcommentListéÿÿÿÿ)rP   r   rE   Ú_write_commentrM   )r%   rR   rT   Ú	author_idr&   r&   r'   rL   (  s    

zComments._write_comment_list)rT   rY   c                 C   sT   t |j|jƒ}d|fg}|dkr0| d|› f¡ |  d|¡ |  |¡ |  d¡ d S )NÚrefrW   ZauthorIdrT   )r   r   r   ÚappendrP   Ú_write_textrM   )r%   rT   rY   rZ   rQ   r&   r&   r'   rX   7  s    

zComments._write_comment)rT   c                 C   s"   |   d¡ |  |¡ |  d¡ d S )Nr   )rP   Ú_write_text_rrM   ©r%   rT   r&   r&   r'   r\   G  s    

zComments._write_textc                 C   s.   |   d¡ |  |¡ |  |j¡ |  d¡ d S )NÚr)rP   Ú_write_r_prÚ_write_text_tr   rM   r^   r&   r&   r'   r]   P  s    

zComments._write_text_r)r   c                 C   s(   g }t |ƒr| d¡ |  d||¡ d S )N)z	xml:spaceZpreserveÚt)r   r[   rV   )r%   r   rQ   r&   r&   r'   ra   \  s    
zComments._write_text_tc                 C   sD   |   d¡ |  |j¡ |  ¡  |  |j¡ |  |j¡ |  d¡ d S )NZrPr)	rP   Ú	_write_szr    Ú_write_colorÚ_write_r_fontr!   Ú_write_familyr"   rM   r^   r&   r&   r'   r`   e  s    
zComments._write_r_pr)r    c                 C   s   d|fg}|   d|¡ d S )NÚvalÚsz©Z_xml_empty_tag)r%   r    rQ   r&   r&   r'   rc   w  s    
zComments._write_szc                 C   s   dg}|   d|¡ d S )N)ZindexedéQ   r   ri   )r%   rQ   r&   r&   r'   rd   }  s    zComments._write_color)r!   c                 C   s   d|fg}|   d|¡ d S )Nrg   ZrFontri   )r%   r!   rQ   r&   r&   r'   re   ƒ  s    
zComments._write_r_font)r"   c                 C   s   d|fg}|   d|¡ d S )Nrg   Úfamilyri   )r%   r"   rQ   r&   r&   r'   rf   ‰  s    
zComments._write_family)N)r?   r@   rA   rB   r(   r   r   r   rN   rJ   rK   r1   rS   rL   r/   rX   r\   r]   ra   r`   r0   rc   rd   re   rf   Ú__classcell__r&   r&   rF   r'   rC   Ð   s    		rC   N)Útypingr   r   r   r   Ú r   Zutilityr   r	   r
   r   r   Z	XMLwriterrC   r&   r&   r&   r'   Ú<module>
   s
    7