U
    7h[U                     @   sH   d dl mZ d dlmZ ddlmZ G dd dZG dd dejZd	S )
    )CommentType)Image   )	xmlwriterc                   @   s4   e Zd ZdZdeeeeeedddZd	ddZdS )

ButtonTypez?
    A class to represent a button in an Excel worksheet.

    N)rowcolheightwidthbutton_numberoptionsc                 C   sd   || _ || _|| _|| _d| d| _d| | _d| _d| _d| _d| _	d| _
g | _| | dS )a  
        Initialize a ButtonType instance.

        Args:
            row (int): The row number of the button.
            col (int): The column number of the button.
            height (int): The height of the button.
            width (int): The width of the button.
            button_number (int): The button number.
            options (dict): Additional options for the button.
        z
[0]!ButtonZ_ClickzButton Nr   r   )r   r   r
   r	   macrocaptiondescriptionx_scaley_scalex_offsety_offsetvertices_set_user_options)selfr   r   r	   r
   r   r    r   H/var/www/formularioweb/env/lib/python3.8/site-packages/xlsxwriter/vml.py__init__   s    zButtonType.__init__c                 C   s   |dkrdS | d| j| _| d| j| _| d| j| _| d| j| _| d| j| _| d| j| _| drd	|d  | _| d
r| j|d
  | _| dr| j|d  | _td| j | _td| j | _dS )zh
        This method handles the additional optional parameters to
        ``insert_button()``.
        Nr
   r	   r   r   r   r   r   z[0]!r   r   g      ?)	getr
   r	   r   r   r   r   r   int)r   r   r   r   r   r   C   s     


zButtonType._set_user_options)N)N)__name__
__module____qualname____doc__r   dictr   r   r   r   r   r   r      s    'r   c                   @   s  e Zd ZdZdZddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zed!d"d#Zed$d%d&Zed'd(d)Zd*d+ Zd,d- Zd.d/ Zd0d1 Zed$d2d3Zd[eed4d5d6Zed7d8d9Z ed!d:d;Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dS )\Vmlz8
    A class for writing the Excel XLSX Vml file.


    Nc                 C   s   d}|    | | |rJ|   |D ]"}|d7 }| ||| |d7 }q&|r~|   |D ]"}|d7 }| ||| |d7 }qZ|r|   d}	|D ]"}
|d7 }| ||	|
 |	d7 }	q| d | 	  d S )Nr   xml)
_write_xml_namespace_write_shapelayout_write_button_shapetype_write_button_shape_write_comment_shapetype_write_comment_shape_write_image_shapetype_write_image_shape_xml_end_tagZ
_xml_close)r   data_idZvml_shape_idZcomments_dataZbuttons_dataZheader_imagesz_indexbuttoncommentindeximager   r   r   _assemble_xml_filew   s0    	




zVml._assemble_xml_filec                 C   s@   |dd \}}}}|d9 }|d9 }|d9 }|d9 }||||fS )N            ?r   )r   r   lefttopr
   r	   r   r   r   _pixels_to_points   s    zVml._pixels_to_pointsc                 C   sB   d}|d }|d }|d }d|fd|fd|fg}|  d| d S )	Nzurn:schemas-microsoft-com:Zvmlzoffice:officezoffice:excelzxmlns:vzxmlns:ozxmlns:xr"   )_xml_start_tag)r   ZschemaZxmlnsZxmlns_oZxmlns_x
attributesr   r   r   r#      s    zVml._write_xml_namespacec                 C   s*   dg}|  d| | | | d d S )Nv:exteditzo:shapelayout)r9   _write_idmapr+   r   r,   r:   r   r   r   r$      s    
zVml._write_shapelayoutc                 C   s   dd|fg}|  d| d S )Nr;   datazo:idmap_xml_empty_tagr?   r   r   r   r>      s    zVml._write_idmapc                 C   sZ   d}d}d}d}d|fd|fd|fd|fg}|  d	| |   | d
d | d	 d S )NZ_x0000_t20221600,21600   m,l,21600r21600,l21600,xeid	coordsizeo:sptpathv:shapetypetrect)r9   _write_stroke_write_comment_pathr+   r   shape_idrG   sptrI   r:   r   r   r   r'      s    zVml._write_comment_shapetypec                 C   s^   d}d}d}d}d|fd|fd|fd|fg}|  d	| |   |   |   | d	 d S )
NZ_x0000_t201rC      rE   rF   rG   rH   rI   rJ   )r9   rM   _write_button_path_write_shapetype_lockr+   rO   r   r   r   r%      s    zVml._write_button_shapetypec           	      C   s   d}d}d}d}d}d}d}d|fd|fd	|fd
|fd|fd|fd|fg}|  d| |   |   |   |   | d d S )NZ
_x0000_t75rC   K   rK   zm@4@5l@4@11@9@11@9@5xefrF   rG   rH   zo:preferrelativerI   filledstrokedrJ   )r9   rM   _write_formulas_write_image_path_write_aspect_ratio_lockr+   )	r   rP   rG   rQ   Zo_preferrelativerI   rW   rX   r:   r   r   r   r)     s*    
zVml._write_image_shapetypec                 C   s   d}d|fg}|  d| d S )NZmiter	joinstylezv:strokerA   )r   r\   r:   r   r   r   rM   7  s    
zVml._write_strokec                 C   s0   g }|r| d | d|f | d| d S )N)gradientshapeokrK   o:connecttypev:path)appendrB   )r   r]   connecttyper:   r   r   r   rN   ?  s
    
