Ë
    çÍ:j •  ã                   óÌ   — d Z ddlmZmZmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ  G d„ de«      Zd„ Zeefd	„Z G d
„ de«      Z G d„ d«      Zd„ Zd„ Zedk(  r e«        yy)z
Graphically display a Tree.
é    )ÚIntVarÚMenuÚTk)Ú	BoxWidgetÚCanvasFrameÚCanvasWidgetÚ
OvalWidgetÚParenWidgetÚ
TextWidget)ÚTree)Úin_idlec                   óˆ   — 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d„ Zy)ÚTreeSegmentWidgetaÃ  
    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           
      ó†  — || _         || _        d| _        d| _        d| _        d| _        d| _        |D �cg c]  }|j                  ddddd¬«      ‘Œ c}| _        |j                  ddddd¬	«      | _
        | j                  |«       |D ]  }| j                  |«       Œ d| _        t        j                  | |fi |¤Ž y
c c}w )zI
        :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          úc/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/draw/tree.pyr'   zTreeSegmentWidget.__init__@   s×   € ð
 ˆŒØ!ˆŒð ˆÔØˆŒ
ØˆŒØˆŒØˆŒð PXÖXÈ!�v×)Ñ)¨!¨Q°°1¸9Ð)ÕEÒXˆŒØ×-Ñ-Øˆq�r °9ð .ó 
ˆŒð
 	×Ñ˜uÔ%Øò 	,ˆGØ×"Ñ" 7Õ+ð	,ð ˆŒä×Ñ˜d FÑ6¨gÓ6ùò Ys   ¶B>c                 ó^  — | j                  «       }|dk(  r—|| _        | j                  rB| j                  D ]  }|j                  |d¬«       Œ |j                  | j                  d¬«       y | j                  D ]  }|j                  |d¬«       Œ |j                  | j                  d¬«       y |dk(  r%|dk(  rd| _        y |dk(  rd	| _        y t        d
«      ‚|dk(  rB| j                  D ]  }|j                  ||¬«       Œ |j                  | j                  |¬«       y t        |t        «      r7|d	   dk(  r/| j                  t        |d   «         }|j                  ||¬«       y |dk(  r|j                  | j                  |¬«       y |dk(  rD|j                  | j                  ||i«       | j                  D ]  }|j                  |||i«       Œ y |dv r5|dk(  r|| _
        n|dk(  r|| _        | j                  | j                  «       y |dk(  r|| _        y t        j                   | ||«       y )NÚroofr   )r   ÚnormalÚorientationÚ
horizontalé   Úverticalr   z*orientation must be horizontal or verticalÚcolorr   )r   r   Úwidth)ÚxspaceÚyspacer9   r:   Úordered)r)   r   r"   Ú
itemconfigr$   r   Ú
ValueErrorÚ
isinstanceÚtupleÚintr   r   Úupdater   r    r   Ú__setitem__)r(   ÚattrÚvaluer)   Úls        r/   rB   zTreeSegmentWidget.__setitem___   s  € Ø—‘“ˆØ�6Š>ØˆDŒJØ�zŠzØŸ™ò 9�AØ×%Ñ% a¨xÐ%Õ8ð9à×!Ñ! $§-¡-°xÐ!Õ@àŸ™ò 9�AØ×%Ñ% a¨xÐ%Õ8ð9à×!Ñ! $§-¡-°xÐ!Õ@Ø�]Ò"Ø˜Ò$Ø#$�Õ Ø˜*Ò$Ø#$�Õ ä Ð!MÓNÐNØ�WŠ_Ø—[‘[ò 1�Ø×!Ñ! !¨%Ð!Õ0ð1à×Ñ˜dŸm™m°UÐÕ;Ü˜œeÔ$¨¨a©°GÒ);à—‘œC  Q¡›LÑ)ˆAØ×Ñ˜a eÐÕ,Ø�VŠ^Ø×Ñ˜dŸm™m°%ÐÕ8Ø�WŠ_Ø×Ñ˜dŸm™m¨d°E¨]Ô;Ø—[‘[ò 4�Ø×!Ñ! ! d¨E ]Õ3ñ4àÐ)Ñ)Ø�xÒØ$�•Ø˜Ò!Ø$�”Ø�K‰K˜Ÿ™Õ$Ø�YÒØ!ˆD�Mä×$Ñ$ T¨4°Õ7ó    c                 ó>  — |dk(  r| j                   S |dk(  r*| j                  «       j                  | j                  |«      S |dk(  r*| j                  «       j                  | j                  d«      S t	        |t
        «      rC|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yy|dk(  r| j                  S t        j                  | |«      S )Nr1   r8   r7   r   r   r5   r   r9   r:   r3   r4   r6   r;   )r   r)   Úitemcgetr$   r>   r?   r"   r@   r   r   r   r    r   Ú__getitem__)r(   rC   rE   s      r/   rI   zTreeSegmentWidget.__getitem__‹   sÿ   € Ø�6Š>Ø—:‘:ÐØ�WŠ_Ø—;‘;“=×)Ñ)¨$¯-©-¸Ó>Ð>Ø�WŠ_Ø—;‘;“=×)Ñ)¨$¯-©-¸ÓCÐCÜ˜œeÔ$¨¨a©°GÒ);Ø—‘œC  Q¡›LÑ)ˆAØ—;‘;“=×)Ñ)¨!¨VÓ4Ð4Ø�XÒØ—<‘<ÐØ�XÒØ—<‘<ÐØ�]Ò"Ø×ÒØ#à!Ø�YÒØ—=‘=Ð ä×+Ñ+¨D°$Ó7Ð7rF   c                 ó   — | j                   S ©N)r   ©r(   s    r/   r*   zTreeSegmentWidget.label£   s   € Ø�{‰{ÐrF   c                 ó    — | j                   d d  S rK   )r   rL   s    r/   r+   zTreeSegmentWidget.subtrees¦   s   € Ø�~‰~™aÐ Ð rF   c                 ó    — | j                  | j                  «       | j                  |«       || _        | j                  | j                  «       y)z2
        Set the node label to ``label``.
        N)Ú_remove_child_widgetr   r%   rA   )r(   r*   s     r/   Ú	set_labelzTreeSegmentWidget.set_label©   s;   € ð 	×!Ñ! $§+¡+Ô.Ø×Ñ˜uÔ%ØˆŒØ�‰�D—K‘KÕ rF   c                 ó¾   — | j                   j                  |«      }|| j                   |<   | j                  |«       | j                  |«       | j	                  |«       y)zC
        Replace the child ``oldchild`` with ``newchild``.
        N)r   ÚindexrO   r%   rA   )r(   ÚoldchildÚnewchildrR   s       r/   Úreplace_childzTreeSegmentWidget.replace_child²   sN   € ð —‘×$Ñ$ XÓ.ˆØ (ˆ�‰�uÑØ×!Ñ! (Ô+Ø×Ñ˜xÔ(Ø�‰�HÕrF   c                 ó  — | j                   j                  |«      }| j                   |= | j                  |«       | j                  «       j	                  | j
                  j                  «       «       | j                  | j                  «       y rK   )	r   rR   rO   r)   Údeleter"   ÚpoprA   r   )r(   ÚchildrR   s      r/   Úremove_childzTreeSegmentWidget.remove_child¼   s_   € Ø—‘×$Ñ$ UÓ+ˆØ�N‰N˜5Ð!Ø×!Ñ! %Ô(Ø�‰‹×Ñ˜TŸ[™[Ÿ_™_Ó.Ô/Ø�‰�D—K‘KÕ rF   c           	      ó  — | j                  «       }| j                  j                  ||«       | j                  |«       | j                  j                  |j                  ddddd¬«      «       | j                  | j                  «       y )Nr   r   r   )	r)   r   Úinsertr%   r"   Úappendr!   rA   r   )r(   rR   rY   r)   s       r/   Úinsert_childzTreeSegmentWidget.insert_childÃ   sg   € Ø—‘“ˆØ�‰×Ñ˜e UÔ+Ø×Ñ˜uÔ%Ø�‰×Ñ˜6×-Ñ-¨a°°A°q¸yÐ-ÓIÔJØ�‰�D—K‘KÕ rF   c                 óL   — | j                   r| j                  gS | j                  S rK   )r   r$   r"   rL   s    r/   Ú_tagszTreeSegmentWidget._tagsÌ   s   € Ø�:Š:Ø—M‘M�?Ð"à—;‘;ÐrF   c                 óä   — t        |t        «      r|j                  «       j                  «       }n|j                  «       }| j                  r|d   |d   |d   z   dz  fS |d   |d   z   dz  |d   fS )Nr   r5   é   ç       @é   )r>   r   r*   Úbboxr   )r(   rY   re   s      r/   Ú_subtree_topzTreeSegmentWidget._subtree_topÒ   sw   € Ü�eÔ.Ô/Ø—;‘;“=×%Ñ%Ó'‰Dà—:‘:“<ˆDØ×ÒØ˜‘G˜d 1™g¨¨Q©Ñ/°3Ñ6Ð7Ð7à˜!‘W˜t A™wÑ&¨#Ñ-¨t°A©wÐ7Ð7rF   c                 óš   — | j                   j                  «       }| j                  r|d   |d   |d   z   dz  fS |d   |d   z   dz  |d   fS )Nrd   r5   rb   rc   r   )r   re   r   )r(   re   s     r/   Ú_node_bottomzTreeSegmentWidget._node_bottomÜ   s_   € Ø�{‰{×ÑÓ!ˆØ×ÒØ˜‘G˜d 1™g¨¨Q©Ñ/°3Ñ6Ð7Ð7à˜!‘W˜t A™wÑ&¨#Ñ-¨t°A©wÐ7Ð7rF   c                 óô  — t        | j                  «      dk(  ry | j                  j                  «       €y || j                  u r| j                  }n|g}| j                  r| j
                  s| j                  |«      }| j                  «       \  }}| j                  d   j                  «       \  }}}}| j                  dd  D ]N  }	|	j                  «       }
