ó
a#nSc           @   s  d  Z  d Z d Z e d e Z d d l m Z m Z m Z d d l Td Z	 e	 d Z
 d	 f  d
 „  ƒ  YZ d f  d „  ƒ  YZ d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d f  d „  ƒ  YZ d d „ Z d  f  d! „  ƒ  YZ  d" S(#   s1  
PIDDLE (Plug-In Drawing, Does Little Else)
2D Plug-In Drawing System

Magnus Lie Hetland
Andy Robinson
Joseph J. Strout
and others

February-March 1999

On coordinates: units are Big Points, approximately 1/72 inch.
The origin is at the top-left, and coordinates increase down (y)
and to the right (x).

s   1.0t   0t   .iÿÿÿÿ(   t
   StringTypet   IntTypet   InstanceType(   t   *iH   gR¸…ëQ@t
   StateSaverc           B   s    e  Z d  Z d „  Z d „  Z RS(   s:  This is a little utility class for saving and restoring the
	default drawing parameters of a canvas.  To use it, add a line
	like this before changing any of the parameters:
	
		saver = StateSaver(myCanvas)
	
	then, when "saver" goes out of scope, it will automagically
	restore the drawing parameters of myCanvas.c         C   s=   | |  _  | j |  _ | j |  _ | j |  _ | j |  _ d  S(   N(   t   canvast   defaultLineColort   defaultFillColort   defaultLineWidtht   defaultFont(   t   selfR   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   __init__y   s
    	c         C   s@   |  j  |  j _  |  j |  j _ |  j |  j _ |  j |  j _ d  S(   N(   R   R   R	   R
   R   (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   __del__€   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   o   s   	t   Fontc           B   sA   e  Z d  Z d d d d d d „ Z d „  Z d „  Z d „  Z RS(   s5   This class represents font typeface, size, and style.i   i    c         C   s?   |  j  } | | d <| | d <| | d <| | d <| | d <d  S(   Nt   boldt   italict	   underlinet   sizet   face(   t   __dict__(   R   R   R   R   R   R   t   d(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   Ž   s    	



c         C   sf   |  j  | j  k r^ |  j | j k r^ |  j | j k r^ |  j | j k r^ |  j | j k r^ d Sd Sd S(   s-   Compare two fonts to see if they're the same.i    i   N(   R   R   R   R   R   (   R   t   other(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   __cmp__œ   s
    $$c         C   s,   d |  j  |  j |  j |  j t |  j ƒ f S(   Ns   Font(%d,%d,%d,%d,%s)(   R   R   R   R   t   reprR   (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   __repr__¥   s    c         C   s   t  d ‚ d  S(   Ns$   piddle.Font has read-only attributes(   t	   TypeError(   R   t   namet   value(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   __setattr__©   s    N(   R   R   R   t   NoneR   R   R   R!   (    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   ‹   s
   			i   i   i   s   s   s   s   s   s   s   s   s   s   s   s   	t   Canvasc           B   sµ  e  Z d  Z d! d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d" d" d	 „ Z
 d
 „  Z d" d „ Z d" d „ Z d" d „ Z d" d „ Z d" d „ Z d d d „ Z d „  Z d" d" d d „ Z d" d" d" d „ Z d" d" d" d „ Z d" d" d d „ Z d" d" d" d d" d „ Z d" d" d" d" d „ Z d d d" d" d" d" d „ Z d" d" d" d" d „ Z d d d" d" d" d" d „ Z d" d" d" d d" d „ Z d" d" d" d d" d „ Z d" d" d  „ Z RS(#   s¯   This is the base class for a drawing canvas.  The 'plug-in renderers'
	we speak of are really just classes derived from this one, which implement
	the various drawing methods.i,  t   PIDDLEc         C   st   t  |  _ t |  _ d |  _ t ƒ  |  _ d „  } | |  _ d „  } | |  _ d „  } | |  _	 | | |  _
 |  _ d S(   sq   Initialize the canvas, and set default drawing parameters. 
		Derived classes should be sure to call this method.i   c         S   s   d  S(   N(    (   R   t   xt   y(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   ignoreClickÛ   s    c         S   s   d  S(   N(    (   R   R%   R&   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt
   ignoreOverß   s    c         S   s   d  S(   N(    (   R   t   keyt	   modifiers(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   ignoreKeyä   s    N(   t   blackR   t   transparentR	   R
   R   R   t   onClickt   onOvert   onKeyR   R   (   R   R   R   R'   R(   R+   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   Ï   s    									c         C   s   |  j  S(   N(   R   (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   getSizeë   s    c         C   s   d S(   sI   Returns 1 if onClick, onOver, and onKey events are possible, 0 otherwise.i    (    (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   isInteractiveð   s    c         C   s   d S(   s€   Returns 1 if the drawing can be meaningfully updated over time 		(e.g., screen graphics), 0 otherwise (e.g., drawing to a file).i    (    (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   canUpdateô   s    c         C   s   d S(   s2   Call this to clear and reset the graphics context.N(    (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   clearú   s    c         C   s   d S(   s‰   Call this to indicate that any comamnds that have been issued                 but which might be buffered should be flushed to the screenN(    (   R   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   flushþ   s    c         C   s   d S(   s,  For backends that can be save to a file or sent to a
                stream, create a valid file out of what's currently been
                drawn on the canvas.  Trigger any finalization here.
                Though some backends may allow further drawing after this call,
                presume that this is not possible for maximum portability

                file may be either a string or a file object with a write method
                     if left as the default, the canvas's current name will be used

                format may be used to specify the type of file format to use as
                     well as any corresponding extension to use for the filename
                     This is an optional argument and backends may ignore it if
                     they only produce one file format.N(    (   R   t   filet   format(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   save  s    c         C   s   d S(   sv   For interactive Canvases, displays the given string in the 		'info line' somewhere where the user can probably see it.N(    (   R   t   s(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   setInfoLine  s    c         C   s   |  j  | | ƒ |  j | ƒ f S(   N(   t   stringWidtht
   fontHeight(   R   R9   t   font(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   stringBox  s    c         C   s   t  d ‚ d S(   sf   Return the logical width of the string if it were drawn 		in the current font (defaults to self.font).R;   N(   t   NotImplementedError(   R   R9   R=   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR;     s    c         C   s   | s |  j  } n  d | j S(   sM   Find the height of one line of text (baseline to baseline) of the given font.g333333ó?(   R   R   (   R   R=   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR<   $  s     c         C   s   t  d ‚ d S(   s6   Find the ascent (height above base) of the given font.t
   fontAscentN(   R?   (   R   R=   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR@   +  s    c         C   s   t  d ‚ d S(   s7   Find the descent (extent below base) of the given font.t   fontDescentN(   R?   (   R   R=   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyRA   /  s    i    ih  c         C   s3  t  | | d ƒ } t  | | d ƒ } t | | ƒ | }	 t | | ƒ | }
 t t | | ƒ | d d d ƒ } | d k  r‡ d } n  d d l m } m } m } g  } t | ƒ | } | } xm t t	 | d ƒ ƒ D]U } |	 | | | d	 | ƒ |
 | | | d	 | ƒ f } | j
 | ƒ | | } qÖ W| S(
   s4   Return a list of points approximating the given arc.g       @g      $@i
   iÈ   i   iÿÿÿÿ(   t   sint   cost   pii   g     €f@(   t   abst   mint   maxt   mathRB   RC   RD   t   floatt   ranget   intt   append(   R   t   x1t   y1t   x2t   y2t   startAngt   extentt   xScalet   yScaleR%   R&   t   stepsRB   RC   RD   t	   pointlistt   stept   anglet   it   point(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   arcPoints5  s"    $ 	c	   %   	   C   s)  t  t t | | | | ƒ t  | | | | ƒ t | | | | ƒ t  | | | | ƒ ƒ d ƒ }	 d |	 }
 |
 |
 } | |
 } | } | } d } } } } | d | d | | } | d | d | | } d | d | d | } d | d | d | } d | d | } d | d | } | | } | | } | | } | | } | | | |
 } | | | |
 } d | } d | }  | d | }! |  d | }" | | f g }# xs t |	 ƒ D]e }$ | | | } | | | } | | |! } | | |" } | | } | |  } |# j | | f ƒ q¼W|# S(   s=   Return a list of points approximating the given Bezier curve.iÈ   g      ð?i    i   i   i   (   RF   RG   RJ   RL   (%   R   RM   RN   RO   RP   t   x3t   y3t   x4t   y4t   bezierStepst   dt1t   dt2t   dt3t   xxt   yyt   uxt   uyt   vxt   vyt   axt   ayt   bxt   byt   cxt   cyt   mx1t   my1t   lx1t   ly1t   kxt   kyt   mxt   myt   lxt   lyt	   pointListRY   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   curvePointsO  sF    +(	










c         K   sù   d d l  } d d l }	 |  j | ƒ }
 |
 | j | | j d ƒ } |
 | j | | j d ƒ } |	 j | d d ƒ } |	 j | d d ƒ } |	 j | d d ƒ } |	 j | d ƒ } x> | D]6 } |  j | | | | | | ƒ | | } | | } q» Wd S(   sL   Breaks string into lines (on 
, , 
, or 
), and calls drawString on each.iÿÿÿÿNg     €f@s   
s   
s   
s   (	   RH   t   stringR<   RC   RD   RB   t   replacet   splitt
   drawString(   R   R9   R%   R&   R=   t   colorRX   t   kwargsRH   R|   t   ht   dyt   dxt   linest   line(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   drawMultiLineString„  s    
c   	      K   s   t  d ‚ d S(   s-   Draw a straight line between x1,y1 and x2,y2.t   drawLineN(   R?   (	   R   RM   RN   RO   RP   R€   t   widtht   dashR�   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyRˆ   š  s    c   
      K   sF   x? | D]7 \ } } } }	 |  j  | | | |	 | | d | | �q Wd S(   sf   Draw a set of lines of uniform color and width.  		lineList: a list of (x1,y1,x2,y2) line coordinates.RŠ   N(   Rˆ   (
   R   t   lineListR€   R‰   RŠ   R�   RM   RN   RO   RP   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   drawLinesŸ  s    c         K   s   t  d ‚ d S(   s'   Draw a string starting at location x,y.R   N(   R?   (   R   R9   R%   R&   R=   R€   RX   R�   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   «  s    c         K   sV   |  j  | | | | | | | | ƒ } |  j | d |	 d |
 d | d | d | | �d S(   s7   Draw a Bezier curve with control points x1,y1 to x4,y4.t	   edgeColort	   edgeWidtht	   fillColort   closedRŠ   N(   R{   t   drawPolygon(   R   RM   RN   RO   RP   R\   R]   R^   R_   R�   RŽ   R�   R�   RŠ   R�   RV   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   drawCurve·  s    $c	      
   K   sS   | | f | | f | | f | | f g }
 |  j  |
 | | | d d d | |	 �d S(   sQ   Draw the rectangle between x1,y1, and x2,y2. 		These should have x1<x2 and y1<y2.R�   i   RŠ   N(   R‘   (   R   RM   RN   RO   RP   R�   RŽ   R�   RŠ   R�   Rz   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   drawRectÄ  s    *i   c         K   si  t  | | ƒ t | | ƒ } } t  | | ƒ t | | ƒ } } | d } | d } t | | | | | | d d f t | | | | | | f t | | | | | | d d f t | | | | | | f t | | | | | | d d f t | | | | | | f t | | | | | | d d f t | | | | | | f g } |  j | | | |	 d d d |
 | �d	 S(
   s§   Draw a rounded rectangle between x1,y1, and x2,y2, 		with corners inset as ellipses with x radius rx and y radius ry. 		These should have x1<x2, y1<y2, rx>0, and ry>0.i   i´   i¦ÿÿÿiZ   i    R�   i   RŠ   N(   RF   RG   t	   figureArct
   figureLinet
   drawFigure(   R   RM   RN   RO   RP   t   rxt   ryR�   RŽ   R�   RŠ   R�   R„   Rƒ   t   partList(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   drawRoundRectÌ  s    

     c	      
   K   sG   |  j  | | | | d d ƒ }
 |  j |
 | | | d d d | |	 �d S(   sk   Draw an orthogonal ellipse inscribed within the rectangle x1,y1,x2,y2. 		These should have x1<x2 and y1<y2.i    ih  R�   i   RŠ   N(   R[   R‘   (   R   RM   RN   RO   RP   R�   RŽ   R�   RŠ   R�   RV   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   drawEllipseç  s    c         K   s…   | | d | | d f } |  j  | | | | | | ƒ } |  j | | g | d g t d |	 ƒ |  j | | | t d |
 | �d S(   sí   Draw a partial ellipse inscribed within the rectangle x1,y1,x2,y2, 		starting at startAng degrees and covering extent degrees.   Angles 		start with 0 to the right (+x) and increase counter-clockwise. 		These should have x1<x2 and y1<y2.i   i    RŠ   N(   R[   R‘   R-   (   R   RM   RN   RO   RP   RQ   RR   R�   RŽ   R�   RŠ   R�   t   centerRV   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   drawArcð  s    c         K   s   t  d ‚ d S(   s¯   drawPolygon(pointlist) -- draws a polygon
		pointlist: a list of (x,y) tuples defining vertices
		closed: if 1, adds an extra segment connecting the last point to the first
		R‘   N(   R?   (   R   RV   R�   RŽ   R�   R�   RŠ   R�   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR‘     s    c         K   sá   g  } xÔ | D]Ì }	 |	 d }
 t  |	 d ƒ } |
 t k rW | j | d  | d g ƒ n] |
 t k r | j t |  j | ƒ ƒ n5 |
 t k r§ | j t |  j | ƒ ƒ n t d |
 ‚ |  j	 | | | | d | d | | �q Wd S(   só   drawFigure(partList) -- draws a complex figure
		partlist: a set of lines, curves, and arcs defined by a tuple whose
				  first element is one of figureLine, figureArc, figureCurve
				  and whose remaining 4, 6, or 8 elements are parameters.i    i   i   s   unknown figure operator: R�   RŠ   N(
   t   listR•   t   extendR”   t   applyR[   t   figureCurveR{   R   R‘   (   R   R™   R�   RŽ   R�   R�   RŠ   R�   Rz   t   tuplet   opt   args(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR–     s    
c         K   s   t  d ‚ d S(   st   Draw a PIL Image into the specified rectangle.  If x2 and y2 are
		omitted, they are calculated from the image size.t	   drawImageN(   R?   (   R   t   imageRM   RN   RO   RP   R�   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR¥   *  s    (   i,  i,  N(   R   R   R   R   R1   R2   R3   R4   R5   R"   R8   R:   R>   R;   R<   R@   RA   R[   R{   R‡   Rˆ   RŒ   R   R’   R“   Rš   R›   R�   R‘   R–   R¥   (    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR#   Ê   sH   							5	t   wbc         C   sX   |  rK t  |  t ƒ r' t |  | ƒ } qT t |  d ƒ r? |  } qT t d ‚ n	 t d ‚ | S(   sŒ   Common code for every Canvas.save() operation takes a string
        or a potential file object and assures that a valid fileobj is returnedt   writes   Invalid file argument to save(   t
   isinstanceR   t   opent   hasattrt	   ValuErrort
   ValueError(   R6   t	   openFlagst   fileobj(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   getFileObject5  s    		t   AffineMatrixc           B   s/   e  Z d d  „ Z d „  Z d „  Z d „  Z RS(   c         C   sm   | rN t  | ƒ d k r$ | |  _ n  t | ƒ t |  ƒ k ri | j |  _ qi n d d d d d d g |  _ d  S(   Ni   g      ð?i    g        (   t   lent   At   type(   R   t   init(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR   L  s    c         C   sY   | |  j  d | |  j  d | |  j  d | |  j  d |  j  d |  j  d g |  _  d  S(   Ni    i   i   i   i   i   (   R³   (   R   t   sxt   sy(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   scaleU  s    c         C   sÅ   t  j t | d ƒ } t  j t | d ƒ } |  j d | |  j d | |  j d | |  j d | |  j d | |  j d | |  j d | |  j d | |  j d |  j d g |  _ d S(	   sC   counter clockwise rotation in standard SVG/libart coordinate systemg     €f@i    i   i   i   i   i   N(   RH   RC   t   PIRB   R³   (   R   t   thetat   cot   si(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   rotateX  s    
c         C   s…   |  j  d |  j  d |  j  d |  j  d |  j  d | |  j  d | |  j  d |  j  d | |  j  d | |  j  d g |  _  d  S(   Ni    i   i   i   i   i   (   R³   (   R   t   txt   ty(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt	   translateh  s    ((N(   R   R   R"   R   R¸   R½   RÀ   (    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyR±   G  s   			N(!   R   t   __version_maj_number__t   __version_min_number__t   __version__t   typesR   R   R   t   rdkit.sping.colorst   incht   cmR   R   R•   R”   R¡   t   keyBkspt   keyDelt   keyLeftt   keyRightt   keyUpt   keyDownt   keyPgUpt   keyPgDnt   keyHomet   keyEndt   keyCleart   keyTabt   modShiftt
   modControlR#   R°   R±   (    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/sping/pid.pyt   <module>`   s<   

%ÿ l