zVml._write_comment_pathc                 C   sF   d}d}d}d}d}d|fd|fd|fd|fd|fg}|  d| d S )	NrV   rL   shadowoko:extrusionokstrokeokfillokr^   r_   rA   )r   rb   extrusionokrd   re   ra   r:   r   r   r   rS   J  s    zVml._write_button_pathc                 C   s2   d}d}d}d|fd|fd|fg}|  d| d S )NrV   rK   rL   rc   r]   r^   r_   rA   )r   rf   r]   ra   r:   r   r   r   rZ   \  s    zVml._write_image_pathc                 C   s(   d}d}d|fd|fg}|  d| d S )Nr=   rK   r<   	shapetypeo:lockrA   )r   extrg   r:   r   r   r   rT   j  s    zVml._write_shapetype_lockc                 C   s(   d}d}d|fd|fg}|  d| d S )Nr=   rK   r<   rotationrh   rA   )r   ri   rj   r:   r   r   r   _write_rotation_lockv  s    zVml._write_rotation_lockc                 C   s(   d}d}d|fd|fg}|  d| d S )Nr=   rK   r<   aspectratiorh   rA   )r   ri   rl   r:   r   r   r   r[     s    zVml._write_aspect_ratio_lock)r/   c                 C   s   d}d}d}dt | }| |j\}}}	}
|jr6d}d|dd|dd	|	dd
|
dd| d| }d|fd|fd|fd|jfd|fg}| d| |   |   | d d | 	  | 
| | d d S )Nz#_x0000_t202autoZhidden_x0000_svisibleposition:absolute;margin-left:.15gpt;margin-top:	pt;width:
pt;height:pt;z-index:z;visibility:rF   typestyle	fillcoloro:insetmodev:shapenone)strr8   r   
is_visiblecolorr9   _write_comment_fill_write_shadowrN   _write_comment_textbox_write_comment_client_datar+   )r   rP   r-   r/   
shape_typeZ	insetmodeZ
visibilityr6   r7   r
   r	   rw   r:   r   r   r   r(     s,    .
zVml._write_comment_shape)r.   c                 C   s   d}dt | }| |j\}}}}d|dd|dd|dd|dd| d	}	d
|fd|fg}
|jd k	rz|
d|jf |
d|	f |
d |
d |
d |
d | d|
 |   |   | | | 	| | 
d d S )Nz#_x0000_t201rn   rp   rq   rr   rs   rt   ru   z;mso-wrap-style:tightrF   rv   Zaltrw   )zo:buttonrK   )rx   buttonFace [67])ZstrokecolorzwindowText [64])ry   rm   rz   )r|   r8   r   r   r`   r9   _write_button_fillrk   _write_button_textbox_write_button_client_datar+   )r   rP   r-   r.   r   r6   r7   r
   r	   rw   r:   r   r   r   r&     s*    *






zVml._write_button_shape)r1   c                 C   s   d}dt | }|j}|j}|j}|j}|j}	|j}
|j}|d | }|	d | }	dt|d d d  }dt|	d d d  }	d|d	d
|	d	d| }d|fd|fd|fd|fg}| 	d| | 
|
| |   | d d S )Nz#_x0000_t75rn   g      R@r5   g      X@H   g      ?z3position:absolute;margin-left:0;margin-top:0;width:rq   rt   ru   rF   zo:spidrv   rw   rz   )r|   Z
image_name_widthZ_x_dpiZ_y_dpi_heightZ_ref_idZ_header_positionr   r9   _write_imagedatark   r+   )r   rP   r-   r1   r   namer
   Zx_dpiZy_dpir	   ref_idpositionrw   r:   r   r   r   r*     s0    
zVml._write_image_shapec                 C   s   d}d|fg}|  d| d S )Nz#ffffe1color2v:fillrA   )r   color_2r:   r   r   r   r   %  s    
zVml._write_comment_fillc                 C   s(   d}d}d|fd|fg}|  d| d S )Nr   rK   r   zo:detectmouseclickr   rA   )r   r   Zdetectmouseclickr:   r   r   r   r   -  s    zVml._write_button_fillc                 C   s2   d}d}d}d|fd|fd|fg}|  d| d S )NrK   blackonr~   obscuredzv:shadowrA   )r   r   r~   r   r:   r   r   r   r   9  s    zVml._write_shadowc                 C   s2   d}d|fg}|  d| | d | d d S )Nmso-direction-alt:autorw   	v:textboxr6   )r9   
_write_divr+   )r   rw   r:   r   r   r   r   G  s
    