t        ||
d   «      }t        ||
d   «      }t        ||
d   «      }t        ||
d   «      }ŒP | j                  r2| j                  «       j                  | j                  ||||||||«	       n1| j                  «       j                  | j                  ||||||||«	       |D ]t  }	| j                  «       \  }}| j                  | j                  j                  |	«         }| j!                  |	«      \  }}| j                  «       j                  |||||«       Œv y )Nr   r5   rd   rb   )Úlenr   r   re   r    r&   Ú_maintain_orderrh   ÚminÚmaxr   r)   Úcoordsr$   r"   rR   rf   )r(   rY   Úneed_updateÚnodexÚnodeyÚxminÚyminÚxmaxÚymaxr.   re   ÚlineÚsubtreexÚsubtreeys                 r/   Ú_updatezTreeSegmentWidget._updateã   sÖ  € Üˆt�~‰~Ó !Ò#ØØ�;‰;×ÑÓÐ%Øð �D—K‘KÑØŸ.™.‰Kà ˜'ˆKà�=Š= §¢Ø×.Ñ.¨uÓ5ˆKð ×*Ñ*Ó,‰ˆ�Ø#'§>¡>°!Ñ#4×#9Ñ#9Ó#;Ñ ˆˆt�T˜4Ø—~‘~ a bÐ)ò 	&ˆGØ—<‘<“>ˆDÜ�t˜T !™WÓ%ˆDÜ�t˜T !™WÓ%ˆDÜ�t˜T !™WÓ%ˆDÜ�t˜T !™WÓ%‰Dð	&ð ×ÒØ�K‰K‹M× Ñ Ø—‘˜u e¨T°4¸¸tÀUÈEõð �K‰K‹M× Ñ Ø—‘˜u e¨T°4¸¸tÀUÈEôð
 #ò 	IˆGØ!×.Ñ.Ó0‰NˆU�EØ—;‘;˜tŸ~™~×3Ñ3°GÓ<Ñ=ˆDØ#'×#4Ñ#4°WÓ#=Ñ ˆX�xØ�K‰K‹M× Ñ   u¨e°X¸xÕHñ		IrF   c                 ó^   — | j                   r| j                  |«      S | j                  |«      S rK   )r   Ú_maintain_order_horizontalÚ_maintain_order_vertical)r(   rY   s     r/   rk   z!TreeSegmentWidget._maintain_order  s-   € Ø×ÒØ×2Ñ2°5Ó9Ð9à×0Ñ0°Ó7Ð7rF   c                 óÐ  — |j                  «       \  }}}}|| j                  u rg| j                  D ]L  }|j                  «       \  }}}	}
|| j                  z   |kD  sŒ+|j	                  d|| j                  z   |z
  «       ŒN | j                  S |g}| j                  j                  |«      }|| j                  z   }t        |dz   t        | j                  «      «      D ]  }| j                  |   j                  «       \  }}}	}
||kD  sŒ+| j                  |   j	                  ||z
  d«       ||	|z
  | j                  z   z  }|j                  | j                  |   «       Œ� || j                  z
  }t        |dz
  dd«      D ]  }| j                  |   j                  «       \  }}}	}
||	k  sŒ+| j                  |   j	                  ||	z
  d«       ||	|z
  | j                  z   z  }|j                  | j                  |   «       Œ� | j                  j                  «       \  }}}	}
|
|| j                  z
  kD  r8| j                  j	                  d|| j                  z
  |
z
  «       | j                  }|S )Nr   r5   éÿÿÿÿ)
