m

IBc           @   s  d  Z  d k Z d k Z d k Z d k Z e Z d k Z d e i f d     YZ d Z	 d Z
 d Z d Z d k l Z d	 k l Z d k Z d k Z e d
  Z e d  Z d Z d a e a d Z d   Z d   Z d   Z d   Z d   Z e i e f   e i e  d e i  f d     YZ! d f  d     YZ" h  d d <d d <d d <d d <d d <d d  <d! d@ <Z# d% f  d&     YZ$ d' e$ f d(     YZ% d) e$ f d*     YZ& d+ e& f d,     YZ' d- e& f d.     YZ( d/ e( f d0     YZ) d1 e& f d2     YZ* d3 e$ f d4     YZ+ d5 e$ f d6     YZ, d7 e$ f d8     YZ- d9 e$ f d:     YZ. d; f  d<     YZ/ d=   Z0 d>   Z1 e2 d? j o e1   n d S(A   s  Simple object oriented graphics library

The library is designed to make it very easy for novice programmers to
experiment with computer graphics in an object oriented fashion. It is
written by John Zelle for use with the book "Python Programming: An
Introduction to Computer Science" (Franklin, Beedle & Associates).

LICENSE: This is open-source software released under the terms of the
GPL (http://www.gnu.org/licenses/gpl.html).

PLATFORMS: The package is a wrapper around Tkinter and should run on
any platform where Tkinter is available.

INSTALLATION: Put this file somewhere where Python can see it.

OVERVIEW: There are two kinds of objects in the library. The GraphWin
class implements a window where drawing can be done and various
GraphicsObjects are provided that can be drawn into a GraphWin. As a
simple example, here is a complete program to draw a circle of radius
10 centered in a 100x100 window:

--------------------------------------------------------------------
from graphics import *

def main():
    win = GraphWin("My Circle", 100, 100)
    c = Circle(Point(50,50), 10)
    c.draw(win)
    win.getMouse() // Pause to view result

main()
--------------------------------------------------------------------
GraphWin objects support coordinate transformation through the
setCoords method and pointer-based input through getMouse.

The library provides the following graphical objects:
    Point
    Line
    Circle
    Oval
    Rectangle
    Polygon
    Text
    Entry (for text-based input)
    Image

Various attributes of graphical objects can be set such as
outline-color, fill-color and line-width. Graphical objects also
support moving and hiding for animation effects.

The library also provides a very simple class for pixel-based image
manipulation, Pixmap. A pixmap can be loaded from a file and displayed
using an Image object. Both getPixel and setPixel methods are provided
for manipulating the image.

DOCUMENTATION: For complete documentation, see Chapter 5 of "Python
Programming: An Introduction to Computer Science" by John Zelle,
published by Franklin, Beedle & Associates.  Also see
http://mcsp.wartburg.edu/zelle/python for a quick referenceNt   GraphicsErrorc           B   s   t  Z d  Z e d  Z RS(   s3   Generic error class for graphics module exceptions.c         C   s   | |  _  d  S(   N(   t   argst   self(   R   R   (    (    t5   F:\anh\www\150\admin\zelle_code\chapter10\graphics.pyt   __init__   s    (   t   __name__t
   __module__t   __doc__t   NoneR   (    (    (    R   R       s    s   Object currently drawns    Object doesn't support operations   Illegal option values!   Graphics thread quit unexpectedly(   s   copy(   s   Queuei    i   i
   c           C   s4   t  i   a t i   t i t t  t i   d  S(   N(   t   tkt   Tkt   _roott   withdrawt   aftert   _POLL_INTERVALt   _tk_pumpt   mainloop(    (    (    R   t
   _tk_thread   s
     
c          C   s   xt t  i   pf t  i   \ } }  y% |   } |  o t i |  n Wq t a	 |  o t i d   n   q Xq Wt	 o t i t t  n d  S(   N(   t   _tk_requestt   emptyt   gett   commandt   returns_valuet   resultt
   _tk_resultt   putt   Falset   _thread_runningR   R   R   R   R   (   R   R   R   (    (    R   R      s      	c            sO   t  p t t  n     d   } t i | t f t  t i t  } | S(   Nc              s         S(   N(   t   fR   t   kw(    (   R   R   R   (    R   t   func   s    (
   R   R    t   DEAD_THREADR   R   R   t   TrueR   R   R   (   R   R   R   R   R   (    (   R   R   R   R   t   _tkCall   s    c            s@   t  p t t  n     d   } t i | t f t  d  S(   Nc              s         S(   N(   R   R   R   (    (   R   R   R   (    R   R      s    (   R   R    R   R   R   R   R   R    (   R   R   R   R   (    (   R   R   R   R   t   _tkExec   s    c           C   s   t  a t i d  d  S(   Nf0.5(   R   R   t   timet   sleep(    (    (    R   t   _tkShutdown   s     t   GraphWinc           B   s   t  Z d  Z d d d e d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z d d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s8   A GraphWin is a toplevel window for displaying graphics.s   Graphics Windowi   c         C   s   t  |  i | | | |  d  S(   N(   R!   R   t   _GraphWin__init_helpt   titlet   widtht   heightt	   autoflush(   R   R(   R)   R*   R+   (    (    R   R      s    c         C   s   t  i t  } | i d |  i  t  i i |  | d | d | |  i i |  |  i   | i d d  d |  _ g  |  _ d  |  _ d  |  _ |  i d |  i  | |  _
 | |  _	 | |  _ d  |  _ d  |  _ t |  _ | o t i   n d  S(   Nt   WM_DELETE_WINDOWR)   R*   i    t   blacks
   <Button-1>(   R	   t   ToplevelR   t   mastert   protocolR   t   _GraphWin__close_helpt   CanvasR   R)   R*   R(   t   packt	   resizablet
   foregroundt   itemsR   t   mouseXt   mouseYt   bindt   _onClickR+   t   _mouseCallbackt   transR   t   closedt   update(   R   R(   R)   R*   R+   R/   (    (    R   t   __init_help   s&    
										 c         C   s   |  i o t d  n d  S(   Ns   window is closed(   R   R=   R    (   R   (    (    R   t   __checkOpen   s    
c         C   s!   |  i   t |  i d | d S(   s"   Set background color of the windowt   bgN(   R   t   _GraphWin__checkOpenR"   t   configt   color(   R   RD   (    (    R   t   setBackground  s     
c         C   s(   t  |  i |  i | | | |  |  _ d S(   st   Set coordinates of window to run from (x1,y1) in the
        lower-left corner to (x2,y2) in the upper-right corner.N(	   t	   TransformR   R)   R*   t   x1t   y1t   x2t   y2R<   (   R   RG   RH   RI   RJ   (    (    R   t	   setCoords  s     c         C   s#   |  i o d  Sn t |  i  d  S(   N(   R   R=   R!   R1   (   R   (    (    R   t   close  s    
 c         C   s$   t  |  _ |  i i   t i   d S(   s   Close the windowN(   R    R   R=   R/   t   destroyR   R>   (   R   (    (    R   t   __close_help  s     	c         C   s   |  i S(   N(   R   R=   (   R   (    (    R   t   isClosed  s    c         C   s   |  i o t t i  n d  S(   N(   R   R+   R!   R   R>   (   R   (    (    R   t   __autoflush  s    
R-   c         C   sS   |  i   |  i | |  \ } } t |  i | | | d | d | |  i
   d S(   s"   Set pixel (x,y) to the given colori   t   fillN(   R   RB   t   toScreent   xt   yt   xst   ysR"   t   create_lineRD   t   _GraphWin__autoflush(   R   RS   RT   RD   RU   RV   (    (    R   t   plot  s
     
#c         C   s;   |  i   t |  i | | | d | d | |  i   d S(   sN   Set pixel raw (independent of window coordinates) pixel
        (x,y) to colori   RQ   N(   R   RB   R"   RW   RS   RT   RD   RX   (   R   RS   RT   RD   (    (    R   t	   plotPixel%  s     
#c         C   s   |  i   t |  i  d S(   s   Update drawing to the windowN(   R   RB   R!   t   update_idletasks(   R   (    (    R   t   flush-  s     
c         C   s   d |  _ d |  _ xY |  i d j p |  i d j o8 t |  i  |  i   o t d  n t i	 d  q W|  i
 |  i |  i  \ } } t | |  S(   sK   Wait for mouse click and return Point object representing
        the clicks   getMouse in closed windowf0.10000000000000001N(   R   R   R7   R8   R!   R>   RO   R    R#   R$   t   toWorldRS   RT   t   Point(   R   RT   RS   (    (    R   t   getMouse3  s     		   c         C   s   |  i S(   s   Return the height of the windowN(   R   R*   (   R   (    (    R   t	   getHeight@  s     c         C   s   |  i S(   s   Return the width of the windowN(   R   R)   (   R   (    (    R   t   getWidthD  s     c         C   s5   |  i } | o |  i i | |  Sn | | f Sd  S(   N(   R   R<   t   screenRS   RT   (   R   RS   RT   R<   (    (    R   RR   H  s    	c         C   s5   |  i } | o |  i i | |  Sn | | f Sd  S(   N(   R   R<   t   worldRS   RT   (   R   RS   RT   R<   (    (    R   R]   O  s    	c         C   s   | |  _ d  S(   N(   R   R   R;   (   R   R   (    (    R   t   setMouseHandlerV  s    c         C   sF   | i |  _ | i |  _ |  i o  |  i t | i | i   n d  S(   N(   t   eRS   R   R7   RT   R8   R;   R^   (   R   Re   (    (    R   R:   Y  s    
(   R   R   R   R   R   R'   RB   RE   RK   RL   R1   RO   RX   RY   RZ   R\   R_   R`   Ra   RR   R]   Rd   R:   (    (    (    R   R&      s(    															RF   c           B   s)   t  Z d  Z d   Z d   Z d   Z RS(   s1   Internal class for 2-D coordinate transformationsc   	      C   sX   | | } | | } | |  _ | |  _ | t	 | d  |  _ | t	 | d  |  _ d  S(   Ni   (   t   xhight   xlowt   xspant   yhight   ylowt   yspanR   t   xbaset   ybaset   floatt   wt   xscalet   ht   yscale(	   R   Ro   Rq   Rg   Rj   Rf   Ri   Rh   Rk   (    (    R   R   c  s    

		c         C   sF   | |  i |  i } |  i | |  i } t	 | d  t	 | d  f S(   Nf0.5(
   RS   R   Rl   Rp   RU   Rm   RT   Rr   RV   t   int(   R   RS   RT   RU   RV   (    (    R   Rb   n  s    c         C   s2   | |  i |  i } |  i | |  i } | | f S(   N(	   RU   R   Rp   Rl   RS   Rm   RV   Rr   RT   (   R   RU   RV   RT   RS   (    (    R   Rc   t  s    (   R   R   R   R   Rb   Rc   (    (    (    R   RF   _  s    		RQ   t    t   outlineR-   R)   t   1t   arrowt   nonet   textt   justifyt   centert   fontt	   helveticai   t   normalt   GraphicsObjectc           B   sh   t  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   Generic base class for all of the drawable objectsc         C   sD   d  |  _ d  |  _ h  } x | D] } t | | | <q W| |  _ d  S(   N(   R   R   t   canvast   idRC   t   optionst   optiont   DEFAULT_CONFIG(   R   R   R   RC   (    (    R   R     s    		 c         C   s   |  i d |  d S(   s   Set interior color to colorRQ   N(   R   t	   _reconfigRD   (   R   RD   (    (    R   t   setFill  s     c         C   s   |  i d |  d S(   s   Set outline color to colorRu   N(   R   R   RD   (   R   RD   (    (    R   t
   setOutline  s     c         C   s   |  i d |  d S(   s   Set line weight to widthR)   N(   R   R   R)   (   R   R)   (    (    R   t   setWidth  s     c         C   s   |  i o |  i i   o t t  n | i   o t d  n | |  _ t |  i | |  i  |  _	 | i
 o t t i  n d S(   s   Draw the object in graphwin, which should be a GraphWin
        object.  A GraphicsObject may only be drawn into one
        window. Raises an error if attempt made to draw an object that
        is already visible.s   Can't draw to closed windowN(   R   R   RO   R    t   OBJ_ALREADY_DRAWNt   graphwinR!   t   _drawRC   R   R+   R   R>   (   R   R   (    (    R   t   draw  s       	
c         C   sp   |  i p d Sn |  i i   p8 t |  i i |  i  |  i i o t t i	  qZ n d |  _ d |  _ d S(   s`   Undraw the object (i.e. hide it). Returns silently if the
        object is not currently drawn.N(   R   R   RO   R"   t   deleteR   R+   R!   R   R>   R   (   R   (    (    R   t   undraw  s     
 	c         C   s   |  i | |  |  i } | o | i   ov | i } | o | | i } | | i	 } n | } | } t |  i i |  i | |  | i o t t i  q n d S(   sG   move object dx units in x direction and dy units in y
        directionN(   R   t   _movet   dxt   dyR   RO   R<   Rp   RS   Rr   RT   R"   t   moveR   R+   R!   R   R>   (   R   R   R   R   RT   RS   R<   (    (    R   R     s     		
c         C   s   |  i i |  p t t  n |  i } | | | <|  i oL |  i i	   o; t
 |  i i |  i |  |  i i o t t i  q n d  S(   N(   R   RC   t   has_keyR   R    t   UNSUPPORTED_METHODR   t   settingR   RO   R"   t
   itemconfigR   R+   R!   R   R>   (   R   R   R   R   (    (    R   R     s    	
c         C   s   d S(   s\   draws appropriate figure on canvas with options provided
        Returns Tk id of item drawnN(    (   R   R   R   (    (    R   R     s    c         C   s   d S(   s7   updates internal state of object to move it dx,dy unitsN(    (   R   R   R   (    (    R   R     s    (   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R     s    									R^   c           B   s>   t  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         C   s8   t  i |  d d g  |  i |  _ | |  _ | |  _ d  S(   NRu   RQ   (   R   R   R   R   R   RS   RT   (   R   RS   RT   (    (    R   R     s    	c         C   s?   | i |  i |  i  \ } } | i | | | d | d |  S(   Ni   (   R   RR   R   RS   RT   t   create_rectangleR   (   R   R   R   RT   RS   (    (    R   R     s    c         C   s$   |  i | |  _ |  i | |  _ d  S(   N(   R   RS   R   RT   R   (   R   R   R   (    (    R   R     s    c         C   s+   t  |  i |  i  } |  i i   | _ | S(   N(   R^   R   RS   RT   t   otherRC   t   copy(   R   R   (    (    R   t   clone  s    c         C   s   |  i S(   N(   R   RS   (   R   (    (    R   t   getX  s    c         C   s   |  i S(   N(   R   RT   (   R   (    (    R   t   getY  s    (   R   R   R   R   R   R   R   R   (    (    (    R   R^     s   					t   _BBoxc           B   sA   t  Z d d d g d  Z d   Z d   Z d   Z d   Z RS(	   NRu   R)   RQ   c         C   s2   t  i |  |  | i   |  _ | i   |  _ d  S(   N(   R   R   R   R   t   p1R   t   p2(   R   R   R   R   (    (    R   R     s    c         C   s\   |  i i | |  i _ |  i i | |  i _ |  i i | |  i _ |  i i | |  i _ d  S(   N(   R   R   RS   R   RT   R   R   (   R   R   R   (    (    R   R     s    c         C   s   |  i i   S(   N(   R   R   R   (   R   (    (    R   t   getP1  s    c         C   s   |  i i   S(   N(   R   R   R   (   R   (    (    R   t   getP2  s    c         C   s;   |  i } |  i } t | i | i d | i | i d  S(   Nf2.0(   R   R   R   R^   RS   RT   (   R   R   R   (    (    R   t	   getCenter  s    		(   R   R   R   R   R   R   R   (    (    (    R   R   
  s
   			t	   Rectanglec           B   s#   t  Z d   Z d   Z d   Z RS(   Nc         C   s   t  i |  | |  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R   R   $  s    c   	      C   sg   |  i } |  i } | i | i | i  \ } } | i | i | i  \ } } | i | | | | |  S(   N(   R   R   R   R   RR   RS   RT   RG   RH   RI   RJ   R   R   (	   R   R   R   R   R   RJ   RI   RH   RG   (    (    R   R   '  s
    		c         C   s+   t  |  i |  i  } |  i i   | _ | S(   N(   R   R   R   R   R   RC   R   (   R   R   (    (    R   R   .  s    (   R   R   R   R   R   (    (    (    R   R   "  s   		t   Ovalc           B   s#   t  Z d   Z d   Z d   Z RS(   Nc         C   s   t  i |  | |  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R   R   5  s    c         C   s+   t  |  i |  i  } |  i i   | _ | S(   N(   R   R   R   R   R   RC   R   (   R   R   (    (    R   R   8  s    c   	      C   sg   |  i } |  i } | i | i | i  \ } } | i | i | i  \ } } | i | | | | |  S(   N(   R   R   R   R   RR   RS   RT   RG   RH   RI   RJ   t   create_ovalR   (	   R   R   R   R   R   RJ   RI   RH   RG   (    (    R   R   =  s
    		(   R   R   R   R   R   (    (    (    R   R   3  s   		t   Circlec           B   s#   t  Z d   Z d   Z d   Z RS(   Nc         C   sZ   t  | i | | i |  } t  | i | | i |  } t i |  | |  | |  _ d  S(   N(
   R^   R{   RS   t   radiusRT   R   R   R   R   R   (   R   R{   R   R   R   (    (    R   R   F  s    c         C   s.   t  |  i   |  i  } |  i i   | _ | S(   N(   R   R   R   R   R   RC   R   (   R   R   (    (    R   R   L  s    c         C   s   |  i S(   N(   R   R   (   R   (    (    R   t	   getRadiusQ  s    (   R   R   R   R   R   (    (    (    R   R   D  s   		t   Linec           B   s,   t  Z d   Z d   Z d   Z d   Z RS(   Nc         C   s@   t  i |  | | d d d g  |  i t d  |  i |  _ d  S(   NRw   RQ   R)   Ru   (   R   R   R   R   R   R   R   R   (   R   R   R   (    (    R   R   V  s    c         C   s+   t  |  i |  i  } |  i i   | _ | S(   N(   R   R   R   R   R   RC   R   (   R   R   (    (    R   R   [  s    c   	      C   sg   |  i } |  i } | i | i | i  \ } } | i | i | i  \ } } | i | | | | |  S(   N(   R   R   R   R   RR   RS   RT   RG   RH   RI   RJ   RW   R   (	   R   R   R   R   R   RJ   RI   RH   RG   (    (    R   R   `  s
    		c         C   s:   | d d d d g j o t t  n |  i d |  d  S(   Nt   firstt   lastt   bothRx   Rw   (   R   R    t
   BAD_OPTIONR   R   (   R   R   (    (    R   t   setArrowg  s    (   R   R   R   R   R   R   (    (    (    R   R   T  s   			t   Polygonc           B   s5   t  Z d   Z d   Z d   Z d   Z d   Z RS(   Nc         G   sp   t  |  d j o+ t | d t g   j  o | d } n t t i |  |  _ t i |  d d d g  d  S(   Ni   i    Ru   R)   RQ   (	   t   lent   pointst   typet   mapR^   R   R   R   R   (   R   R   (    (    R   R   o  s    0c         C   s(   t  t |  i  } |  i i   | _ | S(   N(   t   applyR   R   R   R   RC   R   (   R   R   (    (    R   R   v  s    c         C   s   t  t i |  i  S(   N(   R   R^   R   R   R   (   R   (    (    R   t	   getPoints{  s    c         C   s(   x! |  i D] } | i | |  q
 Wd  S(   N(   R   R   t   pR   R   R   (   R   R   R   R   (    (    R   R   ~  s    
 c         C   sr   | g } xI |  i D]> } | i | i | i  \ } } | i |  | i |  q W| i |  t
 t i |  S(   N(   R   R   R   R   R   RR   RS   RT   t   appendR   R   R&   t   create_polygon(   R   R   R   R   R   RT   RS   (    (    R   R     s    	
 (   R   R   R   R   R   R   R   (    (    (    R   R   m  s
   				t   Textc           B   sk   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 d
   Z d   Z RS(   Nc         C   sY   t  i |  d d d d g  |  i |  | i   |  _ |  i t	 d  |  i |  _
 d  S(   NRz   RQ   Ry   R|   Ru   (   R   R   R   t   setTextRy   R   R   t   anchorR   R   R   (   R   R   Ry   (    (    R   R     s
    c         C   s:   |  i } | i | i | i  \ } } | i | | |  S(   N(	   R   R   R   R   RR   RS   RT   t   create_textR   (   R   R   R   R   RT   RS   (    (    R   R     s    	c         C   s   |  i i | |  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R   R     s    c         C   s/   t  |  i |  i d  } |  i i   | _ | S(   NRy   (   R   R   R   RC   R   R   (   R   R   (    (    R   R     s    c         C   s   |  i d |  d  S(   NRy   (   R   R   Ry   (   R   Ry   (    (    R   R     s    c         C   s   |  i d S(   NRy   (   R   RC   (   R   (    (    R   t   getText  s    c         C   s   |  i i   S(   N(   R   R   R   (   R   (    (    R   t	   getAnchor  s    c         C   sY   | d d d d g j o3 |  i d \ } } } |  i d | | | f  n
 t t  d  S(   NR}   t   arialt   couriers   times romanR|   (	   t   faceR   RC   R   t   st   bR   R    R   (   R   R   R   R   R   (    (    R   t   setFace  s    c         C   s^   d | j o
 d j n o3 |  i d \ } } } |  i d | | | f  n
 t t  d  S(   Ni   i$   R|   (	   t   sizeR   RC   R   R   R   R   R    R   (   R   R   R   R   R   (    (    R   t   setSize  s    c         C   sY   | d d d d g j o3 |  i d \ } } } |  i d | | | f  n
 t t  d  S(   Nt   boldR~   t   italics   bold italicR|   (	   t   styleR   RC   R   R   R   R   R    R   (   R   R   R   R   R   (    (    R   t   setStyle  s    c         C   s   |  i |  d  S(   N(   R   R   RD   (   R   RD   (    (    R   t   setTextColor  s    (   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R     s   										t   Entryc           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 RS(   Nc         C   s|   t  i |  g   | i   |  _ | |  _ t t i	 t
  |  _ t |  i i d  d |  _ d |  _ t d |  _ d  |  _ d  S(   NRt   t   grayR-   R|   (   R   R   R   R   R   R   R)   R!   R	   t	   StringVarR   Ry   t   setRQ   RD   R   R|   R   t   entry(   R   R   R)   (    (    R   R     s    			c         C   s   |  i } | i | i | i  \ } } t i | i	  } t i | d |  i d |  i d |  i d |  i d |  i |  _ |  i i   | i | | d | S(   NR)   t   textvariableRA   t   fgR|   t   window(   R   R   R   R   RR   RS   RT   R	   t   FrameR/   t   frmR   R)   Ry   RQ   RD   R|   R   R3   t   create_window(   R   R   R   R   R   RT   RS   (    (    R   R     s    						c         C   s   t  |  i i  S(   N(   R!   R   Ry   R   (   R   (    (    R   R     s    c         C   s   |  i i | |  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R   R     s    c         C   s   |  i i   S(   N(   R   R   R   (   R   (    (    R   R     s    c         C   s%   t  |  i |  i  } t |  i |  S(   N(   R   R   R   R)   R   R!   t   _Entry__clone_help(   R   R   (    (    R   R     s    c         C   sJ   |  i i   | _ t i   | _ | i i |  i i    |  i	 | _	 | S(   N(
   R   RC   R   R   R	   R   Ry   R   R   RQ   (   R   R   (    (    R   t   __clone_help  s
    c         C   s   t  |  i i |  d  S(   N(   R!   R   Ry   R   t   t(   R   R   (    (    R   R     s    c         C   s1   | |  _ |  i o t |  i i d | n d  S(   NRA   (   RD   R   RQ   R   R"   RC   (   R   RD   (    (    R   R     s    	
c         C   sS   t  |  i  } | | | <t |  |  _ |  i o t |  i i d |  i n d  S(   NR|   (	   t   listR   R|   t   valuet   whicht   tupleR   R"   RC   (   R   R   R   R|   (    (    R   t   _setFontComponent  s
    

c         C   s:   | d d d d g j o |  i d |  n
 t t  d  S(   NR}   R   R   s   times romani    (   R   R   R   R    R   (   R   R   (    (    R   R     s    c         C   s?   d | j o
 d j n o |  i d |  n
 t t  d  S(   Ni   i$   i   (   R   R   R   R    R   (   R   R   (    (    R   R     s    c         C   s:   | d d d d g j o |  i d |  n
 t t  d  S(   NR   R~   R   s   bold italici   (   R   R   R   R    R   (   R   R   (    (    R   R     s    c         C   s1   | |  _  |  i o t |  i i d | n d  S(   NR   (   RD   R   R   R"   RC   (   R   RD   (    (    R   R     s    	
(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R     s   													t   Imagec           B   sJ   t  Z d Z h  Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   Ni    c         C   s   t  i |  g   | i   |  _ t i |  _ t i d t _ t	 |  t	 d  j o t i d | d t  |  _ n | i |  _ d  S(   Ni   Rt   t   fileR/   (   R   R   R   R   R   R   R   t   idCountt   imageIdR   t   pixmapR	   t
   PhotoImageR   t   imgt   image(   R   R   R   (    (    R   R   %  s    c         C   sS   |  i } | i | i | i  \ } } |  i |  i |  i	 <| i
 | | d |  i S(   NR   (   R   R   R   R   RR   RS   RT   R   t
   imageCacheR   t   create_image(   R   R   R   R   RT   RS   (    (    R   R   /  s    	c         C   s   |  i i | |  d  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R   R   5  s    c         C   s   |  i |  i =t i |   d  S(   N(   R   R   R   R   R   (   R   (    (    R   R   8  s    c         C   s   |  i i   S(   N(   R   R   R   (   R   (    (    R   R   <  s    c         C   s@   t  t |  i i   } t |  i |  } |  i	 i   | _	 | S(   N(
   t   PixmapR!   R   R   R   t   imgCopyR   R   R   RC   (   R   R   R   (    (    R   R   ?  s    (
   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R      s   	
				R   c           B   sM   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   Pixmap represents an image as a 2D array of color values.
    A Pixmap can be made from a file (gif or ppm):

       pic = Pixmap("myPicture.gif")
       
    or initialized to a given size (initially transparent):

       pic = Pixmap(512, 512)


    c         G   s   t  |  d j oT t | d  t d  j o& t t i d | d d t |  _ q | d |  _ n1 | \ } } t t i d t d | d | |  _ d  S(   Ni   i    Rt   R   R/   R)   R*   (   R   R   R   R!   R	   R   R   R   R   R)   R*   (   R   R   R*   R)   (    (    R   R   S  s    &c         C   s   t  |  i i  S(   s(   Returns the width of the image in pixelsN(   R!   R   R   R)   (   R   (    (    R   Ra   ^  s     c         C   s   t  |  i i  S(   s)   Returns the height of the image in pixelsN(   R!   R   R   R*   (   R   (    (    R   R`   b  s     c         C   sS   t  |  i i | |  } t |  t j o | | | g Sn t	 t | i
    Sd S(   sj   Returns a list [r,g,b] with the RGB color values for pixel (x,y)
        r,g,b are in range(256)

        N(   R!   R   R   R   RS   RT   R   R   Rs   R   t   split(   R   RS   RT   R   (    (    R   t   getPixelf  s
     c         C   s?   | \ } } } t |  i i d t | | |  | | f  d S(   sn   Sets pixel (x,y) to the color given by RGB values r, g, and b.
        r,g,b should be in range(256)

        s   {%s}N(
   t   rt   gR   R"   R   R   R   t	   color_rgbRS   RT   (   R   RS   RT   t   .6R   R   R   (    (    R   t   setPixelr  s    c         C   s   t  |  i i    S(   s   Returns a copy of this PixmapN(   R   R   R   R   (   R   (    (    R   R   z  s     c         C   sH   t  i i |  \ } } | i d  d } t |  i i	 | d | d S(   s}   Saves the pixmap image to filename.
        The format for the save image is determined from the filname extension.

        t   .it   formatN(
   t   ost   pathR   t   filenamet   namet   extR"   R   R   t   write(   R   R   R   R   R   (    (    R   t   save~  s     (
   R   R   R   R   Ra   R`   R   R   R   R   (    (    (    R   R   F  s    						c         C   s   d |  | | f S(   sv   r,g,b are intensities of red, green, and blue in range(256)
    Returns color specifier string for the resulting colors   #%02x%02x%02xN(   R   R   R   (   R   R   R   (    (    R   R     s     c          C   su  t    } | i d d d d  t t d d  d  } | i |  t t d d  t d d  t d d   } | i |  t	 t d d	  d  }  |  i |  | i   | i d
  | i d  | i d  d } x4 | i   D]& } | d | i   | i   f } q W| i |  i    |  i d  |  i d  |  i d d  | i   | i d d  d } x4 | i   D]& } | d | i   | i   f } q{W| i |  | i   | i   |  i   | i d  | i   | i d  | i   | i d  | i   | i d  | i   | i d  | i   | i d  | i d  | i   | i   d  S(   Ni    i
   i   s   Centered Texti   i   i   i   i   t   redt   blueRt   s   (%0.1f,%0.1f) t   greens   Spam!R   R~   R   s   bold italici   R   i   (   R&   t   winRK   R   R^   R   R   R   R   R   Re   R_   R   R   R   R   R   t   ptR   R   R   R   R   R   R   R   R   RL   (   Re   R   R   R   R   R   (    (    R   t   test  sX    	-
 $
 $








t   __main__(   s	   helveticai   s   normal(3   R   R#   R   t   syst   TkinterR	   t
   exceptionst	   ExceptionR    R   R   R   R   R   t   Queuet   threadt   atexitR   R   R   R   R   R    R   t   _exception_infoR   R   R!   R"   R%   t   start_new_threadt   registerR2   R&   RF   R   R   R^   R   R   R   R   R   R   R   R   R   R   R   R   R   ()   R   R   RF   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^   R   R   R   R    R#   R  R   R   R   (    (    R   t   ?<   sZ   >									En8]&C		,