U
    '1e{                     @   s  d Z dZddlmZ ddlT ddlT 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ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZd+d, Ze d-kre  d.S )/z3.3.0a  This file is a collection of widgets to produce some common signs and symbols.

Widgets include:

- ETriangle (an equilateral triangle),
- RTriangle (a right angled triangle),
- Octagon,
- Crossbox,
- Tickbox,
- SmileyFace,
- StopSign,
- NoEntry,
- NotAllowed (the red roundel from 'no smoking' signs),
- NoSmoking,
- DangerSign (a black exclamation point in a yellow triangle),
- YesNo (returns a tickbox or a crossbox depending on a testvalue),
- FloppyDisk,
- ArrowOne, and
- ArrowTwo
- CrossHair
    )colors)*)isStr	asUnicode)shapes)Widget)	renderPDFc                
   @   sl   e Zd ZdZdZeeeddeeddeeddeeddeeeeeeeedZ	dd	 Z
d
d ZdS )_SymbolzcAbstract base widget
    possible attributes:
    'x', 'y', 'size', 'fillColor', 'strokeColor'
       zsymbol x coordinatedesczsymbol y coordinatezsymbol x coordinate adjustment)xydxdysize	fillColorstrokeColorstrokeWidthc                 C   sJ   | j jdkstdd | _ | _ | _| _d| _tj	| _
d | _d| _d S )Nr	   z#Abstract class _Symbol instantiatedr   d   皙?)	__class____name__AssertionErrorr   r   r   r   r   r   redr   r   r   self r   N/tmp/pip-unpacked-wheel-109iniqw/reportlab/graphics/widgets/signsandsymbols.py__init__8   s    z_Symbol.__init__c              
   C   sr   t dd}t| j}|  }d|_d|_|  || |t j	|j|d  |jd |jj
tjddd	 |S )
N   r   2   r         middle
   r   
textAnchorfontSize)r   Drawingfloatr   r   r   r   drawaddStringr   r   black)r   Dsobr   r   r   demo@   s    

  z_Symbol.demoN)r   
__module____qualname____doc__Z_nodocAttrMapAttrMapValueisNumberisColorOrNone_attrMapr   r2   r   r   r   r   r	   (   s   




r	   c                   @   s    e Zd ZdZdd Zdd ZdS )	ETriangle#This draws an equilateral triangle.c                 C   s   t |  d S N)r	   r   r   r   r   r   r   P   s    zETriangle.__init__c                 C   sj   t | j}t }|d }tj| j| j| j| | j| j|d  | j| g| j| j|d d}|	| |S )N      ?r"         I@pointsr   r   r   
r*   r   r   GroupPolygonr   r   r   r   r,   r   r0   gaeZtriangler   r   r   r+   S   s"    
   
zETriangle.drawNr   r3   r4   r5   r   r+   r   r   r   r   r;   M   s   r;   c                   @   s    e Zd ZdZdd Zdd ZdS )	RTrianglezThis draws a right-angled triangle.

        possible attributes:
        'x', 'y', 'size', 'fillColor', 'strokeColor'

        c                 C   s$   d| _ d| _d| _tj| _d | _d S Nr   r   )r   r   r   r   greenr   r   r   r   r   r   r   l   s
    zRTriangle.__init__c                 C   sb   t | j}t }|d }tj| j| j| j| | j| j| j| g| j| j|d d}|	| |S )Nr>   r?   r@   rB   rE   r   r   r   r+   s   s"    
   
zRTriangle.drawNrH   r   r   r   r   rI   d   s   rI   c                   @   s    e Zd ZdZdd Zdd ZdS )OctagonzvThis widget draws an Octagon.

        possible attributes:
        'x', 'y', 'size', 'fillColor', 'strokeColor'

    c                 C   s$   d| _ d| _d| _tj| _d | _d S rJ   )r   r   r   r   yellowr   r   r   r   r   r   r      s
    zOctagon.__init__c                 C   s   t | j}t }|d }tj| j| | j| j| j| | j| j|d  | j| | j| | j|d  | j| | j| | j|d  | j| | j| | j|d  | jg| j| jdd}|	| |S )N   r"   r%   rA   r   r   r   )
r*   r   r   rC   rD   r   r   r   r   r,   )r   r0   rF   athirdZoctagonr   r   r   r+      s2    
       