re   r   r   r   ÚmoverR   r   Úrangerj   r]   )r(   rY   ÚleftÚtopÚrightÚbotr.   Úx1Úy1Úx2Úy2ÚmovedrR   ÚxÚis                  r/   r|   z*TreeSegmentWidget._maintain_order_vertical  s<  € Ø"'§*¡*£,Ñˆˆs�E˜3à�D—K‘KÑàŸ>™>ò =�Ø#*§<¡<£>Ñ ��R˜˜RØ˜Ÿ™Ñ%¨Ó*Ø—L‘L  C¨$¯,©,Ñ$6¸Ñ$;Õ<ð=ð
 —>‘>Ð!à�GˆEØ—N‘N×(Ñ(¨Ó/ˆEð ˜Ÿ™Ñ$ˆAÜ˜5 1™9¤c¨$¯.©.Ó&9Ó:ò 4�Ø#'§>¡>°!Ñ#4×#9Ñ#9Ó#;Ñ ��R˜˜RØ�r“6Ø—N‘N 1Ñ%×*Ñ*¨1¨r©6°1Ô5Ø˜˜b™ 4§<¡<Ñ/Ñ/�AØ—L‘L §¡°Ñ!2Õ3ð4ð �t—|‘|Ñ#ˆAÜ˜5 1™9 b¨"Ó-ò 4�Ø#'§>¡>°!Ñ#4×#9Ñ#9Ó#;Ñ ��R˜˜RØ�r“6Ø—N‘N 1Ñ%×*Ñ*¨1¨r©6°1Ô5Ø˜˜b™ 4§<¡<Ñ/Ñ/�AØ—L‘L §¡°Ñ!2Õ3ð4ð  $Ÿ{™{×/Ñ/Ó1ÑˆR��R˜Ø�C˜$Ÿ,™,Ñ&Ò&Ø—‘× Ñ   C¨$¯,©,Ñ$6¸Ñ$;Ô<ØŸ™�ð ˆrF   c                 óÎ  — |j                  «       \  }}}}|| j                  u rf| j                  D ]K  }|j                  «       \  }}}	}
|| j                  z   |kD  sŒ+|j	                  || j                  z   |z
  «       ŒM | j                  S |g}| j                  j                  |«      }|| j                  z   }t        |dz   t        | j                  «      «      D ]  }| j                  |   j                  «       \  }}}	}
||kD  sŒ+| j                  |   j	                  d||z
  «       ||
|z
  | j                  z   z  }|j                  | j                  |   «       Œ� || j                  z
  }t        |dz
  dd«      D ]  }| j                  |   j                  «       \  }}}	}
||
k  sŒ+| j                  |   j	                  d||
z
  «       ||
|z
  | j                  z   z  }|j                  | j                  |   «       Œ� | j                  j                  «       \  }}}	}
|	|| j                  z
  kD  r8| j                  j	                  || j                  z
  |	z
  d«       | j                  }|S )Nr5   r   r~   )
re   r   r   r   r   rR   r   r€   rj   r]   )r(   rY   r�   r‚   rƒ   r„   r.   r…   r†   r‡   rˆ   r‰   rR   Úyr‹   s                  r/   r{   z,TreeSegmentWidget._maintain_order_horizontal<  s:  € Ø"'§*¡*£,Ñˆˆs�E˜3à�D—K‘KÑàŸ>™>ò <�Ø#*§<¡<£>Ñ ��R˜˜RØ˜4Ÿ<™<Ñ'¨"Ó,Ø—L‘L ¨¯©Ñ!5¸Ñ!:Õ;ð<ð
 —>‘>Ð!à�GˆEØ—N‘N×(Ñ(¨Ó/ˆEð �d—l‘lÑ"ˆAÜ˜5 1™9¤c¨$¯.©.Ó&9Ó:ò 4�Ø#'§>¡>°!Ñ#4×#9Ñ#9Ó#;Ñ ��R˜˜RØ�r“6Ø—N‘N 1Ñ%×*Ñ*¨1¨a°"©fÔ5Ø˜˜b™ 4§<¡<Ñ/Ñ/�AØ—L‘L §¡°Ñ!2Õ3ð4ð �d—l‘lÑ"ˆAÜ˜5 1™9 b¨"Ó-ò 4�Ø#'§>¡>°!Ñ#4×#9Ñ#9Ó#;Ñ ��R˜˜RØ�r“6Ø—N‘N 1Ñ%×*Ñ*¨1¨a°"©fÔ5Ø˜˜b™ 4§<¡<Ñ/Ñ/�AØ—L‘L §¡°Ñ!2Õ3ð4ð  $Ÿ{™{×/Ñ/Ó1ÑˆR��R˜Ø�D˜4Ÿ<™<Ñ'Ò'Ø—‘× Ñ  ¨¯©Ñ!4°rÑ!9¸1Ô=ØŸ™�ð ˆrF   c                 óÔ  — | j                  «       \  }}d}| j                  D ]\  }|j                  «       }||d   z
  | j                  z   }||d   z
  }|j	                  ||«       ||d   |d   z
  | j
                  z   z  }Œ^ d}| j                  D ]  }|| j                  |«      d   z  }Œ |t        | j                  «      z  }| j                  D ]  }|j	                  d||z
  «       Œ y )Né   r   r5   rb   ç        )rh   r   re   r   r   r   rf   rj   )	r(   rp   rq   r�   r.   Úsubtree_bboxÚdxÚdyÚcenters	            r/   Ú_manage_horizontalz$TreeSegmentWidget._manage_horizontalf  sü   € Ø×*Ñ*Ó,‰ˆ�ð ˆØ—~‘~ò 	BˆGØ"Ÿ<™<›>ˆLØ˜ a™Ñ(¨4¯<©<Ñ7ˆBØ�\ !‘_Ñ$ˆBØ�L‰L˜˜RÔ Ø�˜a‘ <°¡?Ñ2°T·\±\ÑAÑA‰Að	Bð ˆØ—~‘~ò 	4ˆGØ�d×'Ñ'¨Ó0°Ñ3Ñ3‰Fð	4à”#�d—n‘nÓ%Ñ%ˆð —~‘~ò 	,ˆGØ�L‰L˜˜E F™NÕ+ñ	,rF   c                 óÐ  — | j                  «       \  }}d}| j                  D ]\  }|j                  «       }||d   z
  | j                  z   }||d   z
  }|j	                  ||«       ||d   |d   z
  | j
                  z   z  }Œ^ d}| j                  D ]/  }|| j                  |«      d   t        | j                  «      z  z  }Œ1 | j                  D ]  }|j	                  ||z
  d«       Œ y )Nr   r5   rd   r�   )rh   r   re   r   r   r   rf   rj   )	r(   rp   rq   rŠ   r.   r‘   r“   r’   r”   s	            r/   Ú_manage_verticalz"TreeSegmentWidget._manage_vertical|  sù   € Ø×*Ñ*Ó,‰ˆ�ð ˆØ—~‘~ò 	BˆGØ"Ÿ<™<›>ˆLØ˜ a™Ñ(¨4¯<©<Ñ7ˆBØ�\ !‘_Ñ$ˆBØ�L‰L˜˜RÔ Ø�˜a‘ <°¡?Ñ2°T·\±\ÑAÑA‰Að	Bð ˆØ—~‘~ò 	JˆGØ�d×'Ñ'¨Ó0°Ñ3´c¸$¿.¹.Ó6IÑIÑI‰Fð	Jð —~‘~ò 	,ˆGØ�L‰L˜ ™¨Õ+ñ	,rF   c                 ó  — d| _         | j                  «       \  }}t        | j                  «      dk(  ry | j                  r| j                  «        n| j                  «        | j                  D ]  }| j                  |«       Œ d| _         y )NTr   F)r&   rh   rj   r   r   r•   r—   ry   )r(   rp   rq   r.   s       r/   Ú_managezTreeSegmentWidget._manage‘  sz   € ØˆŒØ×*Ñ*Ó,‰ˆ�Üˆt�~‰~Ó !Ò#Øà×ÒØ×#Ñ#Õ%à×!Ñ!Ô#ð —~‘~ò 	"ˆGØ�L‰L˜Õ!ð	"ð ˆ�rF   c                 ó<   — d| j                   › d| j                  › d�S )Nz	[TreeSeg z: ú])r   r   rL   s    r/   Ú__repr__zTreeSegmentWidget.__repr__¢  s    € Ø˜4Ÿ;™;˜- r¨$¯.©.Ð)9¸Ð;Ð;rF   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'   rB   rI   r*   r+   rP   rU   rZ   r^   r`   rf   rh   ry   rk   r|   r{   r•   r—   r™   rœ   © rF   r/   r   r      sq   „ ñòB7ò>*8òX8ò0ò!ò!òò!ò!òò8ò8ò'IòR8ò(òT(òT,ò,,ò*ó"<rF   r   c                 óÊ   — t        |t        «      rE || |j                  «       fi |¤Ž}|D �	cg c]  }	t        | |	||||||«      ‘Œ }
}	t	        | ||
fi |¤ŽS  || |fi |¤ŽS c c}	w rK   )r>   r   r*   Ú_tree_to_treesegr   )r)   ÚtÚ	make_nodeÚ	make_leafÚtree_attribsÚnode_attribsÚleaf_attribsÚloc_attribsr*   rY   r+   s              r/   r£   r£   ¦  s�   € ô �!”TÔÙ˜& !§'¡'£)Ñ<¨|Ñ<ˆð ö
ð ô ØØØØØØØØõ	ð
ˆð 
ô ! ¨°ÑI¸LÑIÐIá˜ Ñ3 lÑ3Ð3ùò
s   ­A c           
      ó  — i }i }i }i }t        |j                  «       «      D ]V  \  }	}