zVml._write_comment_textboxc                 C   s8   d}d|fdg}|  d| | d|j | d d S )Nr   rw   )zo:singleclickrV   r   center)r9   r   r   r+   )r   r.   rw   r:   r   r   r   r   T  s
    zVml._write_button_textbox)alignr   c                 C   s:   d| }d|fg}|  d| |r,| | | d d S )Nztext-align:rw   div)r9   _write_button_fontr+   )r   r   r   rw   r:   r   r   r   r   a  s    

zVml._write_div)r   c                 C   s4   d}d}d}d|fd|fd|fg}|  d|| d S )NZCalibri   z#000000facesizer~   Zfont_xml_data_element)r   r   r   r   r~   r:   r   r   r   r   o  s    zVml._write_button_fontc                 C   sr   d}d|fg}|  d| |   |   | |j |   | |j | |j	 |j
rd|   | d d S )NZNote
ObjectTypex:ClientData)r9   _write_move_with_cells_write_size_with_cells_write_anchorr   _write_auto_fill
_write_rowr   _write_columnr   r}   _write_visibler+   )r   r/   object_typer:   r   r   r   r   }  s    
zVml._write_comment_client_datac                 C   s`   d}d|fg}|  d| | |j |   |   | |j |   |   | 	d d S )NZButtonr   r   )
r9   r   r   _write_print_objectr   _write_fmla_macror   _write_text_halign_write_text_valignr+   )r   r.   r   r:   r   r   r   r     s    
zVml._write_button_client_datac                 C   s   |  d d S )Nzx:MoveWithCellsrA   r   r   r   r   r     s    zVml._write_move_with_cellsc                 C   s   |  d d S )Nzx:SizeWithCellsrA   r   r   r   r   r     s    zVml._write_size_with_cellsc                 C   s   |  d d S )Nz	x:VisiblerA   r   r   r   r   r     s    zVml._write_visiblec                 C   sX   |d d \}}}}}}}}	||||||||	g}
dd |
D }
d |
}| d| d S )Nr3   c                 S   s   g | ]}t |qS r   )r|   ).0ir   r   r   
<listcomp>  s     z%Vml._write_anchor.<locals>.<listcomp>z, zx:Anchor)joinr   )r   r   Z	col_startZ	row_startx1y1Zcol_endZrow_endZx2y2stringsr@   r   r   r   r     s
    
zVml._write_anchorc                 C   s   d}|  d| d S )NFalsez
x:AutoFillr   r   r@   r   r   r   r     s    zVml._write_auto_fillc                 C   s   |  d| d S )Nzx:Rowr   r   r   r   r   r     s    zVml._write_rowc                 C   s   |  d| d S )Nzx:Columnr   r   r   r   r   r     s    zVml._write_columnc                 C   s   |  dd d S )Nzx:PrintObjectr   r   r   r   r   r   r     s    zVml._write_print_objectc                 C   s   |  dd d S )Nzx:TextHAlignCenterr   r   r   r   r   r     s    zVml._write_text_halignc                 C   s   |  dd d S )Nzx:TextVAlignr   r   r   r   r   r   r     s    zVml._write_text_valignc                 C   s   |  d| d S )Nzx:FmlaMacror   r   r   r   r   r     s    zVml._write_fmla_macroc                 C   s(   ddt | fd|fg}| d| d S )Nzo:relidZrIdzo:titlezv:imagedata)r|   rB   )r   r   Zo_titler:   r   r   r   r     s    zVml._write_imagedatac                 C   s   |  d | d | d | d | d | d | d | d | d	 | d
 | d | d | d | d d S )Nz
v:formulaszif lineDrawn pixelLineWidth 0z
sum @0 1 0z
sum 0 0 @1zprod @2 1 2zprod @3 21600 pixelWidthzprod @3 21600 pixelHeightz
sum @0 0 1zprod @6 1 2zprod @7 21600 pixelWidthzsum @8 21600 0zprod @7 21600 pixelHeightzsum @10 21600 0)r9   _write_formular+   r   r   r   r   rY     s    












zVml._write_formulasc                 C   s   d|fg}|  d| d S )Neqnzv:frA   )r   r   r:   r   r   r   r     s    
zVml._write_formula)NNN)N)1r   r   r   r   r2   r8   r#   r$   r>   r'   r%   r)   rM   rN   rS   rZ   rT   rk   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   rY   r   r   r   r   r   r!   k   sZ      
4	$412 	r!   N)	Zxlsxwriter.commentsr   Zxlsxwriter.imager    r   r   Z	XMLwriterr!   r   r   r   r   <module>   s   U