zOctagon.drawNrH   r   r   r   r   rL      s   rL   c                   @   s6   e Zd ZdZeeeeeedZ	dd Z
dd ZdS )CrossboxzThis draws a black box with a red cross in it - a 'checkbox'.

        possible attributes:
        'x', 'y', 'size', 'crossColor', 'strokeColor', 'crosswidth'

    )BASE
crossColor
crosswidthc                 C   s4   d| _ d| _d| _tj| _tj| _tj| _	d| _
d S Nr   r   r%   )r   r   r   r   whiter   r   rS   r.   r   rT   r   r   r   r   r      s    zCrossbox.__init__c              	   C   s   t | j}t }tj| jd | jd |d |d | j| jdd}|	| tj
| j|d  | j|d  | j|d  | j|d  | j| j| jd}|	| tj
| j|d  | j|d  | j|d  | j|d  | j| j| jd}|	| |S )Nr
   r"   r   r   r   333333?333333?)r*   r   r   rC   Rectr   r   r   r   r,   LinerS   rT   )r   r0   rF   boxZ
crossLine1Z
crossLine2r   r   r   r+      s*    
 
4
4
zCrossbox.drawNr   r3   r4   r5   r6   r	   r7   r9   r8   r:   r   r+   r   r   r   r   rQ      s   	rQ   c                   @   s6   e Zd ZdZeeeeeedZ	dd Z
dd ZdS )TickboxzThis draws a black box with a red tick in it - another 'checkbox'.

        possible attributes:
        'x', 'y', 'size', 'tickColor', 'strokeColor', 'tickwidth'

)rR   	tickColor	tickwidthc                 C   s4   d| _ d| _d| _tj| _tj| _tj| _	d| _
d S rU   )r   r   r   r   r   r_   r.   r   rV   r   r`   r   r   r   r   r      s    zTickbox.__init__c                 C   s   t | j}t }tj| jd | jd |d |d | j| jdd}|	| tj
| j|d  | j|d  | j|d  | j|d  | j|d  | j|d  | j|d  | j|d  g| j| j| jd}|	| |S )Nr
   r"   rW   rX   ffffff?rY   r@   )r*   r   r   rC   rZ   r   r   r   r   r,   PolyLiner_   r`   )r   r0   rF   r\   ZtickLiner   r   r   r+      s(    
 
4   
zTickbox.drawNr]   r   r   r   r   r^      s   	r^   c                   @   s    e Zd ZdZdd Zdd ZdS )
SmileyFacezkThis draws a classic smiley face.

        possible attributes:
        'x', 'y', 'size', 'fillColor'

    c                 C   s0   t |  d| _d| _d| _tj| _tj| _	d S rJ   )
r	   r   r   r   r   r   rM   r   r.   r   r   r   r   r   r     s    
zSmileyFace.__init__c                 C   s  t | j}t }|tj| j|d  | j|d  |d | j| j	t
|d | jd dD ]V}|tj| j|d |  | j|d d  |d |d | j	| j	t
|d | jd qZ| j|d  }| j|d  }|d }|}|}d	}	d
}
d}g }|j}ddlm}m}m} |d }|| }|	| }|
| }||k rB|d|  }q(|}||k r||||  }||||  }|| || || }qFtj|| j	| j	t
|d | jd}|| |S )Nr"   g      C@Zcxcyrr   r   r   )r
   r"   rN      r%   rW   r    iT  r
   r   sincospi     f@)r*   r   r   rC   r,   Circler   r   r   r   maxr   ZEllipseappendmathri   rj   rk   rb   )r   r0   rF   icenterxcenteryradiusyradiusxradiusstartangledegreesendangledegreesdegreedelta
pointslistari   rj   rk   degreestoradiansradiansdelta
startangleendangleangler   r   Zsmiler   r   r   r+     sX    
& 4 


 
zSmileyFace.drawNrH   r   r   r   r   rc     s   rc   c                   @   s4   e Zd ZdZeeeedddZdd Z	dd Z
d	S )
StopSignzbThis draws a (British) stop sign.

        possible attributes:
        'x', 'y', 'size'

        zcolor of the word stopr   )rR   	stopColorc                 C   s.   d| _ d| _d| _tj| _tj| _tj| _	d S rJ   )