|	dd dk(  r	|
||	dd <   Œ|	dd dk(  r	|
||	dd <   Œ(|	dd dk(  r	|
||	dd <   Œ9|	dd dk(  r	|
||	dd <   ŒJt        d|	z  «      ‚ t        | |||||||«      S )	aS  
    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ª   ÚkeyrD   s              r/   Útree_to_treesegmentrµ   Ä  sæ   € ð0 €LØ€LØ€LØ€Kä˜7Ÿ=™=›?Ó+ò 
8‰
ˆˆUØˆr�ˆ7�gÒØ$)ˆL˜˜Q˜R˜Ò!Ø��!ˆW˜ÒØ$)ˆL˜˜Q˜R˜Ò!Ø��!ˆW˜ÒØ$)ˆL˜˜Q˜R˜Ò!Ø��!ˆW˜ÒØ#(ˆK˜˜A˜B˜Ò äÐ0°3Ñ6Ó7Ð7ð
8ô ØØ	ØØØØØØó	ð 	rF   c                   ó‚   — e Zd ZdZeef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y)Ú
TreeWidgeta   
    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                 óÚ  — || _         || _        || _        i | _        i | _        ddi| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        i | _        i | _        i | _        g | _        g | _        | j)                  ||d	«       | j+                  ||d	«      | _        | j/                  | j,                  «       t1        j2                  | |fi |¤Ž y )
Nr7   z#008000z#008080r5   z#c0c0c0Fr   r6   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         r/   r'   zTreeWidget.__init__&  sñ   € ð $ˆŒØ#ˆŒØˆŒ
ð ˆÔØˆÔØ# YÐ/ˆÔØ$ˆÔØˆÔØ$ˆÔØ#ˆŒØˆŒØˆŒØˆŒØ&ˆÔØˆŒð ˆŒ
Ø!ˆÔØ "ˆÔØˆŒØˆŒà×"Ñ" 6¨1¨bÔ1Ø×0Ñ0°¸¸BÓ?ˆŒØ×Ñ˜tŸ}™}Ô-ä×Ñ˜d FÑ6¨gÓ6rF   c                 ó    — | j                   |   S ©aF  
        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     r/   Úexpanded_treezTreeWidget.expanded_treeI  s   € ð ×#Ñ# LÑ1Ð1rF   c                 ó    — | j                   |   S rÎ   )rÇ   rÏ   s     r/   Úcollapsed_treezTreeWidget.collapsed_treeT  s   € ð ×$Ñ$ \Ñ2Ð2rF   c                 óì   — t        | j                  j                  «       «      D ]  }|j                  ||«       Œ t        | j                  j                  «       «      D ]  }|j                  ||«       Œ y©z5
        Add a binding to all tree segments.
        N)r²   rÆ   ÚvaluesÚ
