
[Pc           @   s,  d  d l  Z  d  d l Z d  d l Z d Z d e 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 Z d Z d Z d  Z d d  Z d   Z d   Z d e f d     YZ d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d S(!   iNs$   High-level scripting aids for Golly.t   rectc           B   s#   e  Z d  Z d   Z g  d  Z RS(   s:   A simple class to make it easier to manipulate rectangles.c         C   s%   t  j |  j |  j |  j |  j g  S(   s6   Return true if rect is completely visible in viewport.(   t   gollyt   visrectt   xt   yt   wdt   ht(   t   self(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   visible   s    c         C   s  t  |  d k r t |  _ n t  |  d k r t |  _ | d |  _ |  _ | d |  _ |  _ | d |  _ |  _	 | d |  _
 |  _ |  j d k r t d   n  |  j
 d k r t d   n  |  j |  j d |  _ |  j |  j
 d |  _ n t d   t j |  |  d  S(	   Ni    i   i   i   i   s   rect width must be > 0s   rect height must be > 0s"   rect arg must be [] or [x,y,wd,ht](   t   lent   Truet   emptyt   FalseR   t   leftR   t   topR   t   widthR   t   heightt
   ValueErrort   rightt   bottomt	   TypeErrort   listt   __init__(   R   t   R(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyR      s     	  (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyR       s   	i    i   t   Drawt   Pickt   Selectt   Moves   Zoom Ins   Zoom Outs   B3/S23c         C   s   t  j |   d S(   s    Set the rule for the Game of Life.
 Although it affects subsequent calls to pattern.evolve(),
 only the last call to this function matters for the viewer.N(   R   t   setrule(   t   s(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   ruleQ   s    c         C   s'   x  |  j  d  D] } d G| GHq Wd S(   s2   Supply a textual description to the whole pattern.s   
s   #DN(   t   split(   R    t   line(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   descriptionZ   s    c      	   C   s   |  d } |  d } |  d } | d } | d } | d } | | d | | d | | | d | | d | | d | d | d | d | d | d | d | d | d | d | d | d | d | d | d | d f f S(   s    Return the composition of two transformations S and T.
 A transformation is a tuple of the form (x, y, A), which denotes
 multiplying by matrix A and then translating by vector (x, y).
 These tuples can be passed to pattern.__call__().i    i   i   i   (    (   t   St   TR   R   t   AR    t   tt   B(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   composea   s    
 
 

 
 
6>t   patternc           B   s   e  Z d  Z d   Z d   Z e d  Z d   Z d   Z d d e d  Z	 d d d e d	  Z
 d d
  Z d   Z g  d d e d  Z RS(   s"   This class represents a cell list.c         C   s   t  t j |  |   S(   s   Join patterns.(   R+   R   t   join(   R   t   q(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   __add__r   s    c         C   s   |  j  |  S(   sy     The __getitem__() function is an alias to evolve().
  It allows to access the pattern's phases as elements of an array.(   t   evolve(   R   t   N(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   __getitem__v   s    c         C   s   t  t j |  | | |   S(   s'   The same as 'apply(A).translate(x, y)'.(   R+   R   t	   transform(   R   R   R   R'   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   __call__|   s    c         C   s   |  | |  S(   s   Translate the pattern.(    (   R   R   R   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt	   translate   s    c         C   s   |  d d |  S(   s     Apply a matrix transformation to the pattern.
  Predefined matrices are:
  identity, flip, flip_x, flip_y, swap_xy, swap_xy_flip,
  rcw (rotate clockwise) and rccw (rotate counter-clockwise).i    (    (   R   R'   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   apply   s    i    c         C   s   t  j |  | | |  d S(   s$   Paste pattern into current universe.N(   R   t   putcells(   R   R   R   R'   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   put   s    t   untitledc         C   s>   t  j |  t  j |  | | |  t  j   t  j t  d S(   s3   Paste pattern into new universe and display it all.N(   R   t   newR6   t   fitt	   setcursort   zoomin(   R   t   titleR   R   R'   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   display   s    
c         C   s   t  j |  | |  d S(   s]     Save the pattern to file 'fn' in RLE format.
  An optional description 'desc' may be given.N(   R   t   store(   R   t   fnt   desc(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   save   s    c         C   s   | d k  r t  d   n  |  j j |  r8 |  j | Sd } x< |  j j   D]+ } | | k  ok | k  n rN | } qN qN Wt t j |  j | | |   } |  j | <| S(   s     Return N-th generation of the pattern.
  Once computed, the N-th generation is remembered and quickly accessible.
  It is also the base for computing generations subsequent to N-th.i    s   backward evolving requested(   R   t   _pattern__phasest   has_keyt   keysR+   R   R/   (   R   R0   t   Mt   kt   p(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyR/      s     .c         C   s   t    |  _ t |  t k r1 t j |  |  nn t |  t k r\ t j |  t |   nC t |  t k r t j |  t j | | | |   n t	 d   |  |  j d <d S(   sB    Initialize a pattern from argument P.
  P may be another pattern, a cell list, or a multi-line string.
  A cell list should look like [x1, y1, x2, y2, ...];
  a string may be in one of the two autodetected formats:
  'visual' or 'RLE'.
  o  'visual' format means that the pattern is represented
     in a visual way using symbols '*' (on cell), '.' (off cell)
     and '\n' (newline), just like in Life 1.05 format.
     (Note that an empty line should contain at least one dot).
  o  'RLE' format means that a string is Run-Length Encoded.
     The format uses 'o' for on-cells, 'b' for off-cells and
     '$' for newlines.
     Moreover, any of these symbols may be prefixed by a number,
     to denote that symbol repeated that number of times.

  When P is a string, an optional transformation
  (x0, y0, A) may be specified.
  s   list or string is required herei    N(
   t   dictRC   t   typeR   R   R+   t   strR   t   parseR   (   R   t   Pt   x0t   y0R'   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyR      s    %N(   R   R   R   R.   R1   t   identityR3   R4   R5   R7   R>   t   NoneRB   R/   R   (    (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyR+   o   s   					c         C   s   t  t j |    S(   N(   R+   R   t   load(   R@   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyRR      s    c   
      C   sN  t  j } t  j } t  j } t  j } t |   } t |  } d } | d @d k rz d } | d d k rz | d 8} qz n  xT t d | |  D]@ } | | | k  r | | } n  | | | k r | | } q q WxT t d | |  D]@ }	 | |	 | k  r| |	 } n  | |	 | k r | |	 } q q Wt | | | | d | | d g  S(   Ni   i   i   i    (   t   syst   maxintR   R	   t   xrangeR    (
   t   pattt   minxt   maxxt   minyt   maxyt   clistt   clent   incR   R   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt	   getminbox   s,    	
	
     c         C   s_   t  |   d k r t S|  j d d  }  |  d d k sH |  d d k rU |  d }  n  |  j   S(   Ni    t   ,t    t   +t   -i   (   R	   R   t   replacet   isdigit(   R    (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   validint   s       c          C   s(   t  j   \ }  } t |   t |  f S(   N(   R   t   getpost   int(   R   R   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt	   getposint   s    c         C   s    t  j t |   t |   d  S(   N(   R   t   setposRK   (   R   R   (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt	   setposint  s    c         C   s"   t  j d d  t  j d  d  S(   Ns1   Change the script to use the getstring() command
s"   from golly rather than from glife.R`   (   R   t   warnt   exit(   t   prompt(    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt	   getstring  s    	(   i   i    i    i   (   ii    i    i(   ii    i    i   (   i   i    i    i(   i    i   i   i    (   i    iii    (   i    ii   i    (   i    i   ii    (%   R   RS   t   timeR   R   R    t   insidet   outsidet
   left_rightt
   top_bottomt   up_downt	   clockwiset   anticlockwiset   drawt   pickt   selectt   moveR<   t   zoomoutRP   t   flipt   flip_xt   flip_yt   swap_xyt   swap_xy_flipt   rcwt   rccwR!   R$   R*   R+   RR   R^   Re   Rh   Rj   Rn   (    (    (    s0   /home/akt/golly/Scripts/Python/glife/__init__.pyt   <module>   sF   			_						