r   r   r   r   r.   r   	orangeredr   
ghostwhiter   r   r   r   r   r   R  s    zStopSign.__init__c                 C   s  t | j}t }|d }tj| j| | j| j| j| | j| j|d  | j| | j| | j|d  | j| | j| | j|d  | j| | j| | j|d  | jg| jd dd}|| tj| j| |d  | j|d  | j|d  | j| |d  | j|d  | j|d  |d  | j| |d  | j| |d  | j|d  |d  | j| |d  | j| |d  | j|d  |d  | j| |d  | j| |d  | j|d  |d  | j|d  gd | j	dd}|| | j
r|tj| j|d  | j|d  d	| j
d
|d dd |S )NrN   r"   r
   rO   K   r         ?皙?STOPr$   zHelvetica-Bold)r   r'   r(   ZfontName)r*   r   r   rC   rD   r   r   r   r,   r   r   r-   )r   r0   rF   rP   ZouterOctagonZinnerOctagonr   r   r   r+   Z  sl    
       
        
    zStopSign.drawNr   r3   r4   r5   r6   r	   r7   r9   r:   r   r+   r   r   r   r   r   G  s   
r   c                   @   s4   e Zd ZdZeeeedddZdd Z	dd Z
d	S )
NoEntryzThis draws a (British) No Entry sign - a red circle with a white line on it.

        possible attributes:
        'x', 'y', 'size'

        zcolor of the inner barr   )rR   innerBarColorc                 C   s.   d| _ d| _d| _tj| _tj| _tj| _	d S rJ   )
r   r   r   r   r.   r   r   r   r   r   r   r   r   r   r     s    zNoEntry.__init__c                 C   s   t | j}t }| jrN|tj| j|d  | j|d  |d d | jdd | j	r|tj| j|d  | j|d  |d |d  | j	d dd | j
}|r|tj| j|d  | j|d  |d |d	 ||ddd
 |S )Nr"   r
   rd   r!   r   r   r   皙?皙?)widthheightr   r   ZstrokeLineCapr   )r*   r   r   rC   r   r,   rm   r   r   r   r   rZ   )r   r0   rF   r   r   r   r   r+     s    
6><zNoEntry.drawNr   r   r   r   r   r     s   
r   c                   @   s*   e Zd ZdZeedZdd Zdd ZdS )
NotAllowedzThis draws a 'forbidden' roundel (as used in the no-smoking sign).

        possible attributes:
        'x', 'y', 'size'

        )rR   c                 C   s&   d| _ d| _d| _tj| _tj| _d S rJ   )r   r   r   r   r   r   rV   r   r   r   r   r   r     s
    zNotAllowed.__init__c                 C   sf  t | j}t }| j}tj| j|d  | j|d  |d |d  | j||d d}|	| | j| }| j|d  |d  }||d  }|d }|d }	d}
d}d}g }|j
}d	d
lm}m}m} |d }|| }|
| }|| }||k r|d|  }q|}||k rB||||  }||||  }|| || || }qtj||||d d}|	| |S )Nr"   r%   g      $@rd      r   iZ   r   rh   rl   rW   )r*   r   r   rC   r   rm   r   r   r   r,   ro   rp   ri   rj   rk   rb   )r   r0   rF   r   ZouterCirclerr   rs   rt   ru   rv   rw   rx   ry   rz   r{   ri   rj   rk   r|   r}   r~   r   r   r   r   Zcrossbarr   r   r   r+     s@    
<


 

zNotAllowed.drawN)	r   r3   r4   r5   r6   r	   r:   r   r+   r   r   r   r   r     s   
r   c                   @   s    e Zd ZdZdd Zdd ZdS )	NoSmokingz^This draws a no-smoking sign.

        possible attributes:
        'x', 'y', 'size'

        c                 C   s   t |  d S r=   )r   r   r   r   r   r   r     s    zNoSmoking.__init__c           	   	   C   s6  t | j}t| }| j|d  |d  }| j|d  |d  }tj|||d |d tj	tj
dd}||d  |d  }|d| tj|||d	 |d tjd dd}||d
  }|d| tj|||d	 |d tjd dd}||d
  }|d| tj|||d	 |d tjd dd}||d
  }|d| |S )Nr"   g      @       r   r   r   r   r   r   r   r   @   P   #   )r*   r   r   r+   r   r   r   rZ   r   r   Zgrayinsertr   )	r   r0   rF   ZnewxZnewyZcigarrette1Zcigarrette2Zcigarrette3Zcigarrette4r   r   r   r+     sB    

        zNoSmoking.drawNrH   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )
DangerSignzThis draws a 'danger' sign: a yellow box with a black exclamation point.

        possible attributes:
        'x', 'y', 'size', 'strokeColor', 'fillColor', 'strokeWidth'

        c                 C   s2   d| _ d| _d| _tj| _tj| _| jd | _d S )Nr   r   r>   )	r   r   r   r   r.   r   Zgoldr   r   r   r   r   r   r     s    zDangerSign.__init__c           	      C   s&  t | j}t }| j}|d }| j}|d }tj| j| j| j| | j| j|d  | j| gd | jdd}|	| tj| j|d  | j|d  | j| |d  | j|d  | j|d  | j| |d  g| j
d dd}|	| tj| j|d  |d  | j|d  | j|d  |d  | j|d  | j|d  |d  |d  | j|d	  | j|d  |d  |d  | j|d	  g| jd d
}|	| tj| j|d  |d  | j| | j|d  |d  | j| | j|d  |d  | j|d  | j|d  |d  | j|d  g| jd d
}|	| |S )Nr>   r"   r   r@   r!   r   g      @r   g      @)rA   r   r   )r*   r   r   rC   r   rD   r   r   r   r,   r   )	r   r0   rF   ewrG   ZouterTriangleZinnerTriangleZexmarkZexdotr   r   r   r+     sz    
   
   
    
    
zDangerSign.drawNrH   r   r   r   r   r     s   r   c                   @   sD   e Zd ZdZeeeeeeeedZ	dd Z
dd Zdd Zd	S )
YesNoaI  This widget draw a tickbox or crossbox depending on 'testValue'.

        If this widget is supplied with a 'True' or 1 as a value for
        testValue, it will use the tickbox widget. Otherwise, it will
        produce a crossbox.

        possible attributes:
        'x', 'y', 'size', 'tickcolor', 'crosscolor', 'testValue'

)rR   	tickcolor
crosscolor	testValuec                 C   s,   d| _ d| _d| _tj| _tj| _d| _d S )Nr   r   r
   )	r   r   r   r   rK   r   r   r   r   r   r   r   r   r   a  s    zYesNo.__init__c                 C   sH   | j rt }| j|_nt }| j|_| j|_| j|_| j	|_	|
  |S r=   )r   r^   r   r_   rQ   r   rS   r   r   r   r+   )r   ynr   r   r   r+   i  s    
z
YesNo.drawc              
   C   s  t dd}t }d|_d|_d|_d|_|  || t }d|_d|_d|_d|_|  || d	}|t j	|j|jd
  |jd|  dt
jd|d |t j	|j|jd
  |jd|  dt
jd|d d}|t j	|jd |jd | jjt
jd|d |S )Nr    r         F   r   x   r
      r"   333333?ztestValue=0r$   r&   ztestValue=1r%   U      )r   r)   r   r   r   r   r   r+   r,   r-   r   r.   r   r   )r   r/   r   Zyn2labelFontSizer   r   r   r2   w  sH    

"  "    z
YesNo.demoN)r   r3   r4   r5   r6   r	   r7   isColorZ	isBooleanr:   r   r+   r2   r   r   r   r   r   O  s   r   c                   @   s0   e Zd ZdZeeeedZdd Z	dd Z
dS )
FloppyDiskzyThis widget draws an icon of a floppy disk.

        possible attributes:
        'x', 'y', 'size', 'diskcolor'

        )rR   	diskColorc                 C   s   d| _ d| _d| _tj| _d S rJ   )r   r   r   r   r.   r   r   r   r   r   r     s    zFloppyDisk.__init__c              	   C   s8  t | j}t }tj| j| j|d  |||d  | jd dd}|| tj| j|d  | j| |d  |d |d t	j
d dd}|| tj| j|d  | j| |d  |d |d t	jd dd}|| tj| j|d	  | jd
|  | j|d  | jd
|  t	jt	jdd}|| tj| j|d	  | jd|  | j|d  | jd|  t	jt	jdd}|| tj| j|d	  | jd|  | j|d  | jd|  t	jt	jdd}|| tj| j|d  | j|d |d t	jd dd}	||	 tj| j|d  | j|d  |d |d | jd dd}
||
 |S )Nr   r   r   r   r   r   gQ?g{Gz?rX   g333333?rY   )x1y1Zx2y2r   r   r   gffffff?r   ra   gQ?gQ?gQ?)r*   r   r   rC   rZ   r   r   r   r,   r   Z
whitesmokeZ	royalbluer[   r.   Zsilver)r   r0   rF   ZdiskBodylabelZlabelsplashZline1Zline2Zline3Z
metalcoverZ	coverslotr   r   r   r+     sf    
 
,
,
4
4
4
 
