
`]c           @   s   d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d l	 m
 Z
 m Z m Z m Z m Z m Z d e f d     YZ d   Z e e d	  Z d
 e f d     YZ d e f d     YZ d   Z d   Z e d k r e   n  d S(   s   
Graphically display a Tree.
i(   t   IntVart   Menut   Tk(   t   in_idle(   t   Tree(   t   CanvasFramet   CanvasWidgett	   BoxWidgett
   TextWidgett   ParenWidgett
   OvalWidgett   TreeSegmentWidgetc           B   s   e  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   Z RS(   s  
    A canvas widget that displays a single segment of a hierarchical
    tree.  Each ``TreeSegmentWidget`` connects a single "node widget"
    to a sequence of zero or more "subtree widgets".  By default, the
    bottom of the node is connected to the top of each subtree by a
    single line.  However, if the ``roof`` attribute is set, then a
    single triangular "roof" will connect the node to all of its
    children.

    Attributes:
      - ``roof``: What sort of connection to draw between the node and
        its subtrees.  If ``roof`` is true, draw a single triangular
        "roof" over the subtrees.  If ``roof`` is false, draw a line
        between each subtree and the node.  Default value is false.
      - ``xspace``: The amount of horizontal space to leave between
        subtrees when managing this widget.  Default value is 10.
      - ``yspace``: The amount of space to place between the node and
        its children when managing this widget.  Default value is 15.
      - ``color``: The color of the lines connecting the node to its
        subtrees; and of the outline of the triangular roof.  Default
        value is ``'#006060'``.
      - ``fill``: The fill color for the triangular roof.  Default
        value is ``''`` (no fill).
      - ``width``: The width of the lines connecting the node to its
        subtrees; and of the outline of the triangular roof.  Default
        value is 1.
      - ``orientation``: Determines whether the tree branches downwards
        or rightwards.  Possible values are ``'horizontal'`` and
        ``'vertical'``.  The default value is ``'vertical'`` (i.e.,
        branch downwards).
      - ``draggable``: whether the widget can be dragged by the user.
    c      	   K   s   | |  _  | |  _ d |  _ d |  _ d |  _ d |  _ t |  _ g  | D]$ } | j d d d d d d ^ qF |  _	 | j
 d d d d d d d	 d |  _ |  j |  x | D] } |  j |  q Wt |  _ t j |  | |  d
 S(   sI   
        :type node:
        :type subtrees: list(CanvasWidgetI)
        i    i
   i   t   fills   #006060t    t   statet   hiddent   outlineN(   t   _labelt	   _subtreest   _horizontalt   _rooft   _xspacet   _yspacet   Falset   _orderedt   create_linet   _linest   create_polygont   _polygont   _add_child_widgett	   _managingR   t   __init__(   t   selft   canvast   labelt   subtreest   attribst   ct   subtree(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR   @   s    							4!	c         C   s  |  j    } | d k r | |  _ |  j rj x$ |  j D] } | j | d d q4 W| j |  j d d qx$ |  j D] } | j | d d qt W| j |  j d d n| d k r | d k r d |  _ q| d k r d	 |  _ qt d
   n| d k rAx$ |  j D] } | j | d | qW| j |  j d | n?t | t  r| d	 d k r|  j t	 | d  } | j | d | n | d k r| j |  j d | n | d k r| j |  j i | | 6 x |  j D] } | j | i | | 6 qWnz | d k rU| d k r*| |  _
 n | d k rB| |  _ n  |  j |  j  n+ | d k rm| |  _ n t j |  | |  d  S(   Nt   roofR   R   t   normalt   orientationt
   horizontali   t   verticali    s*   orientation must be horizontal or verticalt   colorR   R   t   widtht   xspacet   yspacet   ordered(   R.   R/   (   R!   R   R   t
   itemconfigR   R   t
   ValueErrort
   isinstancet   tuplet   intR   R   t   updateR   R   R   t   __setitem__(   R    t   attrt   valueR!   t   l(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR7   _   sL    		c         C   s  | d k r |  j  S| d k r8 |  j   j |  j |  S| d k r] |  j   j |  j d  St | t  r | d d k r |  j t | d  } |  j   j | d  S| d k r |  j S| d	 k r |  j	 S| d
 k r |  j
 r d Sd Sn# | d k r|  j St j |  |  Sd  S(   NR'   R-   R,   R   i    i   R   R.   R/   R)   R*   R+   R0   (   R   R!   t   itemcgetR   R3   R4   R   R5   R   R   R   R   R   t   __getitem__(   R    R8   R:   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR<      s(    	c         C   s   |  j  S(   N(   R   (   R    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR"      s    c         C   s   |  j  S(   N(   R   (   R    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR#      s    c         C   s:   |  j  |  j  |  j |  | |  _ |  j |  j  d S(   s2   
        Set the node label to ``label``.
        N(   t   _remove_child_widgetR   R   R6   (   R    R"   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt	   set_label   s    	c         C   sJ   |  j  j |  } | |  j  | <|  j |  |  j |  |  j |  d S(   sC   
        Replace the child ``oldchild`` with ``newchild``.
        N(   R   t   indexR=   R   R6   (   R    t   oldchildt   newchildR?   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   replace_child   s
    c         C   sY   |  j  j |  } |  j  | =|  j |  |  j   j |  j j    |  j |  j  d  S(   N(	   R   R?   R=   R!   t   deleteR   t   popR6   R   (   R    t   childR?   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   remove_child   s
    
c         C   sh   |  j    } |  j j | |  |  j |  |  j j | j d d d d d d  |  j |  j  d  S(   Ni    R   s   #006060(	   R!   R   t   insertR   R   t   appendR   R6   R   (   R    R?   RE   R!   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   insert_child   s
    (c         C   s   |  j  r |  j g S|  j Sd  S(   N(   R   R   R   (   R    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _tags   s    	
c         C   sy   t  | t  r$ | j   j   } n | j   } |  j rW | d | d | d d f S| d | d d | d f Sd  S(   Ni    i   i   g       @i   (   R3   R   R"   t   bboxR   (   R    RE   RK   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _subtree_top   s    	c         C   sX   |  j  j   } |  j r6 | d | d | d d f S| d | d d | d f Sd  S(   Ni   i   i   g       @i    (   R   RK   R   (   R    RK   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _node_bottom   s    	c      
   C   s  t  |  j  d k r d  S|  j j   d  k r2 d  S| |  j k rM |  j } n	 | g } |  j r{ |  j r{ |  j |  } n  |  j   \ } } |  j d j   \ } } } } xm |  j d D]^ }	 |	 j   }
 t	 | |
 d  } t	 | |
 d  } t
 | |
 d  } t
 | |
 d  } q W|  j rV|  j   j |  j | | | | | | | | 	 n. |  j   j |  j | | | | | | | | 	 xm | D]e }	 |  j   \ } } |  j |  j j |	  } |  j |	  \ } } |  j   j | | | | |  qWd  S(   Ni    i   i   i   (   t   lenR   R   RK   t   NoneR   R   t   _maintain_orderRM   t   mint   maxR   R!   t   coordsR   R   R?   RL   (   R    RE   t   need_updatet   nodext   nodeyt   xmint   ymint   xmaxt   ymaxR&   RK   t   linet   subtreext   subtreey(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _update   s6    		%"c         C   s'   |  j  r |  j |  S|  j |  Sd  S(   N(   R   t   _maintain_order_horizontalt   _maintain_order_vertical(   R    RE   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyRP     s    	c         C   sH  | j    \ } } } } | |  j k r xZ |  j D]O } | j    \ } } }	 }
 | |  j | k r1 | j d | |  j |  q1 q1 W|  j S| g } |  j j |  } | |  j } x t | d t |  j   D]x } |  j | j    \ } } }	 }
 | | k r |  j | j | | d  | |	 | |  j 7} | j	 |  j |  q q W| |  j } x t | d d d  D]x } |  j | j    \ } } }	 }
 | |	 k  rp|  j | j | |	 d  | |	 | |  j 8} | j	 |  j |  qpqpW|  j j    \ } } }	 }
 |
 | |  j k rD|  j j d | |  j |
  |  j } n  | S(   Ni    i   i(
   RK   R   R   R   t   moveR?   R   t   rangeRN   RH   (   R    RE   t   leftt   topt   rightt   botR&   t   x1t   y1t   x2t   y2t   movedR?   t   xt   i(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR`     s8    "	#c         C   sE  | j    \ } } } } | |  j k r xW |  j D]L } | j    \ } } }	 }
 | |  j | k r1 | j | |  j |  q1 q1 W|  j S| g } |  j j |  } | |  j } x t | d t |  j   D]x } |  j | j    \ } } }	 }
 | | k r |  j | j d | |  | |
 | |  j 7} | j	 |  j |  q q W| |  j } x t | d d d  D]x } |  j | j    \ } } }	 }
 | |
 k  rm|  j | j d | |
  | |
 | |  j 8} | j	 |  j |  qmqmW|  j j    \ } } }	 }
 |	 | |  j k rA|  j j | |  j |	 d  |  j } n  | S(   Ni   i    i(
   RK   R   R   R   Ra   R?   R   Rb   RN   RH   (   R    RE   Rc   Rd   Re   Rf   R&   Rg   Rh   Ri   Rj   Rk   R?   t   yRm   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR_   <  s8    	#c   	      C   s   |  j    \ } } d } xm |  j D]b } | j   } | | d |  j } | | d } | j | |  | | d | d |  j 7} q" Wd } x( |  j D] } | |  j |  d 7} q W| t |  j  :} x% |  j D] } | j d | |  q Wd  S(   Ni   i    i   i   g        (   RM   R   RK   R   Ra   R   RL   RN   (	   R    RU   RV   Rn   R&   t   subtree_bboxt   dxt   dyt   center(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _manage_horizontalf  s    !c   	      C   s   |  j    \ } } d } xm |  j D]b } | j   } | | d |  j } | | d } | j | |  | | d | d |  j 7} q" Wd } x5 |  j D]* } | |  j |  d t |  j  7} q Wx% |  j D] } | j | | d  q Wd  S(   Ni    i   i   g        (   RM   R   RK   R   Ra   R   RL   RN   (	   R    RU   RV   Rl   R&   Ro   Rq   Rp   Rr   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _manage_vertical|  s    !(c         C   s   t  |  _ |  j   \ } } t |  j  d k r4 d  S|  j rJ |  j   n
 |  j   x |  j D] } |  j |  q^ Wt	 |  _ d  S(   Ni    (
   t   TrueR   RM   RN   R   R   Rs   Rt   R^   R   (   R    RU   RV   R&   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   _manage  s    		
c         C   s   d |  j  |  j f S(   Ns   [TreeSeg %s: %s](   R   R   (   R    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   __repr__  s    (   t   __name__t
   __module__t   __doc__R   R7   R<   R"   R#   R>   RB   RF   RI   RJ   RL   RM   R^   RP   R`   R_   Rs   Rt   Rv   Rw   (    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR      s*    		,						
					
		)		*	*			c         C   s   t  | t  rn | |  | j   |  } g  | D]' }	 t |  |	 | | | | | |  ^ q. }
 t |  | |
 |  S| |  | |  Sd  S(   N(   R3   R   R"   t   _tree_to_treesegR   (   R!   t   tt	   make_nodet	   make_leaft   tree_attribst   node_attribst   leaf_attribst   loc_attribsR"   RE   R#   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR{     s    

1c      	   K   s   i  } i  } i  } i  } x t  | j    D] \ }	 }
 |	 d  d k rX |
 | |	 d <q+ |	 d  d k ry |
 | |	 d <q+ |	 d  d k r |
 | |	 d <q+ |	 d  d k r |
 | |	 d <q+ t d |	   q+ Wt |  | | | | | | |  S(   sS  
    Convert a Tree into a ``TreeSegmentWidget``.

    :param make_node: A ``CanvasWidget`` constructor or a function that
        creates ``CanvasWidgets``.  ``make_node`` is used to convert
        the Tree's nodes into ``CanvasWidgets``.  If no constructor
        is specified, then ``TextWidget`` will be used.
    :param make_leaf: A ``CanvasWidget`` constructor or a function that
        creates ``CanvasWidgets``.  ``make_leaf`` is used to convert
        the Tree's leafs into ``CanvasWidgets``.  If no constructor
        is specified, then ``TextWidget`` will be used.
    :param attribs: Attributes for the canvas widgets that make up the
        returned ``TreeSegmentWidget``.  Any attribute beginning with
        ``'tree_'`` will be passed to all ``TreeSegmentWidgets`` (with
        the ``'tree_'`` prefix removed.  Any attribute beginning with
        ``'node_'`` will be passed to all nodes.  Any attribute
        beginning with ``'leaf_'`` will be passed to all leaves.  And
        any attribute beginning with ``'loc_'`` will be passed to all
        text locations (for Trees).
    i   t   tree_t   node_t   leaf_i   t   loc_s   Bad attribute: %s(   t   listt   itemsR2   R{   (   R!   R|   R}   R~   R$   R   R   R   R   t   keyR9   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   tree_to_treesegment  s.    t
   TreeWidgetc           B   s   e  Z d  Z e e d  Z d   Z d   Z d d  Z d d  Z d d  Z	 d d  Z
 d d	  Z d d
  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  
    A canvas widget that displays a single Tree.
    ``TreeWidget`` manages a group of ``TreeSegmentWidgets`` that are
    used to display a Tree.

    Attributes:

      - ``node_attr``: Sets the attribute ``attr`` on all of the
        node widgets for this ``TreeWidget``.
      - ``node_attr``: Sets the attribute ``attr`` on all of the
        leaf widgets for this ``TreeWidget``.
      - ``loc_attr``: Sets the attribute ``attr`` on all of the
        location widgets for this ``TreeWidget`` (if it was built from
        a Tree).  Note that a location widget is a ``TextWidget``.

      - ``xspace``: The amount of horizontal space to leave between
        subtrees when managing this widget.  Default value is 10.
      - ``yspace``: The amount of space to place between the node and
        its children when managing this widget.  Default value is 15.

      - ``line_color``: The color of the lines connecting each expanded
        node to its subtrees.
      - ``roof_color``: The color of the outline of the triangular roof
        for collapsed trees.
      - ``roof_fill``: The fill color for the triangular roof for
        collapsed trees.
      - ``width``

      - ``orientation``: Determines whether the tree branches downwards
        or rightwards.  Possible values are ``'horizontal'`` and
        ``'vertical'``.  The default value is ``'vertical'`` (i.e.,
        branch downwards).

      - ``shapeable``: whether the subtrees can be independently
        dragged by the user.  THIS property simply sets the
        ``DRAGGABLE`` property on all of the ``TreeWidget``'s tree
        segments.
      - ``draggable``: whether the widget can be dragged by the user.
    c         K   s  | |  _  | |  _ | |  _ i  |  _ i  |  _ i d d 6|  _ d |  _ d |  _ d |  _ d |  _	 t
 |  _ d |  _ d |  _ d |  _ t
 |  _ i  |  _ i  |  _ i  |  _ g  |  _ g  |  _ |  j | | d  |  j | | d	  |  _ |  j |  j  t j |  | |  d  S(
   Ns   #008000R,   s   #008080i   s   #c0c0c0i
   R+   (    (    (   t
   _make_nodet
   _make_leaft   _treet   _nodeattribst   _leafattribst   _locattribst   _line_colort   _line_widtht   _roof_colort
   _roof_fillR   t
   _shapeableR   R   t   _orientationR   t   _keyst   _expanded_treest   _collapsed_treest   _nodest   _leavest   _make_collapsed_treest   _make_expanded_treet   _treesegR   R   R   (   R    R!   R|   R}   R~   R$   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR   &  s0    																			c         G   s   |  j  | S(   sF  
        Return the ``TreeSegmentWidget`` for the specified subtree.

        :param path_to_tree: A list of indices i1, i2, ..., in, where
            the desired widget is the widget corresponding to
            ``tree.children()[i1].children()[i2]....children()[in]``.
            For the root, the path is ``()``.
        (   R   (   R    t   path_to_tree(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   expanded_treeI  s    	c         G   s   |  j  | S(   sF  
        Return the ``TreeSegmentWidget`` for the specified subtree.

        :param path_to_tree: A list of indices i1, i2, ..., in, where
            the desired widget is the widget corresponding to
            ``tree.children()[i1].children()[i2]....children()[in]``.
            For the root, the path is ``()``.
        (   R   (   R    R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   collapsed_treeT  s    	i   c         C   sd   x- t  |  j j    D] } | j | |  q Wx- t  |  j j    D] } | j | |  qF Wd S(   s5   
        Add a binding to all tree segments.
        N(   R   R   t   valuest
   bind_clickR   (   R    t   callbackt   buttont   tseg(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_click_trees_  s    c         C   sd   x- t  |  j j    D] } | j | |  q Wx- t  |  j j    D] } | j | |  qF Wd S(   s5   
        Add a binding to all tree segments.
        N(   R   R   R   t	   bind_dragR   (   R    R   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_drag_treesh  s    c         C   sL   x! |  j  D] } | j | |  q
 Wx! |  j  D] } | j | |  q. Wd S(   s.   
        Add a binding to all leaves.
        N(   R   R   (   R    R   R   t   leaf(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_click_leavesq  s    c         C   sL   x! |  j  D] } | j | |  q
 Wx! |  j  D] } | j | |  q. Wd S(   s.   
        Add a binding to all leaves.
        N(   R   R   (   R    R   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_drag_leavesz  s    c         C   sL   x! |  j  D] } | j | |  q
 Wx! |  j  D] } | j | |  q. Wd S(   s-   
        Add a binding to all nodes.
        N(   R   R   (   R    R   R   t   node(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_click_nodes  s    c         C   sL   x! |  j  D] } | j | |  q
 Wx! |  j  D] } | j | |  q. Wd S(   s-   
        Add a binding to all nodes.
        N(   R   R   (   R    R   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   bind_drag_nodes  s    c         C   s)  t  | t  s d  S|  j } |  j } | | | j   |  j  } |  j j |  g  | j   D] } | | | |  j	  ^ q] } |  j
 | 7_
 t | | | d d d |  j d |  j d |  j }	 |	 |  j | <| |  j |	 <|	 j   x> t t |   D]* }
 | |
 } |  j | | | |
 f  q Wd  S(   NR'   i   R,   R   R-   (   R3   R   R   R   R"   R   R   RH   t   leavesR   R   R   R   R   R   R   R   t   hideRb   RN   R   (   R    R!   R|   R   R}   R~   R   R:   R   t   treesegRm   RE   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s,    		.		

c         C   s   |  j  } |  j } t | t  r | | | j   |  j  } |  j j |  | } g  t t	 |   D]& } |  j
 | | | | | f  ^ qe }	 t | | |	 d |  j d |  j }
 |
 |  j | <| |  j |
 <|
 S| | | |  j  } |  j j |  | Sd  S(   NR,   R-   (   R   R   R3   R   R"   R   R   RH   Rb   RN   R   R   R   R   R   R   R   R   (   R    R!   R|   R   R}   R~   R   t   childrenRm   R#   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s     		<!c         C   s  | d  d k r5 x|  j  D] } | | | d <q Wn| d  d k rj x|  j D] } | | | d <qO Wn| d k r | |  _ xt |  j j    D] } | | d <q Wn[| d k r| |  _ x' t |  j j    D] } | | d <q Wxt |  j j    D] } | | d <qWn| d k rZ| |  _ xt |  j j    D] } | | d <qCWn| d	 k r| |  _	 xt |  j j    D] } | | d
 <qWnk| d k r&| |  _
 x' t |  j j    D] } | | d <qWx' t |  j j    D] } | | d <qWx|  j D] } | | d <qWn| d k r| |  _ x' t |  j j    D] } | | d <qQWx' t |  j j    D] } | | d <q{W|  j   nk| d k r| |  _ x' t |  j j    D] } | | d <qWx' t |  j j    D] } | | d <qW|  j   n | d k r| |  _ x' t |  j j    D] } | | d <q=Wx' t |  j j    D] } | | d <qgW|  j   n | d k r| |  _ x' t |  j j    D] } | | d <qWx= t |  j j    D] } | | d <qWn t j |  | |  d  S(   Ni   R   R   t
   line_colorR,   t
   line_widthR-   t
   roof_colort	   roof_fillR   t	   shapeablet	   draggableR.   R/   R)   R0   (   R   R   R   R   R   R   R   R   R   R   R   R   t   manageR   R   R   R   R7   (   R    R8   R9   R   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR7     sx    									c         C   s!  | d  d k r' |  j  j | d d   S| d  d k rN |  j j | d d   S| d  d k ru |  j j | d d   S| d k r |  j S| d k r |  j S| d k r |  j S| d	 k r |  j S| d
 k r |  j	 S| d k r |  j
 S| d k r |  j S| d k r|  j St j |  |  Sd  S(   Ni   R   R   i   R   R   R   R   R   R   R.   R/   R)   (   R   t   getRO   R   R   R   R   R   R   R   R   R   R   R   R<   (   R    R8   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR<   	  s.    c         C   s   g  S(   N(    (   R    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyRJ   #  s    c         C   sj   t  |  j j    t  |  j j    } x; | D]3 } | j   r/ | j   | j   | j   q/ q/ Wd  S(   N(   R   R   R   R   R   t   showR   R   (   R    t   segsR   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyRv   &  s    

c         C   s  | } | d r' |  j  |  j | } n |  j |  j | } | j   |  k rs |  j |  |  j |  | |  _ n | j   j | |  | j   | j	   j
   d  \ } } | j	   j
   d  \ } } | j | | | |  | j   | j   j |  d S(   s)   
        Collapse/expand a tree.
        R'   i   N(   R   R   R   t   parentR=   R   R   RB   R   R"   RK   Ra   R   R6   (   R    R   t   old_treesegt   new_treesegt   newxt   newyt   oldxt   oldy(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   toggle_collapsed0  s    


(   Rx   Ry   Rz   R   R   R   R   R   R   R   R   R   R   R   R   R7   R<   RJ   Rv   R   (    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s"   '"											?			
t   TreeViewc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c   	      G   s  d d l  m } m } | |  _ t   |  _ |  j j d  |  j j d |  j  |  j j d |  j  t	 |  j  } |  _
 |  j j d |  j
 j  t |  j  |  _ |  j j d  d |  j j   d	 f } d |  j j   f } t | | t |     |  _ g  |  _ x t t |   D] } t | j   | | d
 | d d d d d d d d d d d d d | } | j | j  |  j j |  | j | d d  q$W|  j   |  j
 j d d d d  |  j   d  S(   Ni(   t   sqrtt   ceilt   NLTKs   <Control-x>s   <Control-q>s   <Control-p>i   t	   helveticat   boldt	   node_fontt
   leaf_colors   #008040t
   node_colors   #004080R   s   #004040R   t   whiteR   R   i   t	   leaf_fonti    t   expandR   t   both(   t   mathR   R   t   _treesR   t   _topt   titlet   bindt   destroyR   t   _cframet   print_to_fileR    t   _sizet   setR   R5   RN   t   _widtht   _widgetsRb   R   R!   R   R   RH   t
   add_widgett   _layoutt   packt   _init_menubar(	   R    t   treesR   R   t   cfR   t   helvRm   t   widget(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR   V  s@    	!		
	
c   	      C   s   d } } } } |  j  } x t t |  j   D] } |  j | } | j   d  \ } } | | d k ry | } d } n  | j | | | |  | j   d d } t | | j   d d  } q1 Wd  S(   Ni    i   i
   i   (   R   Rb   RN   R   RK   Ra   RR   (	   R    Rm   Rl   Rn   RZ   R-   R   R   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s    		c         C   s  t  |  j  } t  | d d } | j d d d d d |  j j d d  | j d d	 d d
 d |  j d d  | j d d d d d |  t  | d d } | j d d d |  j d d d d d |  j	  | j d d d |  j d d d d d |  j	  | j d d d |  j d d d d d |  j	  | j d d d |  j d d d d d |  j	  | j d d d |  j d d d d d |  j	  | j d d d d d |  |  j j
 d |  d  S(   Nt   tearoffi    R"   s   Print to Postscriptt	   underlinet   commandt   accelerators   Ctrl-pt   Exiti   s   Ctrl-xt   Filet   menut   Tinyt   variableR9   i
   t   Smalli   t   Mediumi   t   Largei   t   Hugei2   t   Zoom(   R   R   t   add_commandR   R   R   t   add_cascadet   add_radiobuttonR   t   resizet   config(   R    t   menubart   filemenut   zoommenu(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     sV    				
		
		
		
		
c         G   s   d |  j  j   d f } d |  j  j   f } |  j  j   } |  j  j   } x |  j D]| } | | d <| | d <| | d <| | d <|  j  j   d k  r d | d	 <qW |  j  j   d
 k  r d | d	 <qW d | d	 <qW W|  j   d  S(   NR   R   R   R   R.   R/   i   i   R   i   i   i   (   R   R   R   R   (   R    t   eR   R   R.   R/   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s    



c         G   s-   |  j  d  k r d  S|  j  j   d  |  _  d  S(   N(   R   RO   R   (   R    R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s    c         O   s$   t    r d S|  j j | |   d S(   s   
        Enter the Tkinter mainloop.  This function must be called if
        this demo is created from a non-interactive program (e.g.
        from a secript); otherwise, the demo will close as soon as
        the script completes.
        N(   R   R   t   mainloop(   R    t   argst   kwargs(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s    	(   Rx   Ry   R   R   R   R   R   R   (    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR   U  s   	+		7		c          G   s   t  |    j   d S(   sd   
    Open a new window containing a graphical diagram of the given
    trees.

    :rtype: None
    N(   R   R   (   R   (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt
   draw_trees  s    c             s  d d  l      f d   }  t d d d d d d  } t j d	  } t | j   | d
 d d d0 d d1 d d d d d d d d } | j | d d  d   } d   } t j d  } t | j   | | | d d }   f d    }   f d!   }	 | j | j  | j | j  | j	 | d"  | j
 d  j |	 d"  | j
   j |	 d"  t | j   |  }
 | j |
 | j   d d d  t j d#  } t | j   | d$ d d% d d& d } d | d
 <| j | d | j   d" d  d'   } d( } t | j   | j    } t | j   | d) d d
 d } | j | | j   d d | j   d" d  t j d*  } t | j   | d
 d d+ d, d d, d d2 d d- d. d/ } | j   | j | | j   d d | j   d" d  | j |  | j | j d"  | j   d  S(3   Nic            s   d   j  d d  |  d <d  S(   Ns   #%06di    i?B R   (   t   randint(   t   cw(   t   random(    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR     s    R-   i&  t   heighti  t   closeenoughi   sU   
    (S (NP the very big cat)
       (VP (Adv sorta) (V saw) (NP (Det the) (N dog))))R   i   R   R   iR   R   it   italicR   R   R   t   blackR   t   green4R   t   blue2i
   c         S   s(   d } t  |  t |  | d | d d S(   NR   iR   t   fontR   t   green(   R   iR   (   R   R   (   R!   t   textt   big(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   boxit  s    c         S   s   t  |  t |  |  d d S(   NR   t   cyan(   R
   R   (   R!   R  (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   ovalit  s    s/   (S (NP this tree) (VP (V is) (AdjP shapeable)))R   c            s   d   j  d d  |  d <d  S(   Ns   #%04d00i    i'  R,   (   R  (   R   (   R  (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyR,     s    c            s:   d   j  d d  |  j   d <d |  j   j   d <d  S(   Ns   #%06di    i'  R   R   R,   (   R  R"   RE   (   R   (   R  (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   color2!  s     i   sb   
    (S (NP this tree) (AUX was)
       (VP (V built) (PP (P with) (NP (N tree_to_treesegment)))))t
   tree_colort   tree_xspacet
   tree_widthc         S   s1  |  d d k r |  j  d d  j   d j d  |  j d d  j   d j d  |  j d  j   d j d  |  j   j   d j d  d |  d <n |  j  d d  j   d j d  |  j d d  j   d j d  |  j d  j   d j d  |  j   j   d j d  d |  d <d  S(   NR)   R*   i   i    R+   i   (   R   R#   t   set_textR   (   t
   treewidget(    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   orientswitch9  s    ## ## sM  
Try clicking, right clicking, and dragging
different elements of each of the trees.
The top-left tree is a TreeWidget built from
a Tree.  The top-right is a TreeWidget built
from a Tree, using non-default widget
constructors for the nodes & leaves (BoxWidget
and OvalWidget).  The bottom-left tree is
built from tree_to_treesegment.R   s/   (S (NP this tree) (VP (V is) (Adj horizontal)))R   t   brown2t   brown4R)   R*   (   R   iR   (   R   iR  (   R   iR   (   R  R   R   t
   fromstringR   R!   R   R   R   R   R   R   R	   RK   R   R   t   stripR   R   R   (   R   R   R|   t   tcR  R  t   treetokt   tc2R,   R  t   parent   tree3t   tc3R  R  t   twidgett   textboxt   tree4t   tc4(    (   R  s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   demo  sn    					!!	$
!	!/		
/t   __main__N(   Rz   t   six.moves.tkinterR    R   R   t	   nltk.utilR   t	   nltk.treeR   t   nltk.draw.utilR   R   R   R   R	   R
   R   R{   R   R   t   objectR   R  R(  Rx   (    (    (    s-   lib/python2.7/site-packages/nltk/draw/tree.pyt   <module>
   s   . 	8 Y		o