bind_clickrÇ   ©r(   ÚcallbackÚbuttonÚtsegs       r/   Úbind_click_treeszTreeWidget.bind_click_trees_  sf   € ô ˜×-Ñ-×4Ñ4Ó6Ó7ò 	.ˆDØ�O‰O˜H fÕ-ð	.ä˜×.Ñ.×5Ñ5Ó7Ó8ò 	.ˆDØ�O‰O˜H fÕ-ñ	.rF   c                 óì   — t        | j                  j                  «       «      D ]  }|j                  ||«       Œ t        | j                  j                  «       «      D ]  }|j                  ||«       Œ yrÕ   )r²   rÆ   rÖ   Ú	bind_dragrÇ   rØ   s       r/   Úbind_drag_treeszTreeWidget.bind_drag_treesh  sf   € ô ˜×-Ñ-×4Ñ4Ó6Ó7ò 	-ˆDØ�N‰N˜8 VÕ,ð	-ä˜×.Ñ.×5Ñ5Ó7Ó8ò 	-ˆDØ�N‰N˜8 VÕ,ñ	-rF   c                 ó�   — | j                   D ]  }|j                  ||«       Œ | j                   D ]  }|j                  ||«       Œ y©z.
        Add a binding to all leaves.
        N)rÉ   r×   ©r(   rÙ   rÚ   Úleafs       r/   Úbind_click_leaveszTreeWidget.bind_click_leavesq  sF   € ð —L‘Lò 	.ˆDØ�O‰O˜H fÕ-ð	.à—L‘Lò 	.ˆDØ�O‰O˜H fÕ-ñ	.rF   c                 ó�   — | j                   D ]  }|j                  ||«       Œ | j                   D ]  }|j                  ||«       Œ yrá   )rÉ   rÞ   râ   s       r/   Úbind_drag_leaveszTreeWidget.bind_drag_leavesz  sF   € ð —L‘Lò 	-ˆDØ�N‰N˜8 VÕ,ð	-à—L‘Lò 	-ˆDØ�N‰N˜8 VÕ,ñ	-rF   c                 ó�   — | j                   D ]  }|j                  ||«       Œ | j                   D ]  }|j                  ||«       Œ y©z-
        Add a binding to all nodes.
        N)rÈ   r×   ©r(   rÙ   rÚ   Únodes       r/   Úbind_click_nodeszTreeWidget.bind_click_nodesƒ  sF   € ð —K‘Kò 	.ˆDØ�O‰O˜H fÕ-ð	.à—K‘Kò 	.ˆDØ�O‰O˜H fÕ-ñ	.rF   c                 ó�   — | j                   D ]  }|j                  ||«       Œ | j                   D ]  }|j                  ||«       Œ yrè   )rÈ   rÞ   ré   s       r/   Úbind_drag_nodeszTreeWidget.bind_drag_nodesŒ  sF   € ð —K‘Kò 	-ˆDØ�N‰N˜8 VÕ,ð	-à—K‘Kò 	-ˆDØ�N‰N˜8 VÕ,ñ	-rF   c           	      óˆ  — t        |t        «      sy | j                  }| j                  } |||j	                  «       fi | j
                  ¤Ž}| j                  j                  |«       |j                  «       D �cg c]  } |||fi | j                  ¤Ž‘Œ }}| xj                  |z  c_
        t        |||d| j                  | j                  | j                  ¬«      }	|	| j                  |<   || j                   |	<   |	j#                  «        t%        t'        |«      «      D ]  }
||
   }| j)                  ||||
fz   «       Œ  y c c}w )Nr5   )r1   r7   r   r8   )r>   r   r¹   rº   r*   r¼   rÈ   r]   Úleavesr½   rÉ   r   rÁ   rÂ   rÀ   rÇ   rÅ   Úhider€   rj   rÊ   )r(   r)   r¤   r´   r¥   r¦   rê   rE   rï   Útreesegr‹   rY   s               r/   rÊ   z TreeWidget._make_collapsed_trees•  s#  € Ü˜!œTÔ"ØØ—O‘Oˆ	Ø—O‘Oˆ	á˜ §¡£Ñ@¨d×.?Ñ.?Ñ@ˆØ�‰×Ñ˜4Ô ØEFÇXÁXÃZÖPÀ‘)˜F AÑ;¨×):Ñ):Ó;ÐPˆÐPØ�Š˜Ñ�Ü#ØØØØØ×"Ñ"Ø—‘Ø×"Ñ"ô
ˆð &-ˆ×Ñ˜cÑ"Ø!ˆ�
‰
�7Ñà�‰Œô ”s˜1“v“ò 	BˆAØ�a‘DˆEØ×&Ñ& v¨u°c¸Q¸D±jÕAñ	Bùò% Qs   Á9D?c           	      ó6  — | j                   }| j                  }t        |t        «      r¼ |||j	                  «       fi | j
                  ¤Ž}| j                  j                  |«       |}t        t        |«      «      D �cg c]  }| j                  |||   ||fz   «      ‘Œ }	}t        |||	| j                  | j                  ¬«      }
