mς
έEc           @   s  d  Z  d k l Z l Z d k Td k l Z l Z d k Z d f  d     YZ	 d f  d     YZ
 d	 e f d
     YZ d f  d     YZ e d j od k l Z l Z e   Z e e d d d d Z e i d e d d  e i   e i   e e i e i d d  e i d d  h  d d < e i d d d d  e e i e i d d  e i d d  h  d d < e i d d d d  e e i e i d d  e i d d  h  d d < e i d d d e	 d d  Z x-g  Z e d d  D] Z  e e  d q[ D]ύ Z! e i e! d e! d d d  e e i" e i e! d   e i e! d  h  d d! < e e i" e i d  e!  e i d e!  h  d d! < e i e! d e! d d d  e	 e e! d"  e e! d"   Z# e i d# d# e# d  e# d  e e# Z qWe i d# d# e d  e d  e i d! d d e e i e i d$ d$  e i d d   e i$ d% d& d  e i%   n d S('   sn   
todo:

scale constraints don't work yet

certain scale constraints should affect position, maybe vice versa

(   s   nested_scopess   division(   t   *(   s   logs   expNt   Pairc           B   s§   t  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   Z d   Z RS(   sX   ordered pair of numbers. element-wise add/mult/etc. access the numbers by index or .x .yc         C   s   | |  _  | |  _ d  S(   N(   t   at   selft   b(   R   R   R   (    (    t%   /home/fenn/3d/cadvas-0.2.2/zooming.pyt   __init__   s    	c         C   s%   t  |  d | d |  d | d  S(   Ni    i   (   R   R   t   other(   R   R   (    (    R   t   __add__   s    c         C   s%   t  |  d | d |  d | d  S(   Ni    i   (   R   R   R   (   R   R   (    (    R   t   __sub__   s    c         C   s%   t  |  d | d |  d | d  S(   Ni    i   (   R   R   R   (   R   R   (    (    R   t   __mul__   s    c         C   s%   t  |  d | d |  d | d  S(   Ni    i   (   R   R   R   (   R   R   (    (    R   t   __truediv__   s    c         C   s,   |  d c | d 7<|  d c | d 7<|  S(   Ni    i   (   R   R   (   R   R   (    (    R   t   __iadd__   s    c         C   s,   |  d c | d 8<|  d c | d 8<|  S(   Ni    i   (   R   R   (   R   R   (    (    R   t   __isub__   s    c         C   s,   |  d c | d 9<|  d c | d 9<|  S(   Ni    i   (   R   R   (   R   R   (    (    R   t   __imul__    s    c         C   s,   |  d c | d <|  d c | d <|  S(   Ni    i   (   R   R   (   R   R   (    (    R   t   __itruediv__$   s    c         C   s   t  |  d |  d  } | S(   Ni    i   (   R   R   t   r(   R   R   (    (    R   t   __neg__)   s    c         C   s6   | d j o |  d Sn | d j o |  d Sn d  S(	   Nt   xR   i    t   yR   i   (   R   R   (   R   R   (   t   attrR   (   R   R   (    (    R   t   __getattr__,   s      c         C   s   d  S(   N(   t   None(   R   R   (    (    R   t
   __coerce__1   s    c         C   s   d |  i |  i f S(   Ns   (%s,%s)(   R   R   R   (   R   (    (    R   t   __str__3   s    c         C   s   d t  |   S(   Ns   Pair%s(   t   strR   (   R   (    (    R   t   __repr__5   s    c         C   s   t  |  d |  d f  S(   Ni    i   (   t   iterR   (   R   (    (    R   t   __iter__7   s    c         C   s:   | d j o |  i Sn | d j o |  i Sn t  d  S(   Ni    i   (   t   iR   R   R   t
   IndexError(   R   R   (    (    R   t   __getitem__9   s
      c         C   s\   | d j o | |  _ n | d j o | |  _ n | d j  p | d j o
 t  n d  S(   Ni    i   (   R   t   valR   R   R   R   (   R   R   R    (    (    R   t   __setitem__=   s      (   t   __name__t
   __module__t   __doc__R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R!   (    (    (    R   R      s$    																t
   Constraintc           B   s#   t  Z d   Z d   Z d   Z RS(   Nc         C   sΏ   | d i   j o t d |   n | d j o t d |   n y t |  } Wn t j
 o n Xt | t  o! | d j o t d |   n | |  _ | |  _ | |  _ d S(   sW   
        for example:
         leftedge>0 (world coords)
         scl.x==scl.y
        s   left top right bottom sclx sclys   varname '%s' is unknownt   <t   >s   <=s   >=s   ==s   op '%s' is unknownt   sclxt   sclys   value '%s' is unknownN(   R&   R'   s   <=s   >=s   ==(   R(   R)   (	   t   varnamet   splitt
   ValueErrort   opt   floatt   valuet
   isinstanceR   t   var(   R   R*   R-   R/   (    (    R   R   D   s     		c         C   s   d |  i |  i |  i f S(   Ns   <Constraint %s %s %s>(   R   R1   R-   R/   (   R   (    (    R   R   Y   s    c         C   sm   |  i d j o | | j p: |  i d j o | | j  p |  i d j o | | j o | | | } n | S(   sρ  
        calc receives requested value 'v' and returns a new
        value. returning v itself means that the
        constraint had no effect-- the requested value will not
        violate the constraint.

        this function might decide to adjust v to
        meet the constraint though.  the available data is a
        transformed edge coodrinate and the actual edge
        coordinate. the coordinate system is unspecified, but all
        values will be in the same coord system.
        R'   R&   s   ==N(   R   R-   t   transformedt   edget   v(   R   R4   R3   R2   (    (    R   t   calc\   s     W(   R"   R#   R   R   R5   (    (    (    R   R%   C   s   		t   Zoomingc           B   s§   t  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   Z d   Z RS(   s2  canvas that supports zoom and pan. in this object, the 'world'
    coordinates are the unchanging ones. you convert to/from 'canvas'
    coordinates, which are the ones suitable for all canvas
    operations.

    maybe sometime i'll wrap all the canvas ops so you can work
    exclusively in world coords.c         O   sD   t  i |  | |  t d d  |  _ t d d  |  _ g  |  _ d  S(   Ni    i   (	   t   CanvasR   R   t   kt   kwR   t   offt   sclt   constraints(   R   R8   R9   (    (    R   R   z   s    c         G   sQ   |  i i t |    |  i   o* |  i d d  |  i d d d d  n d  S(   Ni    i   (   R   R<   t   appendR%   t   argst   winfo_ismappedt   movet   scale(   R   R>   (    (    R   t   addconstraint   s    c         C   sX   g  } xB |  i D]7 } | i | j o | i | j p | i |  q q W| |  _ d  S(   N(   t   keepR   R<   t   cR1   R*   R-   R=   (   R   R*   R-   RC   RD   (    (    R   t   delconstraint   s    
  c         C   sΣ  x|  i D]~} | i d j oK |  i | i d |  i |  d d d |  i | i	 | d  d   } n | i d j oQ |  i | i d |  i |  d |  i
   d |  i | i	 | d  d   } n | i d j oK |  i | i d |  i |  d d d |  i d | i	 |  d   } n | i d	 j oQ |  i | i d |  i |  d |  i   d |  i d | i	 |  d   } q
 q
 W|  i | |  \ } } t i |  d
 | |  |  i | | f 7_ d S(   sv   canvas move command, but always moves everything and
        updates the transformation.  dx,dy are world coordinates.t   leftR4   R3   i    R2   t   rightt   topi   t   bottomt   allN(   R   R<   RD   R1   t   c2w_dxR5   t   w2c_dxt   dxt   world2canvasR/   t   winfo_widtht   c2w_dyt   w2c_dyt   dyt   winfo_heightt   world2canvas_vectort   cdxt   cdyR7   R@   R:   (   R   RM   RR   RD   RU   RV   (    (    R   R@      s,     
 ***.c         C   s   |  i t | |  |  i   S(   sD   like move, but you give canvas units (pixels) instead of world unitsN(   R   R@   R   RM   RR   R;   (   R   RM   RR   (    (    R   t   move_can­   s     c   	      C   sH  | d j p | d j o d GHd Sn x |  i D] } | i d j o. | i | d | d | i |  i i	 } n | i d j o. | i | d | d | i |  i i
 } q1 q1 Wt | |  } t |  i | |    } |  i | 9_ t |  i | |    } |  i | | 7_ t i |  d | | | |  |  i d d  d S(	   sΈ   canvas scale command, but also updates the transformation. all objects are scaled.
        origin is in canvas coordinates (use world2canvas to convert from world coords if necessary).i    s3   Zooming.scale received scale factor of 0 - ignoringNR(   R3   R2   R)   RJ   (   t   xScalet   yScaleR   R<   RD   R1   R5   R/   R;   R   R   R   t   factort   canvas2worldt   xOrigint   yOrigint   worldorigin_prescalet   worldorigin_postscaleR:   R7   RA   R@   (	   R   R\   R]   RX   RY   RD   R_   R^   RZ   (    (    R   RA   ±   s"     
 .2c         C   s.   |  i | | | |  i i | |  i i  d S(   sR   sets scale factor absolutely, rather than multiplying to the existing scale factorN(	   R   RA   R\   R]   RX   R;   R   RY   R   (   R   R\   R]   RX   RY   (    (    R   t   setscaleΠ   s     c         G   s$   t  |   |  i |  i } t |  S(   sE   takes a world coordinate as a tuple and returns the canvas coordinateN(   R   t
   worldcoordR   R:   R;   R   t   tuple(   R   Ra   R   (    (    R   RN   Τ   s     c         G   s$   t  |   |  i |  i } t |  S(   sE   takes a canvas coordinate as a tuple and returns the world coordinateN(   R   t   canvascoordR   R;   R:   R   Rb   (   R   Rc   R   (    (    R   R[   Ω   s     c         G   s   t  |   |  i S(   s(   converts a canvas vector to world vectorN(   R   R4   R   R;   (   R   R4   (    (    R   t   canvas2world_vectorή   s     c         G   s   t  |   |  i S(   s(   converts a world vector to canvas vectorN(   R   R4   R   R;   (   R   R4   (    (    R   RT   α   s     c         C   s   |  i | d  d S(   Ni    (   R   Rd   RM   (   R   RM   (    (    R   RK   ε   s    c         C   s   |  i | d  d S(   Ni    (   R   RT   RM   (   R   RM   (    (    R   RL   ζ   s    c         C   s   |  i d |  d S(   Ni    i   (   R   Rd   RR   (   R   RR   (    (    R   RP   η   s    c         C   s   |  i d |  d S(   Ni    i   (   R   RT   RR   (   R   RR   (    (    R   RQ   θ   s    c            sQ   d    d    d   }   i d    d      i d    d    d S(	   s1   arranges for ctrl-LMB to pan the canvas like me10c         C   s   t  | i | i  |  _ d  S(   N(   R   t   evR   R   R   t	   lastmouse(   R   Re   (    (    R   t   pressμ   s    c         C   sF   |  i | i |  i i | i |  i i  t | i | i  |  _ d  S(   N(   R   RW   Re   R   Rf   R   R   (   R   Re   (    (    R   t   motionξ   s    *c         C   s   d  S(   N(    (   R   Re   (    (    R   t   releaseρ   s    s   <Control-ButtonPress-1>c            s      |   S(   N(   Rg   R   Re   (   Re   (   Rg   R   (    R   t   <lambda>σ   s    s   <Control-B1-Motion>c            s      |   S(   N(   Rh   R   Re   (   Re   (   Rh   R   (    R   Rj   τ   s    N(   Rg   Rh   Ri   R   t   bind(   R   Rg   Rh   Ri   (    (   R   Rg   Rh   R   t   panbindingsκ   s     			c            sQ   d    d    d   }   i d    d      i d    d    d S(	   s2   arranges for ctrl-RMB to zoom the canvas like me10c         C   s4   t  | i | i  |  _ t  | i | i  |  _ d  S(   N(   R   Re   R   R   R   t
   firstmouset	   prevmouse(   R   Re   (    (    R   Rg   ϋ   s    c         C   sh   |  i |  i i |  i i d d | i |  i i d d | i |  i i  t | i | i  |  _ d  S(   Ni   f0.02(   R   RA   Rm   R   R   Re   Rn   R   (   R   Re   (    (    R   Rh   ώ   s    c         C   s   d  S(   N(    (   R   Re   (    (    R   Ri     s    s   <Control-ButtonPress-3>c            s      |   S(   N(   Rg   R   Re   (   Re   (   Rg   R   (    R   Rj     s    s   <Control-B3-Motion>c            s      |   S(   N(   Rh   R   Re   (   Re   (   Rh   R   (    R   Rj     s    N(   Rg   Rh   Ri   R   Rk   (   R   Rg   Rh   Ri   (    (   R   Rg   Rh   R   t   zoombindingsψ   s     			(   R"   R#   R$   R   RB   RE   R@   RW   RA   R`   RN   R[   Rd   RT   RK   RL   RP   RQ   Rl   Ro   (    (    (    R   R6   q   s$    																t   outline_markerc           B   s   t  Z RS(   N(   R"   R#   (    (    (    R   Rp   
  s   t   __main__(   s   sins   cost   widthi  t   heightt   fillt   expandi   i   i  t   tagst   demoi<   f0.5i   i   i   i   i
   i    t   gridf0.10000000000000001i2   i   R(   s   ==(&   R$   t
   __future__t   nested_scopest   divisiont   Tkintert   matht   logt   expt   operatorR   R%   R7   R6   Rp   R"   t   sint   cost   Tkt   roott   zt   packt   BOTHRl   Ro   t   applyt   create_rectangleRN   RA   t   itemconfiguret   unscalet   _[1]t   rangeR   R   t   create_linet   scaRB   t   mainloop(   R   R   R   R~   R   R   R{   Rz   R%   R6   R   R   Rp   R$   R   R   R   R   R   (    (    R   t   ?   sH   	4.	

888/ 88#,