(
zFloppyDisk.drawN)r   r3   r4   r5   r6   r	   r7   r   r:   r   r+   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )ArrowOnezuThis widget draws an arrow (style one).

        possible attributes:
        'x', 'y', 'size', 'fillColor'

        c                 C   s*   d| _ d| _d| _tj| _d| _d | _d S rJ   )r   r   r   r   r   r   r   r   r   r   r   r   r     s    zArrowOne.__init__c                 C   s   t | j}t }| j}| j}|d }|d }|d }|tj||| ||d|  || |d|  || |d|  || || || || || || g| j| j	| j
d |S )Nr"   rN         r@   r*   r   r   rC   r   r   r,   rD   r   r   r   )r   r0   rF   r   r   s2s3s5r   r   r   r+     s8    
  
 
 
   	zArrowOne.drawNrH   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdd Zdd ZdS )ArrowTwozuThis widget draws an arrow (style two).

        possible attributes:
        'x', 'y', 'size', 'fillColor'

        c                 C   s*   d| _ d| _d| _tj| _d| _d | _d S rJ   )r   r   r   r   Zbluer   r   r   r   r   r   r   r     s    zArrowTwo.__init__c           	      C   s   t | j}t }| j}| j}|d }|d }|d }|d }|tj||d|  ||d|  |d|  |d|  |d|  |d|  || || |d|  || |d|  |d|  g| j| j	| j
d |S )	Nr"   rN   r            g     2@r@   r   )	r   r0   rF   r   r   r   r   r   Zs24r   r   r   r+     s:    
 
 

 

 
 
 
 
	zArrowTwo.drawNrH   r   r   r   r   r   	  s   r   c                   @   s<   e Zd ZdZeeeeee	fdddZ
dd Zdd Zd	S )
	CrossHairr<   z( gap at centre as "x%" or points or Noner   )rR   innerGapc                 C   s<   d | _  | _ | _| _d| _d | _tj| _d| _	d| _
d S )Nr   r%   r   z20%)r   r   r   r   r   r   r   r.   r   r   r   r   r   r   r   r   =  s    zCrossHair.__init__c                 C   sJ  t | j}t }| j}| j| j }| j| j }d| j }|sh|| ||| |f||| ||| fg}nt	|rt
|}|dr|t |d d  d }qt |d }n|d }|| ||| |f|| ||| |f||| ||| f||| ||| fg}tj| j| jd}	|D ]&\}
}}}|	|
| |	|| q||	 |S )Nr   %r   g      Y@)r   r   )r*   r   r   rC   r   r   r   r   r   r   r   endswithPathr   r   ZmoveToZlineTor,   )r   r0   rF   Zigr   r   ZhsizeLZgsPZx0Zy0r   r   r   r   r   r+   E  s*    

*
L
zCrossHair.drawN)r   r3   r4   r5   r6   r	   r7   ZEitherOrZisStringZisNumberOrNoner:   r   r+   r   r   r   r   r   7  s   r   c               
   C   sD  d} t dd}t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d
|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d|_d|_|| |jj	d }|t j|j|jd  |jd|   |t
jd| d	 |t jdddt
jd| d d	 t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d
|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }	d|	_d|	_||	 |t j|	j|	jd  |	jd|   |	jj	t
jd| d	 t }
d
|
_d|
_||
 |t j|
j|
jd  |
jd|   |
jj	t
jd| d	 t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d
|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t }d|_d|_|| |t j|j|jd  |jd|   |jj	t
jd| d	 t|dd td dS )z\This function produces a pdf with examples of all the signs and symbols from this file.
    r%   i  i  r   i  r"   r   r$   r&      i@  r      r   zT(The 'YesNo' widget returns a tickbox if testvalue=1, and a crossbox if testvalue=0)g      ?i  i     zsignsandsymbols.pdfzsignsandsymbols.pyzwrote file: signsandsymbols.pdfN)r   r)   rQ   r   r   r,   r-   r   r   r   r   r.   r^   r   r   r   rc   r   r   r   r   r   r   r   Z
drawToFileprint)r   r/   cbtbr   Z
tempstringssneZsfZdsnansZa1Za2fdr   r   r   testb  s   
"  
"  
"    
"  
"  
"  
"  
"  
"  
"  
"  
"  r   __main__N)!__version__r5   Zreportlab.libr   Zreportlab.lib.validatorsZreportlab.lib.attrmapZreportlab.lib.utilsr   r   Zreportlab.graphicsr   Zreportlab.graphics.widgetbaser   r   r	   r;   rI   rL   rQ   r^   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s8   % %1+B=%8*DEL).+n