|
| j                  |<   || j                  |
<   |
S  |||fi | j                   ¤Ž}| j"                  j                  |«       |S c c}w )N)r7   r8   )r¹   rº   r>   r   r*   r¼   rÈ   r]   r€   rj   rË   r   r¿   rÀ   rÆ   rÅ   r½   rÉ   )r(   r)   r¤   r´   r¥   r¦   rê   Úchildrenr‹   r+   rñ   rã   s               r/   rË   zTreeWidget._make_expanded_tree³  s  € Ø—O‘Oˆ	Ø—O‘Oˆ	ä�aœÔÙ˜V Q§W¡W£YÑD°$×2CÑ2CÑDˆDØ�K‰K×Ñ˜tÔ$ØˆHô œs 8›}Ó-öàð ×(Ñ(¨°¸!±¸cÀQÀD¹jÕIðˆHð ô (Ø˜˜h¨d×.>Ñ.>Àd×FVÑFVôˆGð )0ˆD× Ñ  Ñ%Ø"%ˆD�J‰J�wÑØˆNá˜V QÑ<¨$×*;Ñ*;Ñ<ˆDØ�L‰L×Ñ Ô%ØˆKùòs   Á>!Dc                 óv  — |d d dk(  r| j                   D ]
  }|||dd  <   Œ y |d d dk(  r| j                  D ]
  }|||dd  <   Œ y |dk(  r5|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 y |dk(  rb|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 y |dk(  r5|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 y |d	k(  r5|| _	        t        | j                  j                  «       «      D ]  }||d
<   Œ	 y |dk(  rx|| _
        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 | j                  D ]  }||d<   Œ	 y |dk(  rr|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 | j                  «        y |dk(  rr|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 | j                  «        y |dk(  rr|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 | j                  «        y |dk(  rb|| _        t        | j                  j                  «       «      D ]  }||d<   Œ	 t        | j                  j                  «       «      D ]  }||d<   Œ	 y t!        j"                  | ||«       y )Nr¬   r®   r¯   Ú
line_colorr7   Ú
line_widthr8   Ú
roof_colorÚ	roof_fillr   Ú	shapeableÚ	draggabler9   r:   r3   r;   )rÈ   rÉ   r¿   r²   rÆ   rÖ   rÀ   rÇ   rÁ   rÂ   rÃ   r   Úmanager   rÄ   r    r   rB   )r(   rC   rD   rê   rã   rÛ   s         r/   rB   zTreeWidget.__setitem__Ê  sÑ  € Ø��ˆ8�wÒØŸ™ò '�Ø!&��T˜!˜"�X’ñ'à�"�1ˆX˜Ò ØŸ™ò '�Ø!&��T˜!˜"�X’ñ'à�\Ò!Ø$ˆDÔÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò &�Ø %��W’ñ&à�\Ò!Ø$ˆDÔÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò &�Ø %��W’ð&ä˜T×2Ñ2×9Ñ9Ó;Ó<ò &�Ø %��W’ñ&à�\Ò!Ø$ˆDÔÜ˜T×2Ñ2×9Ñ9Ó;Ó<ò &�Ø %��W’ñ&à�[Ò Ø#ˆDŒOÜ˜T×2Ñ2×9Ñ9Ó;Ó<ò %�Ø$��V’ñ%à�[Ò Ø#ˆDŒOÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò *�Ø$)��[Ò!ð*ä˜T×2Ñ2×9Ñ9Ó;Ó<ò *�Ø$)��[Ò!ð*àŸ™ò *�Ø$)��[Ò!ñ*à�XÒØ ˆDŒLÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò '�Ø!&��X’ð'ä˜T×2Ñ2×9Ñ9Ó;Ó<ò '�Ø!&��X’ð'à�K‰K�MØ�XÒØ ˆDŒLÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò '�Ø!&��X’ð'ä˜T×2Ñ2×9Ñ9Ó;Ó<ò '�Ø!&��X’ð'à�K‰K�MØ�]Ò"Ø %ˆDÔÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò ,�Ø&+��]Ò#ð,ä˜T×2Ñ2×9Ñ9Ó;Ó<ò ,�Ø&+��]Ò#ð,à�K‰K�MØ�YÒØ!ˆDŒMÜ˜T×1Ñ1×8Ñ8Ó:Ó;ò (�Ø"'��Y’ð(ä˜T×2Ñ2×9Ñ9Ó;Ó<ò (�Ø"'��Y’ñ(ô ×$Ñ$ T¨4°Õ7rF   c                 ó(  — |d d dk(  r| j                   j                  |dd  d «      S |d d dk(  r| j                  j                  |dd  d «      S |d d dk(  r| j                  j                  |d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                  S t        j                  | |«      S )Nr¬   r®   r¯   r°   r±   rõ   rö   r÷   rø   rù   r9   r:   r3   )r¼   Úgetr½   r¾   r¿   rÀ   rÁ   rÂ   rÃ   r   r   rÄ   r   rI   )r(   rC   s     r/   rI   zTreeWidget.__getitem__	  s4  € Ø��ˆ8�wÒØ×$Ñ$×(Ñ(¨¨a¨b¨°4Ó8Ð8Ø�"�1ˆX˜Ò Ø×$Ñ$×(Ñ(¨¨a¨b¨°4Ó8Ð8Ø�"�1ˆX˜ÒØ×#Ñ#×'Ñ'¨¨Q¨R¨°$Ó7Ð7Ø�\Ò!Ø×#Ñ#Ð#Ø�\Ò!Ø×#Ñ#Ð#Ø�\Ò!Ø×#Ñ#Ð#Ø�[Ò Ø—?‘?Ð"Ø�[Ò Ø—?‘?Ð"Ø�XÒØ—<‘<ÐØ�XÒØ—<‘<ÐØ�]Ò"Ø×$Ñ$Ð$ä×+Ñ+¨D°$Ó7Ð7rF   c                 ó   — g S rK   r¡   rL   s    r/   r`   zTreeWidget._tags#  s   € Øˆ	rF   c                 ó"  — t        | j                  j                  «       «      t        | j                  j                  «       «      z   }|D ]C  }|j	                  «       sŒ|j                  «        |j                  «        |j                  «        ŒE y rK   )r²   rÆ   rÖ   rÇ   r   Úshowrû   rð   )r(   ÚsegsrÛ   s      r/   r™   zTreeWidget._manage&  sn   € Ü�D×(Ñ(×/Ñ/Ó1Ó2´TØ×!Ñ!×(Ñ(Ó*ó6
ñ 
ˆð ò 	ˆDØ�{‰{�}Ø—	‘	”Ø—‘”Ø—	‘	•ñ		rF   c                 óz  — |}|d   r| j                   | j                  |      }n| j                  | j                  |      }|j                  «       | u r*| j	                  |«       | j                  |«       || _        n |j                  «       j                  ||«       |j                  «        |j                  «       j                  «       dd \  }}|j                  «       j                  «       dd \  }}|j                  ||z
  ||z
  «       |j                  «        |j                  «       j                  |«       y)z)
        Collapse/expand a tree.
        r1   Nrd   )rÆ   rÅ   rÇ   ÚparentrO   r%   rÌ   rU   r   r*   re   r   rð   rA   )r(   rñ   Úold_treesegÚnew_treesegÚnewxÚnewyÚoldxÚoldys           r/   Útoggle_collapsedzTreeWidget.toggle_collapsed0  s#  € ð ˆØ�vÒØ×.Ñ.¨t¯z©z¸+Ñ/FÑG‰Kà×/Ñ/°·
±
¸;Ñ0GÑHˆKð ×ÑÓ 4Ñ'Ø×%Ñ% kÔ2Ø×"Ñ" ;Ô/Ø'ˆD�Mà×ÑÓ ×.Ñ.¨{¸KÔHð 	×ÑÔØ"×(Ñ(Ó*×/Ñ/Ó1°"°1Ð5‰ˆˆtØ"×(Ñ(Ó*×/Ñ/Ó1°"°1Ð5‰ˆˆtØ×Ñ˜ ™ d¨T¡kÔ2ð 	×ÑÔð 	×ÑÓ×#Ñ# KÕ0rF   N)r5   )r�   rž   rŸ   r    r   r'   rÑ   rÓ   rÜ   rß   rä   ræ   rë   rí   rÊ   rË   rB   rI   r`   r™   r
  r¡   rF   r/   r·   r·   ý  sb   „ ñ&ðR $.¸ó!7òF	2ò	3ó.ó-ó.ó-ó.ó-òBò<ò.=8ò~8ò4òó1rF   r·   c                   ó0   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚTreeViewc                 óh  — ddl m}m} || _        t	        «       | _        | j
                  j                  d«       | j
                  j                  d| j                  «       | j
                  j                  d| j                  «       t        | j
                  «      x}| _
        | j
                  j                  d| j                  j                  «       t        | j
                  «      | _        | j                  j                  d«       d| j                  j                  «        d	f}d| j                  j                  «        f}t!         | |t#        |«      «      «      «      | _        g | _        t)        t#        |«      «      D ]q  }t+        |j-                  «       ||   |d
ddddd|¬«
      }|j/                  |j0                  «       | j&                  j3                  |«       |j5                  |dd«       Œs | j7                  «        | j                  j9                  dd¬«       | j;                  «        y )Nr   )ÚceilÚsqrtÚNLTKz<Control-x>z<Control-q>z<Control-p>é   Ú	helveticaÚboldz#008040z#004080z#004040Úwhiter5   )Ú	node_fontÚ
leaf_colorÚ
node_colorr÷   rø   rõ   rú   Ú	leaf_fontÚboth)Úexpandr   )Úmathr  r  Ú_treesr   Ú_topÚtitleÚbindÚdestroyr   Ú_cframeÚprint_to_filer   Ú_sizeÚsetrý   r@   rj   Ú_widthÚ_widgetsr€   r·   r)   rÜ   r
  r]   Ú
