
    /h                          S r SSKJrJrJr  SSKJrJrJrJ	r	J
r
Jr  SSKJr  SSKJr   " S S\5      rS r\\4S	 jr " S
 S\5      r " S S5      rS rS r\S:X  a  \" 5         gg)z
Graphically display a Tree.
    )IntVarMenuTk)	BoxWidgetCanvasFrameCanvasWidget
OvalWidgetParenWidget
TextWidget)Tree)in_idlec                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rSrg)TreeSegmentWidget   aK  
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                 ~   X l         X0l        SU l        SU l        SU l        SU l        SU l        U Vs/ s H  oQR                  SSSSSS9PM     snU l        UR                  SSSSSS	9U l
        U R                  U5        U H  nU R                  U5        M     SU l        [        R                  " X40 UD6  g
s  snf )z1
:type node:
:type subtrees: list(CanvasWidgetI)
r   
      F#006060fill hidden)r   stateoutlineN)_label	_subtrees_horizontal_roof_xspace_yspace_orderedcreate_line_linescreate_polygon_polygon_add_child_widget	_managingr   __init__)selfcanvaslabelsubtreesattribscsubtrees          F/var/www/auris/envauris/lib/python3.13/site-packages/nltk/draw/tree.pyr(   TreeSegmentWidget.__init__@   s    
 ! 
 PXXx!))!Q19)ExX--qr9 . 

 	u%G""7+   d6g6 Ys   B:c                 \   U R                  5       nUS:X  a  X l        U R                  (       a>  U R                   H  nUR                  USS9  M     UR                  U R                  SS9  g U R                   H  nUR                  USS9  M     UR                  U R                  SS9  g US:X  a'  US:X  a  SU l        g US:X  a  S	U l        g [        S
5      eUS:X  a=  U R                   H  nUR                  XBS9  M     UR                  U R                  US9  g [        U[        5      (       a4  US	   S:X  a+  U R                  [        US   5         nUR                  XBS9  g US:X  a  UR                  U R                  US9  g US:X  aD  UR                  U R                  X05        U R                   H  nUR                  XAU05        M     g US;   a5  US:X  a  X l
        OUS:X  a  X l        U R                  U R                  5        g US:X  a  X l        g [        R                   " XU5        g )Nroofr   )r   normalorientation
horizontal   verticalr   z*orientation must be horizontal or verticalcolorr   )r   r   width)xspaceyspacer;   r<   ordered)r*   r   r#   
itemconfigr%   r   
ValueError
isinstancetupleintr   r    updater   r!   r   __setitem__)r)   attrvaluer*   ls        r0   rD   TreeSegmentWidget.__setitem___   s   6>JzzA%%ax%8 %!!$--x!@A%%ax%8 %!!$--x!@]"$#$ *$#$  !MNNW_[[!!!!0 !dmmU;e$$aG);CQL)Aa,V^dmm%8W_dmmd];[[!!!E]3 !))x$!$KK$Y!M$$T7    c                 b   US:X  a  U R                   $ US:X  a*  U R                  5       R                  U R                  U5      $ US:X  a*  U R                  5       R                  U R                  S5      $ [	        U[
        5      (       aD  US   S:X  a;  U R                  [        US   5         nU R                  5       R                  US5      $ US:X  a  U R                  $ US	:X  a  U R                  $ US
:X  a  U R                  (       a  ggUS:X  a  U R                  $ [        R                  " X5      $ )Nr3   r:   r9   r   r   r7   r   r;   r<   r5   r6   r8   r=   )r   r*   itemcgetr%   r@   rA   r#   rB   r   r    r   r!   r   __getitem__)r)   rE   rG   s      r0   rL   TreeSegmentWidget.__getitem__   s    6>::W_;;=))$-->>W_;;=))$--CCe$$aG);CQL)A;;=))!V44X<<X<<]"#!Y== ++D77rI   c                     U R                   $ N)r   r)   s    r0   r+   TreeSegmentWidget.label   s    {{rI   c                      U R                   S S  $ rO   )r   rP   s    r0   r,   TreeSegmentWidget.subtrees   s    ~~a  rI   c                     U R                  U R                  5        U R                  U5        Xl        U R                  U R                  5        g)z"
Set the node label to ``label``.
N)_remove_child_widgetr   r&   rC   )r)   r+   s     r0   	set_labelTreeSegmentWidget.set_label   s9     	!!$++.u%DKK rI   c                     U R                   R                  U5      nX R                   U'   U R                  U5        U R                  U5        U R	                  U5        g)z3
Replace the child ``oldchild`` with ``newchild``.
N)r   indexrU   r&   rC   )r)   oldchildnewchildrY   s       r0   replace_childTreeSegmentWidget.replace_child   sL     $$X. (u!!(+x(HrI   c                    U R                   R                  U5      nU R                   U	 U R                  U5        U R                  5       R	                  U R
                  R                  5       5        U R                  U R                  5        g rO   )	r   rY   rU   r*   deleter#   poprC   r   )r)   childrY   s      r0   remove_childTreeSegmentWidget.remove_child   s_    $$U+NN5!!!%(T[[__./DKK rI   c           
      
   U R                  5       nU R                  R                  X5        U R                  U5        U R                  R                  UR                  SSSSSS95        U R                  U R                  5        g )Nr   r   r   )	r*   r   insertr&   r#   appendr"   rC   r   )r)   rY   ra   r*   s       r0   insert_childTreeSegmentWidget.insert_child   se    e+u%6--aAqy-IJDKK rI   c                 V    U R                   (       a  U R                  /$ U R                  $ rO   )r   r%   r#   rP   s    r0   _tagsTreeSegmentWidget._tags   s    ::MM?";;rI   c                     [        U[        5      (       a  UR                  5       R                  5       nOUR                  5       nU R                  (       a  US   US   US   -   S-  4$ US   US   -   S-  US   4$ )Nr   r7             @   )r@   r   r+   bboxr   )r)   ra   rp   s      r0   _subtree_topTreeSegmentWidget._subtree_top   sz    e.//;;=%%'D::<DGd1gQ/3677!WtAw&#-tAw77rI   c                     U R                   R                  5       nU R                  (       a  US   US   US   -   S-  4$ US   US   -   S-  US   4$ )Nro   r7   rm   rn   r   )r   rp   r   )r)   rp   s     r0   _node_bottomTreeSegmentWidget._node_bottom   s_    {{!Gd1gQ/3677!WtAw&#-tAw77rI   c                    [        U R                  5      S:X  a  g U R                  R                  5       c  g XR                  L a  U R                  nOU/nU R                  (       a"  U R
                  (       d  U R                  U5      nU R                  5       u  p4U R                  S   R                  5       u  pVpxU R                  SS   HK  n	U	R                  5       n
[        XZS   5      n[        XjS   5      n[        XzS   5      n[        XS   5      nMM     U R                  (       a.  U R                  5       R                  U R                  X4XVXXX45	        O-U R                  5       R                  U R                  X4XVXvX45	        U Hq  n	U R                  5       u  p4U R                  U R                  R                  U	5         nU R!                  U	5      u  pU R                  5       R                  XXLU5        Ms     g )Nr   r7   ro   rm   )lenr   r   rp   r!   r'   _maintain_orderrt   minmaxr   r*   coordsr%   r#   rY   rq   )r)   ra   need_updatenodexnodeyxminyminxmaxymaxr/   rp   linesubtreexsubtreeys                 r0   _updateTreeSegmentWidget._update   s   t~~!#;;% KK..K 'K==..u5K **,#'>>!#4#9#9#; T~~ab)G<<>Dt!W%Dt!W%Dt!W%Dt!W%D * KKM  uTU KKM  uTU
 #G!..0NU;;t~~33G<=D#'#4#4W#= XKKM  exH	 #rI   c                 h    U R                   (       a  U R                  U5      $ U R                  U5      $ rO   )r   _maintain_order_horizontal_maintain_order_vertical)r)   ra   s     r0   rx   !TreeSegmentWidget._maintain_order  s-    225990077rI   c                    UR                  5       u  p#pEXR                  L ag  U R                   HK  nUR                  5       u  pxpXPR                  -   U:  d  M*  UR	                  SXPR                  -   U-
  5        MM     U R                  $ U/nU R                  R                  U5      nX@R                  -   n[        US-   [        U R                  5      5       H}  nU R                  U   R                  5       u  pxpX:  d  M*  U R                  U   R	                  X-
  S5        XU-
  U R                  -   -  nUR                  U R                  U   5        M     X R                  -
  n[        US-
  SS5       H}  nU R                  U   R                  5       u  pxpX:  d  M*  U R                  U   R	                  X-
  S5        XU-
  U R                  -   -  nUR                  U R                  U   5        M     U R                  R                  5       u  pxpXU R                  -
  :  a7  U R                  R	                  SX0R                  -
  U
-
  5        U R                  nU$ )Nr   r7   )
rp   r   r   r    moverY   r   rangerw   rf   )r)   ra   lefttoprightbotr/   x1y1x2y2movedrY   xis                  r0   r   *TreeSegmentWidget._maintain_order_vertical  s   "'**,EKK>>#*<<> %*LLC,,$6$;< *
 >>!GENN((/E $A519c$..&9:#'>>!#4#9#9#; 6NN1%**1615b4<<//ALL!23 ; ||#A519b"-#'>>!#4#9#9#; 6NN1%**1615b4<<//ALL!23 .  ${{//1RR$,,&&  C,,$6$;< rI   c                    UR                  5       u  p#pEXR                  L af  U R                   HJ  nUR                  5       u  pxpX@R                  -   U:  d  M*  UR	                  X@R                  -   U-
  5        ML     U R                  $ U/nU R                  R                  U5      nXPR                  -   n[        US-   [        U R                  5      5       H}  nU R                  U   R                  5       u  pxpX:  d  M*  U R                  U   R	                  SX-
  5        XU-
  U R                  -   -  nUR                  U R                  U   5        M     X0R                  -
  n[        US-
  SS5       H}  nU R                  U   R                  5       u  pxpX:  d  M*  U R                  U   R	                  SX-
  5        XU-
  U R                  -   -  nUR                  U R                  U   5        M     U R                  R                  5       u  pxpXU R                  -
  :  a7  U R                  R	                  X R                  -
  U	-
  S5        U R                  nU$ )Nr7   r   r   )
rp   r   r   r   r   rY   r    r   rw   rf   )r)   ra   r   r   r   r   r/   r   r   r   r   r   rY   yr   s                  r0   r   ,TreeSegmentWidget._maintain_order_horizontal<  s   "'**,EKK>>#*<<> <<'",LL!5!:; *
 >>!GENN((/E ll"A519c$..&9:#'>>!#4#9#9#; 6NN1%**1af5b4<<//ALL!23 ; ll"A519b"-#'>>!#4#9#9#; 6NN1%**1af5b4<<//ALL!23 .  ${{//1RR4<<''  !4r!91= rI   c                    U R                  5       u  pSnU R                   HY  nUR                  5       nXS   -
  U R                  -   nX5S   -
  nUR	                  Xg5        X5S   US   -
  U R
                  -   -  nM[     SnU R                   H  nXR                  U5      S   -  nM     U[        U R                  5      -  nU R                   H  nUR	                  SX(-
  5        M     g )N   r   r7   rm           )rt   r   rp   r   r   r    rq   rw   )	r)   r}   r~   r   r/   subtree_bboxdxdycenters	            r0   _manage_horizontal$TreeSegmentWidget._manage_horizontalf  s    **, ~~G"<<>La(4<<7B!_$BLL a<?2T\\AAA & ~~G''033F &#dnn%% ~~GLLEN+ &rI   c                    U R                  5       u  pSnU R                   HY  nUR                  5       nX%S   -
  U R                  -   nX5S   -
  nUR	                  Xv5        X5S   US   -
  U R
                  -   -  nM[     SnU R                   H/  nXR                  U5      S   [        U R                  5      -  -  nM1     U R                   H  nUR	                  X-
  S5        M     g )Nr   r7   ro   r   )rt   r   rp   r    r   r   rq   rw   )	r)   r}   r~   r   r/   r   r   r   r   s	            r0   _manage_vertical"TreeSegmentWidget._manage_vertical|  s    **, ~~G"<<>La(4<<7B!_$BLL a<?2T\\AAA & ~~G''03c$..6IIIF & ~~GLL+ &rI   c                 $   SU l         U R                  5       u  p[        U R                  5      S:X  a  g U R                  (       a  U R                  5         OU R                  5         U R                   H  nU R                  U5        M     SU l         g )NTr   F)r'   rt   rw   r   r   r   r   r   )r)   r}   r~   r/   s       r0   _manageTreeSegmentWidget._manage  ss    **,t~~!###%!!# ~~GLL! & rI   c                 <    SU R                    SU R                   S3$ )Nz	[TreeSeg z: ])r   r   rP   s    r0   __repr__TreeSegmentWidget.__repr__  s     4;;-r$..)9;;rI   )
r   r   r#   r'   r!   r%   r   r   r   r    N)__name__
__module____qualname____firstlineno____doc__r(   rD   rL   r+   r,   rV   r\   rb   rg   rj   rq   rt   r   rx   r   r   r   r   r   r   __static_attributes__ rI   r0   r   r      sq    B7>*8X80!!!!88'IR8(T(T,,,*"<rI   r   c                     [        U[        5      (       aF  U" XR                  5       40 UD6nU V	s/ s H  n	[        U U	UUUUUU5      PM     n
n	[	        XU
40 UD6$ U" X40 UD6$ s  sn	f rO   )r@   r   r+   _tree_to_treesegr   )r*   t	make_node	make_leaftree_attribsnode_attribsleaf_attribsloc_attribsr+   ra   r,   s              r0   r   r     s     !T&'')<|< 
  	  	 
 !ILII3l33
s   A%c           
      "   0 n0 n0 n0 n[        UR                  5       5       HY  u  pU	SS S:X  a	  XU	SS '   M  U	SS S:X  a	  XU	SS '   M)  U	SS S:X  a	  XU	SS '   M;  U	SS S:X  a	  XU	SS '   MM  [        SU	-  5      e   [        U UUUUUUU5      $ )	a  
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).
N   tree_node_leaf_   loc_zBad attribute: %s)listitemsr?   r   )r*   r   r   r   r-   r   r   r   r   keyrF   s              r0   tree_to_treesegmentr     s    0 LLLK7==?+
r7g$)QR!!W$)QR!!W$)QR!!W#(AB 03677 , 		 	rI   c                       \ rS rSrSr\\4S jrS rS rSS jr	SS jr
SS jrSS	 jrSS
 jrSS jrS rS rS rS rS rS rS rSrg)