add_widgetÚ_layoutÚpackÚ_init_menubar)	r(   Útreesr  r  Úcfr  Úhelvr‹   Úwidgets	            r/   r'   zTreeView.__init__V  s©  € ß#àˆŒä“DˆŒ	Ø�	‰	�‰˜ÔØ�	‰	�‰�} d§l¡lÔ3Ø�	‰	�‰�} d§l¡lÔ3ä'¨¯	©	Ó2Ð2ˆˆTŒ\Ø�	‰	�‰�} d§l¡l×&@Ñ&@ÔAô ˜DŸI™IÓ&ˆŒ
Ø�
‰
�‰�rÔØ˜dŸj™jŸn™nÓ.Ð.°Ð7ˆØ˜dŸj™jŸn™nÓ.Ð.Ð/ˆô ™$™t¤C¨£JÓ/Ó0Ó1ˆŒØˆŒÜ”s˜5“zÓ"ò 	(ˆAÜØ—	‘	“Ø�a‘ØØ$Ø$Ø$Ø!Ø$ØØôˆFð ×#Ñ# F×$;Ñ$;Ô<Ø�M‰M× Ñ  Ô(Ø�M‰M˜& ! QÕ'ð	(ð" 	�‰ŒØ�‰×Ñ ¨ÐÔ0Ø×ÑÕrF   c                 óp  — dx}x}x}}| j                   }t        t        | j                  «      «      D ]�  }| j                  |   }|j	                  «       d d \  }}||z  dk(  r|}d}|j                  ||z
  ||z
  «       |j	                  «       d   dz   }t        ||j	                  «       d   dz   «      }Œƒ y )Nr   rd   r   rb   )r%  r€   rj   r&  re   r   rm   )	r(   r‹   rŠ   r�   ru   r8   r.  r  r	  s	            r/   r(  zTreeView._layout�  s¼   € ØÐˆÐˆAÐ��DØ—‘ˆÜ”s˜4Ÿ=™=Ó)Ó*ò 	4ˆAØ—]‘] 1Ñ%ˆFØ!Ÿ;™;›=¨¨!Ð,‰LˆT�4Ø�5‰y˜AŠ~Ø�Ø�Ø�K‰K˜˜D™ ! d¡(Ô+Ø—‘“˜aÑ  2Ñ%ˆAÜ�t˜VŸ[™[›]¨1Ñ-°Ñ2Ó3‰Dñ	4rF   c                 ó  — t        | j                  «      }t        |d¬«      }|j                  dd| j                  j                  d¬«       |j                  dd| j
                  d¬«       |j                  d	d|¬
«       t        |d¬«      }|j                  d| j                  dd| j                  ¬«       |j                  d| j                  dd| j                  ¬«       |j                  d| j                  dd| j                  ¬«       |j                  d| j                  dd| j                  ¬«       |j                  d| j                  dd| j                  ¬«       |j                  dd|¬
«       | j                  j                  |¬«       y )Nr   )ÚtearoffzPrint to PostscriptzCtrl-p)r*   Ú	underlineÚcommandÚacceleratorÚExitr5   zCtrl-xÚFile)r*   r2  ÚmenuÚTinyr   )r*   Úvariabler2  rD   r3  ÚSmallr  ÚMediumé   ÚLargeé   ÚHugeé2   ÚZoom)r7  )r   r  Úadd_commandr!  r"  r   Úadd_cascadeÚadd_radiobuttonr#  ÚresizeÚconfig)r(   ÚmenubarÚfilemenuÚzoommenus       r/   r*  zTreeView._init_menubarŽ  s�  € Ü�t—y‘y“/ˆä˜¨Ô+ˆØ×ÑØ'ØØ—L‘L×.Ñ.Ø ð	 	ô 	
ð 	×ÑØ A¨t¯|©|Èð 	ô 	
ð 	×Ñ &°A¸HÐÔEä˜¨Ô+ˆØ× Ñ ØØ—Z‘ZØØØ—K‘Kð 	!ô 	
ð 	× Ñ ØØ—Z‘ZØØØ—K‘Kð 	!ô 	
ð 	× Ñ ØØ—Z‘ZØØØ—K‘Kð 	!ô 	
ð 	× Ñ ØØ—Z‘ZØØØ—K‘Kð 	!ô 	
ð 	× Ñ ØØ—Z‘ZØØØ—K‘Kð 	!ô 	
ð 	×Ñ &°A¸HÐÔEà�	‰	×Ñ˜gÐÕ&rF   c                 óâ  — d| j                   j                  «        df}d| j                   j                  «        f}| j                   j                  «       }| j                   j                  «       }| j                  D ]a  }||d<   ||d<   ||d<   ||d<   | j                   j                  «       dk  rd|d	<   Œ:| j                   j                  «       d
k  rd|d	<   Œ]d|d	<   Œc | j                  «        y )Nr  r  r  r  r9   r:   r�   r5   rö   é   rd   rb   )r#  rý   r&  r(  )r(   Úer  r-  r9   r:   r.  s          r/   rE  zTreeView.resizeÅ  sÞ   € Ø˜dŸj™jŸn™nÓ.Ð.°Ð7ˆØ˜dŸj™jŸn™nÓ.Ð.Ð/ˆØ—‘—‘Ó!ˆØ—‘—‘Ó!ˆØ—m‘mò 
	)ˆFØ"&ˆF�;ÑØ"&ˆF�;ÑØ%ˆF�8ÑØ%ˆF�8ÑØ�z‰z�~‰~Ó "Ò$Ø'(��|Ò$Ø—‘—‘Ó! BÒ&Ø'(��|Ò$à'(��|Ò$ð
	)ð 	�‰�rF   c                 ó`   — | j                   €y | j                   j                  «        d | _         y rK   )r  r   )r(   rL  s     r/   r   zTreeView.destroy×  s&   € Ø�9‰9ÐØØ�	‰	×ÑÔØˆ�	rF   c                 óR   — t        «       ry | j                  j                  |i |¤Ž y)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   r  Úmainloop)r(   ÚargsÚkwargss      r/   rO  zTreeView.mainloopÝ  s%   € ô Œ9ØØˆ�	‰	×Ñ˜DÐ+ FÓ+rF   N)	r�   rž   rŸ   r'   r(  r*  rE  r   rO  r¡   rF   r/   r  r  U  s"   „ ò)òV4ò5'ònò$ó	,rF   r  c                  ó0   — t        | Ž j                  «        y)zd
    Open a new window containing a graphical diagram of the given
    trees.

    :rtype: None
    N)r  rO  )r+  s    r/   Ú
draw_treesrS  é  s   € ô ˆeÐ×ÑÔØ
rF   c                  ó&  ‡— dd l Šˆfd„} t        ddd¬«      }t        j                  d«      }t	        |j                  «       |dd	d
dddd¬«	      }|j                  |dd«       d„ }d„ }t        j                  d«      }t	        |j                  «       |||d¬«      }ˆfd„}ˆfd„}	|j                  |j                  «       |j                  |j                  «       |j                  |d«       |j                  d«      j                  |	d«       |j                  «       j                  |	d«       t        |j                  «       |«      }
|j                  |
|j                  «       d   dz   d«       t        j                  d«      }t        |j                  «       |ddd¬«      }d|d<   |j                  |d|j                  «       d   dz   «       d„ }d}t        |j                  «       |j!                  «       «      }t#        |j                  «       |dd¬«      }|j                  ||j                  «       d   dz   |j                  «       d   dz   «       t        j                  d«      }t	        |j                  «       |dddd d!d"¬#«      }|j%                  «        |j                  ||j                  «       d   dz   |j                  «       d   dz   «       |j                  |«       |j                  |j                  d«       |j'                  «        y )$Nr   c                 ó6   •— d‰j                  dd«      z  | d<   y )Nú#%06dr   i?B r   ©Úrandint)ÚcwÚrandoms    €r/   r   zdemo.<locals>.fillü  s   ø€ Ø˜vŸ~™~¨a°Ó8Ñ8ˆˆ6Š
rF   i&  iÂ  rd   )r8   ÚheightÚcloseenoughzU
    (S (NP the very big cat)
       (VP (Adv sorta) (V saw) (NP (Det the) (N dog))))r5   )r  iòÿÿÿr  )r  éôÿÿÿÚitalicr  ÚblackÚgreen4Úblue2)rú   r  r  rø   r÷   r  r  r   c                 ó:   — d}t        | t        | ||¬«      d¬«      S )N)r  iðÿÿÿr  )ÚfontÚgreenr   )r   r   )r)   ÚtextÚbigs      r/   Úboxitzdemo.<locals>.boxit  s   € Ø(ˆÜ˜¤¨F°D¸sÔ!CÈ'ÔRÐRrF   c                 ó2   — t        | t        | |«      d¬«      S )NÚcyanr   )r	   r   )r)   re  s     r/   Úovalitzdemo.<locals>.ovalit  s   € Ü˜&¤*¨V°TÓ":ÀÔHÐHrF   z/(S (NP this tree) (VP (V is) (AdjP shapeable))))rù   c                 ó6   •— d‰j                  dd«      z  | d<   y )Nz#%04d00r   é'  r7   rW  )rê   rZ  s    €r/   r7   zdemo.<locals>.color  s   ø€ Ø! F§N¡N°1°dÓ$;Ñ;ˆˆWŠrF   c                 ó”   •— d‰j                  dd«      z  | j                  «       d<   d| j                  «       j                  «       d<   y )NrV  r   rl  r   r  r7   )rX  r*   rY   )rñ   rZ  s    €r/   Úcolor2zdemo.<locals>.color2!  s<   ø€ Ø")¨F¯N©N¸1¸dÓ,CÑ"Cˆ�‰‹˜ÑØ+2ˆ�‰‹×ÑÓ Ò(rF   rb   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                 ó>  — | 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<   y | 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<   y )Nr3   r4   r5   r   r6   rb   )rÑ   r+   Úset_textrÓ   )Ú
treewidgets    r/   Úorientswitchzdemo.<locals>.orientswitch9  s_  € Ø�mÑ$¨Ò4Ø×$Ñ$ Q¨Ó*×3Ñ3Ó5°aÑ8×AÑAÀ*ÔMØ×%Ñ% a¨Ó+×4Ñ4Ó6°qÑ9×BÑBÀ:ÔNØ×%Ñ% aÓ(×1Ñ1Ó3°AÑ6×?Ñ?À
ÔKØ×%Ñ%Ó'×0Ñ0Ó2°1Ñ5×>Ñ>¸zÔJØ(2ˆJ�}Ò%à×$Ñ$ Q¨Ó*×3Ñ3Ó5°aÑ8×AÑAÀ,ÔOØ×%Ñ% a¨Ó+×4Ñ4Ó6°qÑ9×BÑBÀ<ÔPØ×%Ñ% aÓ(×1Ñ1Ó3°AÑ6×?Ñ?ÀÔMØ×%Ñ%Ó'×0Ñ0Ó2°1Ñ5×>Ñ>¸|ÔLØ(4ˆJ�}Ò%rF   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)r  r]  r  Úbrown4r4   )rú   rõ   r÷   r  r  r3   )rZ  r   r   Ú
fromstringr·   r)   r'  rÜ   r
  rë   rÑ   r×   r
   re   rµ   r   Ústripr   rû   rO  )r   r,  r¤   Útcrg  rj  ÚtreetokÚtc2r7   rn  ÚparenÚtree3Útc3ru  re  ÚtwidgetÚtextboxÚtree4Útc4rZ  s                      @r/   Údemor„  ù  s¯  ø€ Ûô9ô 
˜3 s¸Ô	:€Bä�‰ð	;ó	€Aô 
Ø
�	‰	‹Ø	ØØ,Ø.ØØØØô

€Bð ‡M�M�"�b˜"ÔòSòIô �o‰oÐOÓP€GÜ
�R—Y‘Y“[ '¨5°&ÀAÔ
F€Cô<ô3ð ×Ñ˜×+Ñ+Ô,Ø×Ñ˜×-Ñ-Ô.Ø×Ñ˜˜qÔ!Ø×Ñ�aÓ×#Ñ# F¨AÔ.Ø×ÑÓ×"Ñ" 6¨1Ô-ä˜Ÿ	™	› SÓ)€EØ‡M�M�%˜Ÿ™› 1™¨Ñ*¨BÔ/ä�O‰Oð	Eó€Eô
 Ø
�	‰	‹�U x¸QÈ1ô€Cð €CˆÑØ‡M�M�#�r˜2Ÿ7™7›9 Q™<¨"Ñ,Ô-ò5ð#€Dô ˜Ÿ™› d§j¡j£lÓ3€GÜ˜Ÿ	™	› W°7ÀaÔH€GØ‡M�M�'˜3Ÿ8™8›: a™=¨2Ñ-¨s¯x©x«z¸!©}¸rÑ/AÔBä�O‰OÐMÓN€EÜ
Ø
�	‰	‹ØØØØØ,ØØ ô	€Cð ‡J�J„LØ‡M�M�#�s—x‘x“z !‘} rÑ)¨7¯<©<«>¸!Ñ+<¸rÑ+AÔBØ‡N�N�<Ô Ø×Ñ˜×-Ñ-¨qÔ1ð ‡K�K…MrF   Ú__main__N)r    Útkinterr   r   r   Únltk.draw.utilr   r   r   r	   r
   r   Ú	nltk.treer   Ú	nltk.utilr   r   r£   rµ   r·   r  rS  r„  r�   r¡   rF   r/   ú<module>rŠ     s�   ðñ÷ %Ñ $÷÷ õ Ý ôE<˜ô E<òP4ð> $¨zó1ôrP1�ô P1÷p
Q,ñ Q,òhò lð^ ˆzÒÙ…Fð rF   