TreeWidgeti  a   
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                    X0l         X@l        X l        0 U l        0 U l        SS0U l        SU l        SU l        SU l        SU l	        SU l
        SU l        SU l        SU l        SU l        0 U l        0 U l        0 U l        / U l        / U l        U R)                  XS	5        U R+                  XS	5      U l        U R/                  U R,                  5        [0        R2                  " X40 UD6  g )
Nr9   z#008000z#008080r7   z#c0c0c0Fr   r8   r   )
_make_node
_make_leaf_tree_nodeattribs_leafattribs_locattribs_line_color_line_width_roof_color
_roof_fill
_shapeabler   r    _orientationr!   _keys_expanded_trees_collapsed_trees_nodes_leaves_make_collapsed_trees_make_expanded_tree_treesegr&   r   r(   )r)   r*   r   r   r   r-   s         r0   r(   TreeWidget.__init__&  s     $#
 #Y/$$#& 
! """6b100B?t}}-d6g6rI   c                      U R                   U   $ a  
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)   path_to_trees     r0   expanded_treeTreeWidget.expanded_treeI  s     ##L11rI   c                      U R                   U   $ r   )r   r   s     r0   collapsed_treeTreeWidget.collapsed_treeT  s     $$\22rI   c                     [        U R                  R                  5       5       H  nUR                  X5        M     [        U R                  R                  5       5       H  nUR                  X5        M     gz%
Add a binding to all tree segments.
N)r   r   values
bind_clickr   r)   callbackbuttontsegs       r0   bind_click_treesTreeWidget.bind_click_trees_  sX     --4467DOOH- 8..5578DOOH- 9rI   c                     [        U R                  R                  5       5       H  nUR                  X5        M     [        U R                  R                  5       5       H  nUR                  X5        M     gr   )r   r   r   	bind_dragr   r   s       r0   bind_drag_treesTreeWidget.bind_drag_treesh  sX     --4467DNN8, 8..5578DNN8, 9rI   c                     U R                    H  nUR                  X5        M     U R                    H  nUR                  X5        M     gz
Add a binding to all leaves.
N)r   r   r)   r   r   leafs       r0   bind_click_leavesTreeWidget.bind_click_leavesq  s8     LLDOOH- !LLDOOH- !rI   c                     U R                    H  nUR                  X5        M     U R                    H  nUR                  X5        M     gr   )r   r   r   s       r0   bind_drag_leavesTreeWidget.bind_drag_leavesz  s8     LLDNN8, !LLDNN8, !rI   c                     U R                    H  nUR                  X5        M     U R                    H  nUR                  X5        M     gz
Add a binding to all nodes.
N)r   r   r)   r   r   nodes       r0   bind_click_nodesTreeWidget.bind_click_nodes  s8     KKDOOH-  KKDOOH-  rI   c                     U R                    H  nUR                  X5        M     U R                    H  nUR                  X5        M     gr  )r   r   r  s       r0   bind_drag_nodesTreeWidget.bind_drag_nodes  s8     KKDNN8,  KKDNN8,  rI   c           
         [        U[        5      (       d  g U R                  nU R                  nU" XR	                  5       40 U R
                  D6nU R                  R                  U5        UR                  5        Vs/ s H  ou" X40 U R                  D6PM     nnU =R                  U-  sl
        [        UUUSU R                  U R                  U R                  S9n	XR                  U'   X0R                   U	'   U	R#                  5         [%        ['        U5      5       H  n
X*   nU R)                  XX:4-   5        M     g s  snf )Nr7   )r3   r9   r   r:   )r@   r   r   r   r+   r   r   rf   leavesr   r   r   r   r   r   r   r   hider   rw   r   )r)   r*   r   r   r   r   r  rG   r  treesegr   ra   s               r0   r    TreeWidget._make_collapsed_trees  s   !T""OO	OO	@d.?.?@4 EFXXZPZ)F;):):;ZP#""""
 &-c"!

7 s1vADE&&vcDjA % Qs   =D>c           	      0   U R                   nU R                  n[        U[        5      (       a  U" XR	                  5       40 U R
                  D6nU R                  R                  U5        Un[        [        U5      5       Vs/ s H  nU R                  XU   X84-   5      PM     n	n[        XXR                  U R                  S9n
XR                  U'   X0R                  U
'   U
$ U" X40 U R                   D6nU R"                  R                  U5        U$ s  snf )N)r9   r:   )r   r   r@   r   r+   r   r   rf   r   rw   r   r   r   r   r   r   r   r   )r)   r*   r   r   r   r   r  childrenr   r,   r  r   s               r0   r   TreeWidget._make_expanded_tree  s   OO	OO	aVWWYD$2C2CDDKKt$H s8}--A ((!cDjI-   (h.>.>dFVFVG )0  %"%JJwNV<$*;*;<DLL%Ks   "Dc                    US S S:X  a  U R                    H
  nX#USS  '   M     g US S S:X  a  U R                   H
  nX$USS  '   M     g US:X  a5  X l        [        U R                  R                  5       5       H  nX%S'   M	     g US:X  ac  X l        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     g US:X  a5  X l        [        U R                  R                  5       5       H  nX%S'   M	     g US	:X  a5  X l	        [        U R                  R                  5       5       H  nX%S
'   M	     g US:X  az  X l
        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     U R                   H  nX$S'   M	     g US:X  as  X l        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     U R                  5         g US:X  as  X l        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     U R                  5         g US:X  as  X l        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     U R                  5         g US:X  ac  X l        [        U R                  R                  5       5       H  nX%S'   M	     [        U R                  R                  5       5       H  nX%S'   M	     g [         R"                  " XU5        g )Nr   r   r   
line_colorr9   
line_widthr:   
roof_color	roof_fillr   	shapeable	draggabler;   r<   r5   r=   )r   r   r   r   r   r   r   r   r   r   r   r   manager    r   r!   r   rD   )r)   rE   rF   r  r   r   s         r0   rD   TreeWidget.__setitem__  s?   8w!&T!"X $"1X !&T!"X %\!$T1188:; %W <\!$T1188:; %W <T2299;< %W =\!$T2299;< %W =[ #OT2299;<$V =[ #OT1188:;$)[! <T2299;<$)[! =$)[! %X LT1188:;!&X <T2299;<!&X =KKMX LT1188:;!&X <T2299;<!&X =KKM]" %T1188:;&+]# <T2299;<&+]# =KKMY!MT1188:;"'Y <T2299;<"'Y = $$T7rI   c                 >   US S S:X  a  U R                   R                  USS  S 5      $ US S S:X  a  U R                  R                  USS  S 5      $ US S S:X  a  U R                  R                  USS  S 5      $ US:X  a  U R                  $ US:X  a  U R
                  $ US:X  a  U R                  $ US	:X  a  U R                  $ US
:X  a  U R                  $ US:X  a  U R                  $ US:X  a  U R                  $ US:X  a  U R                  $ [        R                  " X5      $ )Nr   r   r   r   r   r  r  r  r  r  r;   r<   r5   )r   getr   r   r   r   r   r   r   r   r    r   r   rL   )r)   rE   s     r0   rL   TreeWidget.__getitem__	  s2   8w$$((ab488"1X $$((ab488"1X##''QR$77\!###\!###\!###[ ??"[ ??"X<<X<<]"$$$++D77rI   c                     / $ rO   r   rP   s    r0   rj   TreeWidget._tags#  s    	rI   c                 2   [        U R                  R                  5       5      [        U R                  R                  5       5      -   nU HJ  nUR	                  5       (       d  M  UR                  5         UR                  5         UR                  5         ML     g rO   )r   r   r   r   r   showr  r  )r)   segsr   s      r0   r   TreeWidget._manage&  sk    D((//12T!!((*6
 
 D{{}}					 rI   c                 z   UnUS   (       a  U R                   U R                  U      nOU R                  U R                  U      nUR                  5       U L a)  U R	                  U5        U R                  U5        X0l        OUR                  5       R                  X#5        UR                  5         UR                  5       R                  5       SS u  pEUR                  5       R                  5       SS u  pgUR                  Xd-
  Xu-
  5        UR                  5         UR                  5       R                  U5        g)z
Collapse/expand a tree.
r3   Nro   )r   r   r   parentrU   r&   r   r\   r%  r+   rp   r   r  rC   )r)   r  old_treesegnew_treesegnewxnewyoldxoldys           r0   toggle_collapsedTreeWidget.toggle_collapsed0  s    v..tzz+/FGK//

;0GHK 4'%%k2"";/'M ..{H 	"((*//1"15"((*//1"15dk2 	 	##K0rI   )r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   r   r   r   r    N)r7   )r   r   r   r   r   r   r(   r   r   r   r   r   r  r	  r  r   r   rD   rL   rj   r   r0  r   r   rI   r0   r   r     sb    &R $.!7F	2	3.-.-.-B<.=8~841rI   r   c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
TreeViewiU  c                 Z   SSK JnJn  Xl        [	        5       U l        U R
                  R                  S5        U R
                  R                  SU R                  5        U R
                  R                  SU R                  5        [        U R
                  5      =o@l
        U R
                  R                  SU R                  R                  5        [        U R
                  5      U l        U R                  R                  S5        SU R                  R                  5       * S	4nSU R                  R                  5       * 4n[!        U" U" [#        U5      5      5      5      U l        / U l        [)        [#        U5      5       Hn  n[+        UR-                  5       X   US
SSSSSUS9
nUR/                  UR0                  5        U R&                  R3                  U5        UR5                  USS5        Mp     U R7                  5         U R                  R9                  SSS9  U R;                  5         g )Nr   )ceilsqrtNLTKz<Control-x>z<Control-q>z<Control-p>   	helveticaboldz#008040z#004080z#004040whiter7   )	node_font
leaf_color
node_colorr  r  r  r  	leaf_fontboth)expandr   )mathr5  r6  _treesr   _toptitlebinddestroyr   _cframeprint_to_filer   _sizesetr   rB   rw   _width_widgetsr   r   r*   r   r0  rf   
add_widget_layoutpack_init_menubar)	r)   treesr5  r6  cfr:  helvr   widgets	            r0   r(   TreeView.__init__V  s   #D					}dll3		}dll3'		22\		}dll&@&@A DII&


rdjjnn..7djjnn../ $tCJ/01s5z"A		$$$!$F ##F$;$;<MM  (MM&!Q' #" 	0rI   c                 j   S=n=n=p4U R                   n[        [        U R                  5      5       H~  nU R                  U   nUR	                  5       S S u  pxX-  S:X  a  UnSnUR                  X'-
  X8-
  5        UR	                  5       S   S-   n[        XFR	                  5       S   S-   5      nM     g )Nr   ro   r   rm   )rL  r   rw   rM  rp   r   rz   )	r)   r   r   r   r   r:   rU  r.  r/  s	            r0   rO  TreeView._layout  s    As4==)*A]]1%F!;;=!,LTyA~KK!(+a 2%At[[]1-23D +rI   c                    [        U R                  5      n[        USS9nUR                  SSU R                  R                  SS9  UR                  SSU R
                  SS9  UR                  S	SUS
9  [        USS9nUR                  SU R                  SSU R                  S9  UR                  SU R                  SSU R                  S9  UR                  SU R                  SSU R                  S9  UR                  SU R                  SSU R                  S9  UR                  SU R                  SSU R                  S9  UR                  SSUS
9  U R                  R                  US9  g )Nr   )tearoffzPrint to PostscriptzCtrl-p)r+   	underlinecommandacceleratorExitr7   zCtrl-xFile)r+   r[  menuTinyr   )r+   variabler[  rF   r\  Smallr8  Medium   Large   Huge2   Zoom)r`  )r   rD  add_commandrH  rI  rG  add_cascadeadd_radiobuttonrJ  resizeconfig)r)   menubarfilemenuzoommenus       r0   rQ  TreeView._init_menubar  s   tyy/+'LL.. 	 	 	
 	At|| 	 	
 	&AHE+  ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	  ZZKK 	! 	
 	&AHE		g&rI   c                    SU R                   R                  5       * S4nSU R                   R                  5       * 4nU R                   R                  5       nU R                   R                  5       nU R                   Hb  nX&S'   X6S'   XFS'   XVS'   U R                   R                  5       S:  a  SUS	'   M8  U R                   R                  5       S
:  a  SUS	'   M]  SUS	'   Md     U R                  5         g )Nr9  r:  r<  r?  r;   r<   r   r7   r  r   ro   rm   )rJ  r   rM  rO  )r)   er:  rT  r;   r<   rU  s          r0   rn  TreeView.resize  s    djjnn..7djjnn../!!mmF"&;"&;%8%8zz~~"$'(|$!B&'(|$'(|$ $ 	rI   c                 b    U R                   c  g U R                   R                  5         S U l         g rO   )rD  rG  )r)   ru  s     r0   rG  TreeView.destroy  s&    99			rI   c                 \    [        5       (       a  gU R                  R                  " U0 UD6  g)z
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   rD  mainloop)r)   argskwargss      r0   rz  TreeView.mainloop  s%     99		D+F+rI   )rH  rJ  rD  rC  rM  rL  N)r   r   r   r   r(   rO  rQ  rn  rG  rz  r   r   rI   r0   r3  r3  U  s"    )V45'n$	,rI   r3  c                  0    [        U 6 R                  5         g)zT
Open a new window containing a graphical diagram of the given
trees.

:rtype: None
N)r3  rz  )rR  s    r0   
draw_treesr    s     e
rI   c                    ^ SS K mU4S jn [        SSSS9n[        R                  " S5      n[	        UR                  5       USS	S
SSSSS9	nUR                  USS5        S nS n[        R                  " S5      n[	        UR                  5       XdUSS9nU4S jnU4S jn	UR                  UR                  5        UR                  UR                  5        UR                  US5        UR                  S5      R                  U	S5        UR                  5       R                  U	S5        [        UR                  5       U5      n
UR                  XR                  5       S   S-   S5        [        R                  " S5      n[        UR                  5       USSSS9nSUS'   UR                  USUR                  5       S   S-   5        S nSn[        UR                  5       UR!                  5       5      n[#        UR                  5       USSS9nUR                  UUR                  5       S   S-   UR                  5       S   S-   5        [        R                  " S5      n[	        UR                  5       USSSS S!S"S#9nUR%                  5         UR                  UUR                  5       S   S-   UR                  5       S   S-   5        UR                  U5        UR                  UR                  S5        UR'                  5         g )$Nr   c                 6   > STR                  SS5      -  U S'   g )N#%06dr   i?B r   randint)cwrandoms    r0   r   demo.<locals>.fill  s    v~~a886
rI   i&  i  ro   )r:   heightcloseenoughzU
    (S (NP the very big cat)
       (VP (Adv sorta) (V saw) (NP (Det the) (N dog))))r7   )r9  ir:  )r9  italicr;  blackgreen4blue2)r  r<  r?  r  r  r=  r>  r   c           	      ,    Sn[        U [        XUS9SS9$ )N)r9  ir:  )fontgreenr   )r   r   )r*   textbigs      r0   boxitdemo.<locals>.boxit  s    (Fs!C'RRrI   c                 *    [        U [        X5      SS9$ )Ncyanr   )r	   r   )r*   r  s     r0   ovalitdemo.<locals>.ovalit  s    &*V":HHrI   z/(S (NP this tree) (VP (V is) (AdjP shapeable))))r  c                 6   > STR                  SS5      -  U S'   g )Nz#%04d00r   '  r9   r  )r  r  s    r0   r9   demo.<locals>.color  s    !FNN1d$;;WrI   c                    > STR                  SS5      -  U R                  5       S'   SU R                  5       R                  5       S'   g )Nr  r   r  r   r;  r9   )r  r+   ra   )r  r  s    r0   color2demo.<locals>.color2!  s<    ")FNN1d,C"C+2(rI   rm   zb
    (S (NP this tree) (AUX was)
       (VP (V built) (PP (P with) (NP (N tree_to_treesegment))))))
tree_colortree_xspace
tree_widthr  c                 @   U S   S:X  a  U R                  SS5      R                  5       S   R                  S5        U R                  SS5      R                  5       S   R                  S5        U R                  S5      R                  5       S   R                  S5        U R                  5       R                  5       S   R                  S5        SU S'   g U R                  SS5      R                  5       S   R                  S5        U R                  SS5      R                  5       S   R                  S5        U R                  S5      R                  5       S   R                  S5        U R                  5       R                  5       S   R                  S5        SU S'   g )Nr5   r6   r7   r   r8   rm   )r   r,   set_textr   )
treewidgets    r0   orientswitchdemo.<locals>.orientswitch9  s_   m$4$$Q*335a8AA*M%%a+446q9BB:N%%a(113A6??
K%%'00215>>zJ(2J}%$$Q*335a8AA,O%%a+446q9BB<P%%a(113A6??M%%'00215>>|L(4J}%rI   aM  
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   r  z/(S (NP this tree) (VP (V is) (Adj horizontal)))brown2)r9  r  r:  brown4r6   )r  r  r  r<  r>  r5   )r  r   r   
fromstringr   r*   rN  r   r0  r	  r   r   r
   rp   r   r   stripr   r  rz  )r   rS  r   tcr  r  treetoktc2r9   r  parentree3tc3r  r  twidgettextboxtree4tc4r  s                      @r0   demor    s   9 
3s	:B	;	A 

			,.

B MM"b"SI ooOPG
RYY['&A
FC<3 ++,--.q!a##FA.""61-		S)EMM%1*B/OO	EE
 
		UxQ1C CMM#r2779Q<",-5#D djjl3G		W7aHGMM'388:a=2-sxxz!}r/ABOOMNE

		, 	C JJLMM#sxxz!}r)7<<>!+<r+ABNN< --q1 KKMrI   __main__N)r   tkinterr   r   r   nltk.draw.utilr   r   r   r	   r
   r   	nltk.treer   	nltk.utilr   r   r   r   r   r3  r  r  r   r   rI   r0   <module>r     s    % $   E< E<P4> $z1rP1 P1p
Q, Q,h l^ zF rI   