
    /h-Y                       S r SSKJrJr  SSKJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJr  SSKJr  SSKJr   " S S\S9r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S S\5      r" " S S 5      r# " S! S"5      r$ " S# S$5      r% " S% S&5      r& " S' S(\5      r'S) r(\)S*:X  a  \(" 5         g+g+),a8  
Tools for graphically displaying and interacting with the objects and
processing classes defined by the Toolkit.  These tools are primarily
intended to help students visualize the objects that they create.

The graphical tools are typically built using "canvas widgets", each
of which encapsulates the graphical elements and bindings used to
display a complex object on a Tkinter ``Canvas``.  For example, NLTK
defines canvas widgets for displaying trees and directed graphs, as
well as a number of simpler widgets.  These canvas widgets make it
easier to build new graphical tools and demos.  See the class
documentation for ``CanvasWidget`` for more information.

The ``nltk.draw`` module defines the abstract ``CanvasWidget`` base
class, and a number of simple canvas widgets.  The remaining canvas
widgets are defined by submodules, such as ``nltk.draw.tree``.

The ``nltk.draw`` module also defines ``CanvasFrame``, which
encapsulates a ``Canvas`` and its scrollbars.  It uses a
``ScrollWatcherWidget`` to ensure that all canvas widgets contained on
its canvas are within the scroll region.

Acknowledgements: Many of the ideas behind the canvas widget system
are derived from ``CLIG``, a Tk-based grapher for linguistic data
structures.  For more information, see the CLIG
homepage (http://www.ags.uni-sb.de/~konrad/clig.html).

    )ABCMetaabstractmethod)RAISEDButtonCanvasEntryFrameLabelMenu
Menubutton	Scrollbar	StringVarTextTkToplevelWidget)asksaveasfilename)in_idlec                       \ rS rSrSrS'S jrS rS rS rS r	S	 r
S
 rS rS(S jrS rS rS rS rS rS rS rS rS rS rS)S jrS rS)S jrS rS rS rS rS rS r S  r!S! r"S" r#\$S# 5       r%S$ r&S% r'S&r(g)*CanvasWidget>   a  
A collection of graphical elements and bindings used to display a
complex object on a Tkinter ``Canvas``.  A canvas widget is
responsible for managing the ``Canvas`` tags and callback bindings
necessary to display and interact with the object.  Canvas widgets
are often organized into hierarchies, where parent canvas widgets
control aspects of their child widgets.

Each canvas widget is bound to a single ``Canvas``.  This ``Canvas``
is specified as the first argument to the ``CanvasWidget``'s
constructor.

Attributes.  Each canvas widget can support a variety of
"attributes", which control how the canvas widget is displayed.
Some typical examples attributes are ``color``, ``font``, and
``radius``.  Each attribute has a default value.  This default
value can be overridden in the constructor, using keyword
arguments of the form ``attribute=value``:

    >>> from nltk.draw.util import TextWidget
    >>> cn = TextWidget(Canvas(), 'test', color='red')  # doctest: +SKIP

Attribute values can also be changed after a canvas widget has
been constructed, using the ``__setitem__`` operator:

    >>> cn['font'] = 'times'  # doctest: +SKIP

The current value of an attribute value can be queried using the
``__getitem__`` operator:

    >>> cn['color']  # doctest: +SKIP
    'red'

For a list of the attributes supported by a type of canvas widget,
see its class documentation.

Interaction.  The attribute ``'draggable'`` controls whether the
user can drag a canvas widget around the canvas.  By default,
canvas widgets are not draggable.

``CanvasWidget`` provides callback support for two types of user
interaction: clicking and dragging.  The method ``bind_click``
registers a callback function that is called whenever the canvas
widget is clicked.  The method ``bind_drag`` registers a callback
function that is called after the canvas widget is dragged.  If
the user clicks or drags a canvas widget with no registered
callback function, then the interaction event will propagate to
its parent.  For each canvas widget, only one callback function
may be registered for an interaction event.  Callback functions
can be deregistered with the ``unbind_click`` and ``unbind_drag``
methods.

Subclassing.  ``CanvasWidget`` is an abstract class.  Subclasses
are required to implement the following methods:

  - ``__init__``: Builds a new canvas widget.  It must perform the
    following three tasks (in order):

      - Create any new graphical elements.
      - Call ``_add_child_widget`` on each child widget.
      - Call the ``CanvasWidget`` constructor.
  - ``_tags``: Returns a list of the canvas tags for all graphical
    elements managed by this canvas widget, not including
    graphical elements managed by its child widgets.
  - ``_manage``: Arranges the child widgets of this canvas widget.
    This is typically only called when the canvas widget is
    created.
  - ``_update``: Update this canvas widget in response to a
    change in a single child.

For a ``CanvasWidget`` with no child widgets, the default
definitions for ``_manage`` and ``_update`` may be used.

If a subclass defines any attributes, then it should implement
``__getitem__`` and ``__setitem__``.  If either of these methods is
called with an unknown attribute, then they should propagate the
request to ``CanvasWidget``.

Most subclasses implement a number of additional methods that
modify the ``CanvasWidget`` in some way.  These methods must call
``parent.update(self)`` after making any changes to the canvas
widget's graphical elements.  The canvas widget must also call
``parent.update(self)`` after changing any attribute value that
affects the shape or position of the canvas widget's graphical
elements.

:type __canvas: Tkinter.Canvas
:ivar __canvas: This ``CanvasWidget``'s canvas.

:type __parent: CanvasWidget or None
:ivar __parent: This ``CanvasWidget``'s hierarchical parent widget.
:type __children: list(CanvasWidget)
:ivar __children: This ``CanvasWidget``'s hierarchical child widgets.

:type __updating: bool
:ivar __updating: Is this canvas widget currently performing an
    update?  If it is, then it will ignore any new update requests
    from child widgets.

:type __draggable: bool
:ivar __draggable: Is this canvas widget draggable?
:type __press: event
:ivar __press: The ButtonPress event that we're currently handling.
:type __drag_x: int
:ivar __drag_x: Where it's been moved to (to find dx)
:type __drag_y: int
:ivar __drag_y: Where it's been moved to (to find dy)
:type __callbacks: dictionary
:ivar __callbacks: Registered callbacks.  Currently, four keys are
    used: ``1``, ``2``, ``3``, and ``'drag'``.  The values are
    callback functions.  Each callback function takes a single
    argument, which is the ``CanvasWidget`` that triggered the
    callback.
Nc                    U R                   [        :X  a  [        S5      e[        U[        5      (       d  [        S5      eXl        X l        [        U S5      (       d  / U l        SU l	        SU l
        SU l        S=U l        U l        0 U l        SU l        [!        UR#                  5       5       H	  u  pEXPU'   M     U R%                  5         U R'                  5        Hx  nU R
                  R)                  USU R*                  5        U R
                  R)                  USU R*                  5        U R
                  R)                  USU R*                  5        Mz     g)	a  
Create a new canvas widget.  This constructor should only be
called by subclass constructors; and it should be called only
"after" the subclass has constructed all graphical canvas
objects and registered all child widgets.

:param canvas: This canvas widget's canvas.
:type canvas: Tkinter.Canvas
:param parent: This canvas widget's hierarchical parent.
:type parent: CanvasWidget
:param attribs: The new canvas widget's attributes.
z&CanvasWidget is an abstract base classzExpected a canvas!_CanvasWidget__childrenr   N<ButtonPress-1><ButtonPress-2><ButtonPress-3>)	__class__r   	TypeError
isinstancer   _CanvasWidget__canvas_CanvasWidget__parenthasattrr   _CanvasWidget__hidden_CanvasWidget__updating_CanvasWidget__press_CanvasWidget__drag_x_CanvasWidget__drag_y_CanvasWidget__callbacks_CanvasWidget__draggablelistitems_manage_tagstag_bind_CanvasWidget__press_cb)selfcanvasparentattribsattrvaluetags          F/var/www/auris/envauris/lib/python3.13/site-packages/nltk/draw/util.py__init__CanvasWidget.__init__   s    >>\)DEE&&))011 t677 DO   ())  0KDJ 1 	 ::<CMM""3(94??KMM""3(94??KMM""3(94??K      c                     U R                   (       a  g[        U R                  5       5      S:X  a  [        S5      eU R                  R
                  " U R                  5       6 $ )aa  
:return: A bounding box for this ``CanvasWidget``. The bounding
    box is a tuple of four coordinates, *(xmin, ymin, xmax, ymax)*,
    for a rectangle which encloses all of the canvas
    widget's graphical elements.  Bounding box coordinates are
    specified with respect to the coordinate space of the ``Canvas``.
:rtype: tuple(int, int, int, int)
)r   r   r   r   r   No tags)r#   lentags
ValueErrorr    bboxr0   s    r7   r@   CanvasWidget.bbox   sG     ==tyy{q Y''}}!!499;//r:   c                     [        U R                  5       5      S:X  a  [        S5      eU R                  R                  " U R                  5       6 nUS   US   -
  $ )zp
:return: The width of this canvas widget's bounding box, in
    its ``Canvas``'s coordinate space.
:rtype: int
r   r<      r=   r>   r?   r    r@   r0   r@   s     r7   widthCanvasWidget.width   O     tyy{q Y''}}!!499;/Awa  r:   c                     [        U R                  5       5      S:X  a  [        S5      eU R                  R                  " U R                  5       6 nUS   US   -
  $ )zq
:return: The height of this canvas widget's bounding box, in
    its ``Canvas``'s coordinate space.
:rtype: int
r   r<         rE   rF   s     r7   heightCanvasWidget.height  rI   r:   c                     U R                   $ )z
:return: The hierarchical parent of this canvas widget.
    ``self`` is considered a subpart of its parent for
    purposes of user interaction.
:rtype: CanvasWidget or None
)r!   rA   s    r7   r2   CanvasWidget.parent  s     }}r:   c                     U R                   $ )z
:return: A list of the hierarchical children of this canvas
    widget.  These children are considered part of ``self``
    for purposes of user interaction.
:rtype: list of CanvasWidget
)r   rA   s    r7   child_widgetsCanvasWidget.child_widgets  s     r:   c                     U R                   $ )zQ
:return: The canvas that this canvas widget is bound to.
:rtype: Tkinter.Canvas
)r    rA   s    r7   r1   CanvasWidget.canvas!      
 }}r:   c                     Xs=:X  a  S:X  a   g  U R                  5        H  nU R                  R                  X1U5        M!     U R                  (       a  U R                  R	                  U 5        gg)a  
Move this canvas widget by a given distance.  In particular,
shift the canvas widget right by ``dx`` pixels, and down by
``dy`` pixels.  Both ``dx`` and ``dy`` may be negative, resulting
in leftward or upward movement.

:type dx: int
:param dx: The number of pixels to move this canvas widget
    rightwards.
:type dy: int
:param dy: The number of pixels to move this canvas widget
    downwards.
:rtype: None
r   N)r>   r    mover!   update)r0   dxdyr6   s       r7   rX   CanvasWidget.move(  sW     =q= 99;CMMs+ ==MM  & r:   c                 4   U R                  5       u  pEpgUS:X  a  U R                  X-
  X%-
  5        US:X  a  U R                  XS-  -
  US-  -
  X%-
  5        US:X  a  U R                  X-
  X%-
  5        US:X  a  U R                  X-
  X%S-  -
  US-  -
  5        US:X  a  U R                  X-
  X'-
  5        US:X  a  U R                  XS-  -
  US-  -
  X'-
  5        US:X  a  U R                  X-
  X'-
  5        US	:X  a   U R                  X-
  X%S-  -
  US-  -
  5        g
g
)a  
Move this canvas widget to the given location.  In particular,
shift the canvas widget such that the corner or side of the
bounding box specified by ``anchor`` is at location (``x``,
``y``).

:param x,y: The location that the canvas widget should be moved
    to.
:param anchor: The corner or side of the canvas widget that
    should be moved to the specified location.  ``'N'``
    specifies the top center; ``'NE'`` specifies the top right
    corner; etc.
NWNrD   NEESESSWWN)r@   rX   )r0   xyanchorx1y1x2y2s           r7   movetoCanvasWidget.moveto>  s    T>IIafaf%S=IIaq&j26)162T>IIafaf%S=IIafaq&j2612T>IIafaf%S=IIaq&j26)162T>IIafaf%S=IIafaq&j2612 r:   c                    U R                   b  U R                   R                  5         gU R                  5        HW  nU R                  R	                  US5        U R                  R	                  US5        U R                  R	                  US5        MY     U R                  R
                  " U R                  5       6   SU l        g)a  
Remove this ``CanvasWidget`` from its ``Canvas``.  After a
``CanvasWidget`` has been destroyed, it should not be accessed.

Note that you only need to destroy a top-level
``CanvasWidget``; its child widgets will be destroyed
automatically.  If you destroy a non-top-level
``CanvasWidget``, then the entire top-level widget will be
destroyed.

:raise ValueError: if this ``CanvasWidget`` has a parent.
:rtype: None
Nr   r   r   )r!   destroyr>   r    
tag_unbinddeleter0   r6   s     r7   rp   CanvasWidget.destroy^  s     ==$MM!!#99;CMM$$S*;<MM$$S*;<MM$$S*;<  	diik*r:   c                    U R                   (       d  UR                   (       a  gU R                  (       a  gSU l        U R                  U5        U R                  (       a  U R                  R	                  U 5        SU l        g)z
Update the graphical display of this canvas widget, and all of
its ancestors, in response to a change in one of this canvas
widget's children.

:param child: The child widget that changed.
:type child: CanvasWidget
NrL   r   )r#   r$   _updater!   rY   r0   childs     r7   rY   CanvasWidget.updatew  sY     ==ENN ?? 	U ==MM  & r:   c                     U R                   (       a  gU R                   H  nUR                  5         M     U R                  5         g)zF
Arrange this canvas widget and all of its descendants.

:rtype: None
N)r#   r   manager,   rw   s     r7   r{   CanvasWidget.manage  s.     ==__ELLN %r:   c                     U R                   c  [        S5      e/ nXR                  5       -  nU R                   H  nXR	                  5       -  nM     U$ )z
:return: a list of the canvas tags for all graphical
    elements managed by this canvas widget, including
    graphical elements managed by its child widgets.
:rtype: list of int
z+Attempt to access a destroyed canvas widget)r    r?   r-   r   r>   )r0   r>   rx   s      r7   r>   CanvasWidget.tags  sN     == JKK

__EJJL D %r:   c                 8    US:X  a  X l         g[        SU-  5      e)z
Set the value of the attribute ``attr`` to ``value``.  See the
class documentation for a list of attributes supported by this
canvas widget.

:rtype: None
	draggableUnknown attribute %rNr)   r?   r0   r4   r5   s      r7   __setitem__CanvasWidget.__setitem__  s#     ;$3d:;;r:   c                 B    US:X  a  U R                   $ [        SU-  5      e)z
:return: the value of the attribute ``attr``.  See the class
    documentation for a list of attributes supported by this
    canvas widget.
:rtype: (any)
r   r   r   r0   r4   s     r7   __getitem__CanvasWidget.__getitem__  s)     ;###3d:;;r:   c                 4    SU R                   R                  -  $ )zE
:return: a string representation of this canvas widget.
:rtype: str
z<%s>)r   __name__rA   s    r7   __repr__CanvasWidget.__repr__  s    
 ////r:   c                 t    SU l         U R                  5        H  nU R                  R                  USS9  M     g)z4
Temporarily hide this canvas widget.

:rtype: None
rL   hiddenstateNr#   r>   r    
itemconfigrs   s     r7   hideCanvasWidget.hide  2     99;CMM$$S$9 r:   c                 t    SU l         U R                  5        H  nU R                  R                  USS9  M     g)z,
Show a hidden canvas widget.

:rtype: None
r   normalr   Nr   rs   s     r7   showCanvasWidget.show  r   r:   c                     U R                   $ )z=
:return: True if this canvas widget is hidden.
:rtype: bool
)r#   rA   s    r7   r   CanvasWidget.hidden  rV   r:   c                      XR                   U'   g)a  
Register a new callback that will be called whenever this
``CanvasWidget`` is clicked on.

:type callback: function
:param callback: The callback function that will be called
    whenever this ``CanvasWidget`` is clicked.  This function
    will be called with this ``CanvasWidget`` as its argument.
:type button: int
:param button: Which button the user should use to click on
    this ``CanvasWidget``.  Typically, this should be 1 (left
    button), 3 (right button), or 2 (middle button).
Nr(   )r0   callbackbuttons      r7   
bind_clickCanvasWidget.bind_click  s     $, r:   c                 .    SU l         XR                  S'   g)a_  
Register a new callback that will be called after this
``CanvasWidget`` is dragged.  This implicitly makes this
``CanvasWidget`` draggable.

:type callback: function
:param callback: The callback function that will be called
    whenever this ``CanvasWidget`` is clicked.  This function
    will be called with this ``CanvasWidget`` as its argument.
rL   dragN)r)   r(   )r0   r   s     r7   	bind_dragCanvasWidget.bind_drag  s     #+ r:   c                 .     U R                   U	 g!    g= f)z
Remove a callback that was registered with ``bind_click``.

:type button: int
:param button: Which button the user should use to click on
    this ``CanvasWidget``.  Typically, this should be 1 (left
    button), 3 (right button), or 2 (middle button).
Nr   )r0   r   s     r7   unbind_clickCanvasWidget.unbind_click
  s    	  (	    c                 .     U R                   S	 g!    g= f)z;
Remove a callback that was registered with ``bind_drag``.
r   Nr   rA   s    r7   unbind_dragCanvasWidget.unbind_drag  s    	  (	r   c                    U R                   R                  S5      (       d@  U R                   R                  S5      (       d   U R                   R                  S5      (       a  gU R                   R                  S5        Xl        UR                  S:X  a6  U nUb1  US   (       a  UR                  U5        OUR                  5       nUb  M1  U R                   R                  SUR                  -  U R                  5        g)	z
Handle a button-press event:
  - record the button press event in ``self.__press``
  - register a button-release callback.
  - if this CanvasWidget or any of its ancestors are
    draggable, then register the appropriate motion callback.
z<ButtonRelease-1>z<ButtonRelease-2>z<ButtonRelease-3>N<Motion>rL   r   <ButtonRelease-%d>)r    bindunbindr%   num_CanvasWidget__start_dragr2   _CanvasWidget__release_cb)r0   eventwidgets      r7   
__press_cbCanvasWidget.__press_cb%  s     MM233}}!!"566}}!!"566 	Z(  99>F$+&''.	 $ 	/%));T=N=NOr:   c                     U R                   R                  SU R                  5        UR                  U l        UR
                  U l        g)z\
Begin dragging this object:
  - register a motion callback
  - record the drag coordinates
r   N)r    r   _CanvasWidget__motion_cbrf   r&   rg   r'   r0   r   s     r7   __start_dragCanvasWidget.__start_dragI  s4     	:t'7'78r:   c                     U R                  UR                  U R                  -
  UR                  U R                  -
  5        UR                  U l        UR                  U l        g)ze
Handle a motion event:
  - move this object to the new location
  - record the new drag coordinates
N)rX   rf   r&   rg   r'   r   s     r7   __motion_cbCanvasWidget.__motion_cbS  sB     			%''DMM)577T]]+BCr:   c                    U R                   R                  SUR                  -  5        U R                   R                  S5        UR                  U R                  R                  -
  S:  a  [        UR                  U R                  R                  -
  5      [        UR                  U R                  R                  -
  5      -   S:  a  U R                  (       ad  UR                  S:X  aT  U R                  U R                  R                  U R                  -
  U R                  R                  U R                  -
  5        U R                  UR                  5        O UR                  S:X  a  U R                  5         SU l        g)z
Handle a release callback:
  - unregister motion & button release callbacks.
  - decide whether they clicked, dragged, or cancelled
  - call the appropriate handler.
r   r   d      rL   N)r    r   r   timer%   absrf   rg   r)   rX   r&   r'   _CanvasWidget__click_CanvasWidget__dragr   s     r7   __release_cbCanvasWidget.__release_cb]  s     	1EII=>Z( JJ***S0EGGdllnn,-EGGdllnn4L0MMPQQ EIIN		LLNNT]]2DLLNNT]]4R LL#YY!^KKMr:   c                     U R                   (       a*  SU R                  ;   a  U R                  S   n U" U 5        ggU R                  b  U R                  R	                  5         gg!   [        SU -  5         g= f)z
If this ``CanvasWidget`` has a drag callback, then call it;
otherwise, find the closest ancestor with a drag callback, and
call it.  If no ancestors have a drag callback, do nothing.
r   zError in drag callback for %rN)r)   r(   printr!   r   )r0   cbs     r7   __dragCanvasWidget.__dragx  st     )))%%f-BtH * ]]&MM  " 'B9D@As   A% %A7c                     XR                   ;   a  U R                   U   nU" U 5        gU R                  b  U R                  R                  U5        gg)z
If this ``CanvasWidget`` has a drag callback, then call it;
otherwise, find the closest ancestor with a click callback, and
call it.  If no ancestors have a click callback, do nothing.
N)r(   r!   r   )r0   r   r   s      r7   __clickCanvasWidget.__click  sJ     %%%!!&)BtH ]]&MM!!&) 'r:   c                     [        U S5      (       d  / U l        UR                  b  [        U S35      eXl        U R                  R	                  U5        g)a  
Register a hierarchical child widget.  The child will be
considered part of this canvas widget for purposes of user
interaction.  ``_add_child_widget`` has two direct effects:
  - It sets ``child``'s parent to this canvas widget.
  - It adds ``child`` to the list of canvas widgets returned by
    the ``child_widgets`` member function.

:param child: The new child widget.  ``child`` must not already
    have a parent.
:type child: CanvasWidget
r   Nz already has a parent)r"   r   r!   r?   appendrw   s     r7   _add_child_widgetCanvasWidget._add_child_widget  sM     t677 DO>>%w&;<==u%r:   c                 H    U R                   R                  U5        SUl        g)a  
Remove a hierarchical child widget.  This child will no longer
be considered part of this canvas widget for purposes of user
interaction.  ``_add_child_widget`` has two direct effects:
  - It sets ``child``'s parent to None.
  - It removes ``child`` from the list of canvas widgets
    returned by the ``child_widgets`` member function.

:param child: The child widget to remove.  ``child`` must be a
    child of this canvas widget.
:type child: CanvasWidget
N)r   remover!   rw   s     r7   _remove_child_widget!CanvasWidget._remove_child_widget  s     	u%r:   c                     g)z
:return: a list of canvas tags for all graphical elements
    managed by this canvas widget, not including graphical
    elements managed by its child widgets.
:rtype: list of int
N rA   s    r7   r-   CanvasWidget._tags      r:   c                     g)z
Arrange the child widgets of this canvas widget.  This method
is called when the canvas widget is initially created.  It is
also called if the user calls the ``manage`` method on this
canvas widget or any of its ancestors.

:rtype: None
Nr   rA   s    r7   r,   CanvasWidget._manage  r   r:   c                     g)z
Update this canvas widget in response to a change in one of
its children.

:param child: The child that changed.
:type child: CanvasWidget
:rtype: None
Nr   rw   s     r7   rv   CanvasWidget._update  r   r:   )
__callbacks__canvas
__children__drag_x__drag_y__draggable__hidden__parent__press
__updatingN)r^   )rL   ))r   
__module____qualname____firstlineno____doc__r8   r@   rG   rM   r2   rR   r1   rX   rm   rp   rY   r{   r>   r   r   r   r   r   r   r   r   r   r   r/   r   r   r   r   r   r   r   r   r-   r,   rv   __static_attributes__r   r:   r7   r   r   >   s    qf2Lp0	!	!',3@26
<
<0::, ,"PH  6# *(&((  r:   r   )	metaclassc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)
TextWidgeti  a  
A canvas widget that displays a single string of text.

Attributes:
  - ``color``: the color of the text.
  - ``font``: the font used to display the text.
  - ``justify``: justification for multi-line texts.  Valid values
    are ``left``, ``center``, and ``right``.
  - ``width``: the width of the text.  If the text is wider than
    this width, it will be line-wrapped at whitespace.
  - ``draggable``: whether the text can be dragged by the user.
c                 j    X l         UR                  SSUS9U l        [        R                  " X40 UD6  g)z
Create a new text widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:type text: str
:param text: The string of text to display.
:param attribs: The new canvas widget's attributes.
rL   textN)_textcreate_text_tagr   r8   )r0   r1   r   r3   s       r7   r8   TextWidget.__init__  s5     
&&q!$&7	d6g6r:   c                     US;   a4  US:X  a  SnU R                  5       R                  U R                  X05        g [        R	                  XU5        g )N)colorfontjustifyrG   r   fill)r1   r   r   r   r   r   s      r7   r   TextWidget.__setitem__  sC    88wKKM$$TYY>$$T7r:   c                    US:X  a3  [        U R                  5       R                  U R                  U5      5      $ US;   a2  US:X  a  SnU R                  5       R                  U R                  U5      $ [        R                  X5      $ )NrG   )r   r   r   r   r  )intr1   itemcgetr   r   r   r   s     r7   r   TextWidget.__getitem__  sn    7?t{{}--dii>??11w;;=))$))T::++D77r:   c                     U R                   /$ r   r   rA   s    r7   r-   TextWidget._tags      		{r:   c                 V    U R                  5       R                  U R                  S5      $ )z>
:return: The text displayed by this text widget.
:rtype: str
TEXT)r1   r  r   rA   s    r7   r   TextWidget.text  s!    
 {{}%%dii88r:   c                     U R                  5       R                  U R                  US9  U R                  5       b   U R                  5       R	                  U 5        gg)z
Change the text that is displayed by this text widget.

:type text: str
:param text: The string of text to display.
:rtype: None
r   N)r1   r   r   r2   rY   )r0   r   s     r7   set_textTextWidget.set_text  sF     	   6;;=$KKM  & %r:   c                      SU R                   -  $ )Nz
[Text: %r])r   rA   s    r7   r   TextWidget.__repr__+  s    djj((r:   )r   r   N)r   r   r   r   r   r8   r   r   r-   r   r  r   r   r   r:   r7   r   r     s*    7889
')r:   r   c                       \ rS rSrSr0 SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_S\" S5      _SS_SS _S!S"_S#S$_S%S&0ErS' rS( rS) r	S* r
\S.S+ j5       rS,rg-)/SymbolWidgeti/  a\  
A canvas widget that displays special symbols, such as the
negation sign and the exists operator.  Symbols are specified by
name.  Currently, the following symbol names are defined: ``neg``,
``disj``, ``conj``, ``lambda``, ``merge``, ``forall``, ``exists``,
``subseteq``, ``subset``, ``notsubset``, ``emptyset``, ``imp``,
``rightarrow``, ``equal``, ``notequal``, ``epsilon``.

Attributes:

- ``color``: the color of the text.
- ``draggable``: whether the text can be dragged by the user.

:cvar SYMBOLS: A dictionary mapping from symbols to the character
    in the ``symbol`` font used to render them.
neg   Ødisj   Úconj   Ùlambdalmerge   Äforall"exists$subseteq   Ísubset   Ì	notsubset   Ëemptyset   Æimp   Þ
rightarrow   equal=notequal   ¹intersection   Çunion   Èepsilonec                 `    SUS'   [         R                  " XS40 UD6  U R                  U5        g)z
Create a new symbol widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:type symbol: str
:param symbol: The name of the symbol to display.
:param attribs: The new canvas widget's attributes.
symbolr    N)r   r8   
set_symbol)r0   r1   r:  r3   s       r7   r8   SymbolWidget.__init__V  s.     #D"88r:   c                     U R                   $ )zZ
:return: the name of the symbol that is displayed by this
    symbol widget.
:rtype: str
_symbolrA   s    r7   r:  SymbolWidget.symbold  s     ||r:   c                     U[         R                  ;  a  [        SU-  5      eXl        U R	                  [         R                  U   5        g)z
Change the symbol that is displayed by this symbol widget.

:type symbol: str
:param symbol: The name of the symbol to display.
zUnknown symbol: %sN)r  SYMBOLSr?   r@  r  )r0   r:  s     r7   r<  SymbolWidget.set_symboll  s?     ---1F:;;l**623r:   c                      SU R                   -  $ )Nz[Symbol: %r]r?  rA   s    r7   r   SymbolWidget.__repr__x  s    ,,r:   c                    [        5       nU4S jnUR                  SU5        [        USUR                  S9R	                  SS9  [        USU * 4SS	S
9nUR	                  SS9  [        XR                  S9nUR                  US'   UR	                  SSS9  UR                  SSU * 4S9  [        S5       H  nUS;   a  M  [        [        R                  R                  5       5       H+  u  pgU[        U5      :X  d  M  UR!                  SSU-  5          O   UR!                  SSU-  5        UR!                  SS[        U5      -  S5        M     UR#                  5         g)z
Open a new Tkinter window that displays the entire alphabet
for the symbol font.  This is useful for constructing the
``SymbolWidget.SYMBOLS`` dictionary.
c                 $    UR                  5         g r   )rp   )r8  tops     r7   rp   )SymbolWidget.symbolsheet.<locals>.destroy  s    KKMr:   qQuitr   commandbottomside	helvetica      )r   rG   rM   leftrN  yscrollcommandrightrg   rQ  r  r:  )r      )r   
   endz%-10s	z%-10d  	z[%s]
N)r   r   r   rp   packr   r   yviewset
tag_configranger*   r  rC  r+   chrinsertmainloop)sizerI  rp   r   sbikvs           r7   symbolsheetSymbolWidget.symbolsheet{  s:    d 	 	gs5:::IC{TE2"RH		v	sJJ/!#
W3'4%'89sAG|\11779:A;KKy1}5 ;
 E;?3KKx#a&0(;  	r:   r?  N)rS  )r   r   r   r   r   rb  rC  r8   r:  r<  r   staticmethodrj  r   r   r:   r7   r  r  /  s   "v 	 	&	
 	 	& 	& 	F 	& 	V 	F 	v 	c#h 	 	F  	!" 	#$ 	3%G* 
4-  r:   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
AbstractContainerWidgeti  a  
An abstract class for canvas widgets that contain a single child,
such as ``BoxWidget`` and ``OvalWidget``.  Subclasses must define
a constructor, which should create any new graphical elements and
then call the ``AbstractCanvasContainer`` constructor.  Subclasses
must also define the ``_update`` method and the ``_tags`` method;
and any subclasses that define attributes should define
``__setitem__`` and ``__getitem__``.
c                 `    X l         U R                  U5        [        R                  " X40 UD6  g)aM  
Create a new container widget.  This constructor should only
be called by subclass constructors.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param child: The container's child widget.  ``child`` must not
    have a parent.
:type child: CanvasWidget
:param attribs: The new canvas widget's attributes.
N)_childr   r   r8   r0   r1   rx   r3   s       r7   r8    AbstractContainerWidget.__init__  s*     u%d6g6r:   c                 :    U R                  U R                  5        g r   )rv   rp  rA   s    r7   r,   AbstractContainerWidget._manage  s    T[[!r:   c                     U R                   $ )zT
:return: The child widget contained by this container widget.
:rtype: CanvasWidget
rp  rA   s    r7   rx   AbstractContainerWidget.child  s    
 {{r:   c                     U R                  U R                  5        U R                  U5        Xl        U R                  U5        g)z
Change the child widget contained by this container widget.

:param child: The new child widget.  ``child`` must not have a
    parent.
:type child: CanvasWidget
:rtype: None
N)r   rp  r   rY   rw   s     r7   	set_child!AbstractContainerWidget.set_child  s5     	!!$++.u%Er:   c                 r    U R                   R                  nUSS  S:X  a  US S nSU SU R                  < S3$ )Nir   [z: ])r   r   rp  r0   names     r7   r    AbstractContainerWidget.__repr__  sC    ~~&&9 9D4&4;;/++r:   rv  N)r   r   r   r   r   r8   r,   rx   ry  r   r   r   r:   r7   rn  rn    s     7 ",r:   rn  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
	BoxWidgeti  a  
A canvas widget that places a box around a child widget.

Attributes:
  - ``fill``: The color used to fill the interior of the box.
  - ``outline``: The color used to draw the outline of the box.
  - ``width``: The width of the outline of the box.
  - ``margin``: The number of pixels space left between the child
    and the box.
  - ``draggable``: whether the text can be dragged by the user.
c                     X l         SU l        UR                  SSSS5      U l        UR	                  U R                  5        [
        R                  " XU40 UD6  g)z
Create a new box widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param child: The child widget.  ``child`` must not have a
    parent.
:type child: CanvasWidget
:param attribs: The new canvas widget's attributes.
rL   N)rp  _margincreate_rectangle_box	tag_lowerrn  r8   rq  s       r7   r8   BoxWidget.__init__  sO     ++Aq!Q7	#((uHHr:   c                     US:X  a  X l         g US;   a,  U R                  5       R                  U R                  X05        g [        R                  XU5        g )Nmarginoutliner  rG   )r  r1   r   r  r   r   r   s      r7   r   BoxWidget.__setitem__  sD    8 L11KKM$$TYY>$$T7r:   c                 "   US:X  a  U R                   $ US:X  a3  [        U R                  5       R                  U R                  U5      5      $ US;   a*  U R                  5       R                  U R                  U5      $ [
        R                  X5      $ )Nr  rG   r  )r  floatr1   r  r  r   r   r   s     r7   r   BoxWidget.__getitem__  st    8<<W_//		4@AA11;;=))$))T::++D77r:   c                     UR                  5       u  p#pEU R                  U S   S-  -   nU R                  5       R                  U R                  X&-
  X6-
  XF-   XV-   5        g )NrG   rD   )r@   r  r1   coordsr  )r0   rx   ri   rj   rk   rl   r  s          r7   rv   BoxWidget._update  sT     ::<W 11IIr{BKbk	
r:   c                     U R                   /$ r   )r  rA   s    r7   r-   BoxWidget._tags  r
  r:   )r  rp  r  Nr   r   r   r   r   r8   r   r   rv   r-   r   r   r:   r7   r  r    s!    
I"88
r:   r  c                   :    \ rS rSrSrS rS rS rSrS r	S r
S	rg
)
OvalWidgeti  a  
A canvas widget that places a oval around a child widget.

Attributes:
  - ``fill``: The color used to fill the interior of the oval.
  - ``outline``: The color used to draw the outline of the oval.
  - ``width``: The width of the outline of the oval.
  - ``margin``: The number of pixels space left between the child
    and the oval.
  - ``draggable``: whether the text can be dragged by the user.
  - ``double``: If true, then a double-oval is drawn.
c                 v   X l         SU l        UR                  SSSS5      U l        UR	                  SS5      U l        UR	                  SS5      U l        U R                  (       a  UR                  SSSS5      U l        OSU l        UR                  U R                  5        [        R                  " XU40 UD6  g)z
Create a new oval widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param child: The child widget.  ``child`` must not have a
    parent.
:type child: CanvasWidget
:param attribs: The new canvas widget's attributes.
rL   circleFdoubleN)rp  r  create_oval_ovalpop_circle_double_oval2r  rn  r8   rq  s       r7   r8   OvalWidget.__init__  s     ''1a3
{{8U3{{8U3<< ,,Q1a8DKDK$((uHHr:   c                 `   U R                  5       nUS:X  a  X l        g US:X  a  US:X  a  U R                  c  UR                  U R                  5      u  pEpgU S   S-  nUR                  XH-
  XX-
  Xh-   Xx-   UR                  U R                  S5      UR                  U R                  S5      S9U l        UR                  U R                  5        US:X  a1  U R                  b#  UR                  U R                  5        S U l        g g g US	;   a  UR                  U R                  X05        U R                  b#  US
:w  a  UR                  U R                  X05        U R                  b3  US
:w  a,  U R                  5       R                  U R                  X05        g g g [        R                  XU5        g )Nr  r  TrG   rD   r  )r  rG   Fr  r  )r1   r  r  r@   r  r  r  r  rr   r   r   r   )	r0   r4   r5   cri   rj   rk   rl   ws	            r7   r   OvalWidget.__setitem__6  sl   KKM8 LX}!4!"

!3MA%mmFFFFJJtzz9=**TZZ9 ,  DKK(~$++"9%" #:~ 11LLd]3{{&46>T[[4-8{{&46>((tmD ,:& $$T7r:   c                 J   US:X  a  U R                   $ US:X  a  U R                  S L$ US:X  a3  [        U R                  5       R	                  U R
                  U5      5      $ US;   a*  U R                  5       R	                  U R
                  U5      $ [        R                  X5      $ )Nr  r  rG   r  )r  r  r  r1   r  r  r   r   r   s     r7   r   OvalWidget.__getitem__T  s    8<<X<<t++W_//

DABB11;;=))$**d;;++D77r:   g;f?c                    [         R                  nUR                  5       u  p4pVU R                  nU R                  (       aL  [        X5-
  5      [        XF-
  5      pX:  a  XF-   S-  n
XS-  -
  XS-  -   pdOX:  a  X5-   S-  nXS-  -
  XS-  -   pS[        USU-   -  USU-
  -  -   S-  5      nU[        XS-
  U-  5      -   n[        USU-   -  USU-
  -  -   S-  5      nU[        Xd-
  U-  5      -   nU R                  5       R                  U R                  X-
  X-
  X-   X-   5        U R                  bB  U R                  5       R                  U R                  X-
  S-   X-
  S-   X-   S-
  X-   S-
  5        g g )NrD   rL   )r  RATIOr@   r  r  r   r  r1   r  r  r  )r0   rx   Rri   rj   rk   rl   r  rZ   r[   rg   rf   rU  rX  rI  bots                   r7   rv   OvalWidget._updatec  s{    ::< <<\3rw<wWM!VQaZBWM!VQaZB B!a%L2Q</145sBGq=))2Q<"A,.!34CA&&JJs|U^S\	
 ;;"KKM  !q "q  #r:   c                 f    U R                   c  U R                  /$ U R                  U R                   /$ r   )r  r  rA   s    r7   r-   OvalWidget._tags  s+    ;;JJ<JJ,,r:   )rp  r  r  r  r  r  N)r   r   r   r   r   r8   r   r   r  rv   r-   r   r   r:   r7   r  r    s)    I.8<
8 E@-r:   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
ParenWidgeti  z
A canvas widget that places a pair of parenthases around a child
widget.

Attributes:
  - ``color``: The color used to draw the parenthases.
  - ``width``: The width of the parenthases.
  - ``draggable``: whether the text can be dragged by the user.
c           
          X l         UR                  SSSSSSSS9U l        UR                  SSSSSSSS9U l        [        R
                  " XU40 UD6  g)a  
Create a new parenthasis widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param child: The child widget.  ``child`` must not have a
    parent.
:type child: CanvasWidget
:param attribs: The new canvas widget's attributes.
rL   arcZ      )stylestartextentiN)rp  
create_arc_oparen_cparenrn  r8   rq  s       r7   r8   ParenWidget.__init__  sb     ((Aq!5SV(W((Aq!5TW(X((uHHr:   c                    US:X  aQ  U R                  5       R                  U R                  US9  U R                  5       R                  U R                  US9  g US:X  aQ  U R                  5       R                  U R                  US9  U R                  5       R                  U R                  US9  g [        R                  XU5        g )Nr   r  rG   rG   )r1   r   r  r  r   r   r   s      r7   r   ParenWidget.__setitem__  s    7?KKM$$T\\5$AKKM$$T\\5$AW_KKM$$T\\$?KKM$$T\\$?$$T7r:   c                     US:X  a*  U R                  5       R                  U R                  S5      $ US:X  a*  U R                  5       R                  U R                  S5      $ [        R	                  X5      $ Nr   r  rG   )r1   r  r  r   r   r   s     r7   r   ParenWidget.__getitem__  [    7?;;=))$,,	BBW_;;=))$,,@@++D77r:   c                    UR                  5       u  p#pE[        XS-
  S-  S5      nU R                  5       R                  U R                  X&-
  X2U-   U5        U R                  5       R                  U R
                  XF-
  X4U-   U5        g )N      )r@   maxr1   r  r  r  r0   rx   ri   rj   rk   rl   rG   s          r7   rv   ParenWidget._update  sl     ::<RWM1%T\\2:r:rJT\\2:r:rJr:   c                 2    U R                   U R                  /$ r   )r  r  rA   s    r7   r-   ParenWidget._tags      dll++r:   )rp  r  r  Nr  r   r:   r7   r  r    s"    I 88K,r:   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
BracketWidgeti  z
A canvas widget that places a pair of brackets around a child
widget.

Attributes:
  - ``color``: The color used to draw the brackets.
  - ``width``: The width of the brackets.
  - ``draggable``: whether the text can be dragged by the user.
c           
          X l         UR                  SSSSSSSS5      U l        UR                  SSSSSSSS5      U l        [        R
                  " XU40 UD6  g)z
Create a new bracket widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param child: The child widget.  ``child`` must not have a
    parent.
:type child: CanvasWidget
:param attribs: The new canvas widget's attributes.
rL   N)rp  create_line_obrack_cbrackrn  r8   rq  s       r7   r8   BracketWidget.__init__  s^     ))!Q1aAqA))!Q1aAqA((uHHr:   c                    US:X  aQ  U R                  5       R                  U R                  US9  U R                  5       R                  U R                  US9  g US:X  aQ  U R                  5       R                  U R                  US9  U R                  5       R                  U R                  US9  g [        R                  XU5        g )Nr   r  rG   r  )r1   r   r  r  r   r   r   s      r7   r   BracketWidget.__setitem__  s    7?KKM$$T\\$>KKM$$T\\$>W_KKM$$T\\$?KKM$$T\\$?$$T7r:   c                     US:X  a*  U R                  5       R                  U R                  S5      $ US:X  a*  U R                  5       R                  U R                  S5      $ [        R	                  X5      $ r  )r1   r  r  r   r   r   s     r7   r   BracketWidget.__getitem__  r  r:   c                    UR                  5       u  p#pE[        XS-
  S-  S5      nU R                  5       R                  U R                  X#X&-
  X2U-
  XRU5	        U R                  5       R                  U R
                  XCXF-   X4U-   XTU5	        g )N   rD   )r@   r  r1   r  r  r  r  s          r7   rv   BracketWidget._update  s|     ::<RWM1%LL""*bu*bb	
 	LL""*bu*bb	
r:   c                 2    U R                   U R                  /$ r   )r  r  rA   s    r7   r-   BracketWidget._tags  r  r:   )r  rp  r  Nr  r   r:   r7   r  r    s!    I 88
,r:   r  c                   r    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 r\R                  rS rS rS rSrg)SequenceWidgeti  a  
A canvas widget that keeps a list of canvas widgets in a
horizontal line.

Attributes:
  - ``align``: The vertical alignment of the children.  Possible
    values are ``'top'``, ``'center'``, and ``'bottom'``.  By
    default, children are center-aligned.
  - ``space``: The amount of horizontal space to place between
    children.  By default, one pixel of space is used.
  - ``ordered``: If true, then keep the children in their
    original order.
c                     SU l         SU l        SU l        [        U5      U l        U H  nU R                  U5        M     [        R                  " X40 UD6  g)a*  
Create a new sequence widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param children: The widgets that should be aligned
    horizontally.  Each child must not have a parent.
:type children: list(CanvasWidget)
:param attribs: The new canvas widget's attributes.
centerrL   FN_align_space_orderedr*   	_childrenr   r   r8   r0   r1   childrenr3   rx   s        r7   r8   SequenceWidget.__init__  O     hE""5) d6g6r:   c                     US:X  a  US;  a  [        SU-  5      eX l        g US:X  a  X l        g US:X  a  X l        g [        R                  XU5        g )Nalign)rI  rO  r  Bad alignment: %rspaceorderedr?   r  r  r  r   r   r   s      r7   r   SequenceWidget.__setitem__  Q    7?77 !4u!<==KW_KY!M$$T7r:   c                     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   s     r7   r   SequenceWidget.__getitem__*  G    7?;;W_;;Y== ++D77r:   c                     / $ r   r   rA   s    r7   r-   SequenceWidget._tags4      	r:   c                 z    U R                   S:X  a  U$ U R                   S:X  a  U$ U R                   S:X  a  X-   S-  $ g )NrI  rO  r  rD   r  )r0   rI  r  s      r7   _yalignSequenceWidget._yalign7  sA    ;;%J;;("J;;("I?" #r:   c           	         UR                  5       u  p#pEU R                  X55      nU R                   H9  nUR                  5       u  ppUR                  SX`R                  X5      -
  5        M;     U R                  (       GaK  [        U R                  5      S:  Ga0  U R                  R                  U5      nX@R                  -   n[        US-   [        U R                  5      5       H_  nU R                  U   R                  5       u  ppX:  d  M*  U R                  U   R                  X-
  S5        XU-
  U R                  -   -  nMa     X R                  -
  n[        US-
  SS5       H_  nU R                  U   R                  5       u  ppX:  d  M*  U R                  U   R                  X-
  S5        XU-
  U R                  -   -  nMa     g g g Nr   rL   )	r@   r  r  rX   r  r=   indexr  ra  )r0   rx   rU  rI  rX  r  rg   r  ri   rj   rk   rl   r  rf   rg  s                  r7   rv   SequenceWidget._update?  s   "'**,ELL"A vvxRRFF1a,,r../   ===S014NN((/E#A519c$..&9:#'>>!#4#9#9#; 6NN1%**1615b4;;..A	 ; {{"A519b"-#'>>!#4#9#9#; 6NN1%**1615b4;;..A	 . 5=r:   c           	      $   [        U R                  5      S:X  a  g U R                  S   nUR                  5       u  p#pEU R                  X55      nU R                  R	                  U5      nX@R
                  -   n[        US-   [        U R                  5      5       Hi  n	U R                  U	   R                  5       u  ppU R                  U	   R                  X-
  X`R                  X5      -
  5        XU
-
  U R
                  -   -  nMk     X R
                  -
  n[        US-
  SS5       Hi  n	U R                  U	   R                  5       u  ppU R                  U	   R                  X-
  X`R                  X5      -
  5        XU
-
  U R
                  -   -  nMk     g r  )r=   r  r@   r  r  r  ra  rX   )r0   rx   rU  rI  rX  r  rg   r  rf   rg  ri   rj   rk   rl   s                 r7   r,   SequenceWidget._manageX  sY   t~~!#q! #(**,ELL"$$U+ KKuqy#dnn"56A#~~a0557RRNN1""161||B/C+CDb4;;&&A 7 ;;uqy"b)A#~~a0557RRNN1""161||B/C+CDb4;;&&A *r:   c                 >    S[        U R                  5      SS -   S-   $ )Nz[Sequence: rL   r  r}  reprr  rA   s    r7   r   SequenceWidget.__repr__q  s"    tDNN3Ab99C??r:   c                     U R                   R                  U5      nX R                   U'   U R                  U5        U R                  U5        U R	                  U5        gaJ  
Replace the child canvas widget ``oldchild`` with ``newchild``.
``newchild`` must not have a parent.  ``oldchild``'s parent will
be set to None.

:type oldchild: CanvasWidget
:param oldchild: The child canvas widget to remove.
:type newchild: CanvasWidget
:param newchild: The canvas widget that should replace
    ``oldchild``.
Nr  r  r   r   rY   r0   oldchildnewchildr  s       r7   replace_childSequenceWidget.replace_childw  L     $$X. (u!!(+x(Hr:   c                     U R                   R                  U5      nU R                   U	 U R                  U5        [        U R                   5      S:  a  U R	                  U R                   S   5        ggz
Remove the given child canvas widget.  ``child``'s parent will
be set to None.

:type child: CanvasWidget
:param child: The child canvas widget to remove.
r   Nr  r  r   r=   rY   r0   rx   r  s      r7   remove_childSequenceWidget.remove_child  ]     $$U+NN5!!!%(t~~"KKq)* #r:   c                 \    U R                   R                  X5        U R                  U5        ga  
Insert a child canvas widget before a given index.

:type child: CanvasWidget
:param child: The canvas widget that should be inserted.
:type index: int
:param index: The index where the child widget should be
    inserted.  In particular, the index of ``child`` will be
    ``index``; and the index of any children whose indices were
    greater than equal to ``index`` before ``child`` was
    inserted will be incremented by one.
Nr  rc  r   r0   r  rx   s      r7   insert_childSequenceWidget.insert_child  $     	e+u%r:   r  r  r  r  N)r   r   r   r   r   r8   r   r   r-   r  rv   r,   r   r   rR   r  r  r  r  r   r   r:   r7   r  r    sL    7&
88#/2'2@ ))H$+&r:   r  c                   r    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 r\R                  rS rS rS rSrg)StackWidgeti  a  
A canvas widget that keeps a list of canvas widgets in a vertical
line.

Attributes:
  - ``align``: The horizontal alignment of the children.  Possible
    values are ``'left'``, ``'center'``, and ``'right'``.  By
    default, children are center-aligned.
  - ``space``: The amount of vertical space to place between
    children.  By default, one pixel of space is used.
  - ``ordered``: If true, then keep the children in their
    original order.
c                     SU l         SU l        SU l        [        U5      U l        U H  nU R                  U5        M     [        R                  " X40 UD6  g)a%  
Create a new stack widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:param children: The widgets that should be aligned
    vertically.  Each child must not have a parent.
:type children: list(CanvasWidget)
:param attribs: The new canvas widget's attributes.
r  rL   FNr  r  s        r7   r8   StackWidget.__init__  r  r:   c                     US:X  a  US;  a  [        SU-  5      eX l        g US:X  a  X l        g US:X  a  X l        g [        R                  XU5        g )Nr  )rU  rX  r  r  r  r  r  r   s      r7   r   StackWidget.__setitem__  r  r:   c                     US:X  a  U R                   $ US:X  a  U R                  $ US:X  a  U R                  $ [        R	                  X5      $ r  r  r   s     r7   r   StackWidget.__getitem__  r  r:   c                     / $ r   r   rA   s    r7   r-   StackWidget._tags  r  r:   c                 z    U R                   S:X  a  U$ U R                   S:X  a  U$ U R                   S:X  a  X-   S-  $ g )NrU  rX  r  rD   r  )r0   rU  rX  s      r7   _xalignStackWidget._xalign  sB    ;;& K;;'!L;;("LA%% #r:   c                    UR                  5       u  p#pEU R                  X$5      nU R                   H9  nUR                  5       u  ppUR                  X`R                  X5      -
  S5        M;     U R                  (       GaK  [        U R                  5      S:  Ga0  U R                  R                  U5      nXPR                  -   n[        US-   [        U R                  5      5       H_  nU R                  U   R                  5       u  ppX:  d  M*  U R                  U   R                  SX-
  5        XU	-
  U R                  -   -  nMa     X0R                  -
  n[        US-
  SS5       H_  nU R                  U   R                  5       u  ppX:  d  M*  U R                  U   R                  SX-
  5        XU	-
  U R                  -   -  nMa     g g g r  )	r@   r.  r  rX   r  r=   r  r  ra  )r0   rx   rU  rI  rX  r  rf   r  ri   rj   rk   rl   r  rg   rg  s                  r7   rv   StackWidget._update  s   "'**,ELL%A vvxRRFF1||B++Q/   ===S014NN((/Ekk!A519c$..&9:#'>>!#4#9#9#; 6NN1%**1af5b4;;..A	 ; kk!A519b"-#'>>!#4#9#9#; 6NN1%**1af5b4;;..A	 . 5=r:   c                 $   [        U R                  5      S:X  a  g U R                  S   nUR                  5       u  p#pEU R                  X$5      nU R                  R	                  U5      nXPR
                  -   n[        US-   [        U R                  5      5       Hi  n	U R                  U	   R                  5       u  ppU R                  U	   R                  X`R                  X5      -
  X-
  5        XU-
  U R
                  -   -  nMk     X0R
                  -
  n[        US-
  SS5       Hi  n	U R                  U	   R                  5       u  ppU R                  U	   R                  X`R                  X5      -
  X-
  5        XU-
  U R
                  -   -  nMk     g r  )r=   r  r@   r.  r  r  ra  rX   )r0   rx   rU  rI  rX  r  rf   r  rg   rg  ri   rj   rk   rl   s                 r7   r,   StackWidget._manage  sY   t~~!#q! #(**,ELL%$$U+ ++uqy#dnn"56A#~~a0557RRNN1""1||B';#;QVDb4;;&&A 7 ++uqy"b)A#~~a0557RRNN1""1||B';#;QVDb4;;&&A *r:   c                 >    S[        U R                  5      SS -   S-   $ )Nz[Stack: rL   r  r}  r  rA   s    r7   r   StackWidget.__repr__  s"    D0266<<r:   c                     U R                   R                  U5      nX R                   U'   U R                  U5        U R                  U5        U R	                  U5        gr  r  r  s       r7   r  StackWidget.replace_child#  r  r:   c                     U R                   R                  U5      nU R                   U	 U R                  U5        [        U R                   5      S:  a  U R	                  U R                   S   5        ggr  r  r  s      r7   r  StackWidget.remove_child5  r  r:   c                 \    U R                   R                  X5        U R                  U5        gr  r  r  s      r7   r  StackWidget.insert_childC  r!  r:   r"  N)r   r   r   r   r   r8   r   r   r-   r.  rv   r,   r   r   rR   r  r  r  r  r   r   r:   r7   r$  r$    sK    7&
88&/2'2= ))H$+&r:   r$  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
SpaceWidgetiT  aL  
A canvas widget that takes up space but does not display
anything.  A ``SpaceWidget`` can be used to add space between
elements.  Each space widget is characterized by a width and a
height.  If you wish to only create horizontal space, then use a
height of zero; and if you wish to only create vertical space, use
a width of zero.
c                     US:  a  US-  nUS:  a  US-  nUR                  SSX#SS9U l        [        R                  " X40 UD6  g)a!  
Create a new space widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:type width: int
:param width: The width of the new space widget.
:type height: int
:param height: The height of the new space widget.
:param attribs: The new canvas widget's attributes.
r  rL   r;  r  N)r  r   r   r8   )r0   r1   rG   rM   r3   s        r7   r8   SpaceWidget.__init__^  sR     19QJEA:aKF&&q!U&D	d6g6r:   c                     U R                  5       u  p#pEU R                  5       R                  U R                  X#X!-   U5        g)zd
Change the width of this space widget.

:param width: The new width.
:type width: int
:rtype: None
Nr@   r1   r  r   )r0   rG   ri   rj   rk   rl   s         r7   	set_widthSpaceWidget.set_widths  s4      99;TYY
B?r:   c                     U R                  5       u  p#pEU R                  5       R                  U R                  X#XCU-   5        g)zh
Change the height of this space widget.

:param height: The new height.
:type height: int
:rtype: None
NrA  )r0   rM   ri   rj   rk   rl   s         r7   
set_heightSpaceWidget.set_height~  s4      99;TYYK@r:   c                     U R                   /$ r   r  rA   s    r7   r-   SpaceWidget._tags  r
  r:   c                     g)Nz[Space]r   rA   s    r7   r   SpaceWidget.__repr__  s    r:   r  N)r   r   r   r   r   r8   rB  rE  r-   r   r   r   r:   r7   r=  r=  T  s"    7*	@	Ar:   r=  c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ScrollWatcherWidgeti  z
A special canvas widget that adjusts its ``Canvas``'s scrollregion
to always include the bounding boxes of all of its children.  The
scroll-watcher widget will only increase the size of the
``Canvas``'s scrollregion; it will never decrease it.
c                 f    U H  nU R                  U5        M     [        R                  " X40 UD6  g)a  
Create a new scroll-watcher widget.

:type canvas: Tkinter.Canvas
:param canvas: This canvas widget's canvas.
:type children: list(CanvasWidget)
:param children: The canvas widgets watched by the
    scroll-watcher.  The scroll-watcher will ensure that these
    canvas widgets are always contained in their canvas's
    scrollregion.
:param attribs: The new canvas widget's attributes.
N)r   r   r8   r  s        r7   r8   ScrollWatcherWidget.__init__  s/     E""5) d6g6r:   c                 H    U R                  U5        U R                  U5        g)z
Add a new canvas widget to the scroll-watcher.  The
scroll-watcher will ensure that the new canvas widget is
always contained in its canvas's scrollregion.

:param canvaswidget: The new canvas widget.
:type canvaswidget: CanvasWidget
:rtype: None
N)r   rY   r0   canvaswidgets     r7   	add_childScrollWatcherWidget.add_child  s     	|,L!r:   c                 &    U R                  U5        g)a	  
Remove a canvas widget from the scroll-watcher.  The
scroll-watcher will no longer ensure that the new canvas
widget is always contained in its canvas's scrollregion.

:param canvaswidget: The canvas widget to remove.
:type canvaswidget: CanvasWidget
:rtype: None
N)r   rP  s     r7   r   ScrollWatcherWidget.remove_child  s     	!!,/r:   c                     / $ r   r   rA   s    r7   r-   ScrollWatcherWidget._tags  r  r:   c                 $    U R                  5         g r   )_adjust_scrollregionrw   s     r7   rv   ScrollWatcherWidget._update  s    !!#r:   c           	         U R                  5       nU R                  5       nUS   R                  5        Vs/ s H  n[        U5      PM     nn[	        U5      S:w  a  gUS   US   :  d$  US   US   :  d  US   US   :  d  US   US   :  aN  S[        US   US   5      [        US   US   5      [        US   US   5      [        US   US   5      4-  nXBS'   ggs  snf )	zs
Adjust the scrollregion of this scroll-watcher's ``Canvas`` to
include the bounding boxes of all of its children.
scrollregionr  Nr   rL   rD   rK   z%d %d %d %d)r@   r1   splitr  r=   minr  )r0   r@   r1   nr\  s        r7   rY  (ScrollWatcherWidget._adjust_scrollregion  s    
 yy{(.~(>(D(D(FG(F1A(FG|!Gl1o%Awa(Awa(Awa((DG\!_-DG\!_-DG\!_-DG\!_-	, L &2>" ) Hs   Cr   N)r   r   r   r   r   r8   rR  r  r-   rv   rY  r   r   r:   r7   rL  rL    s%    7""
0$2r:   rL  c                   r    \ rS rSrSrSS jrS rSS jrS rS r	SS	 jr
S
 rS rS r0 4S jrS rS rSrg)CanvasFramei  a'  
A ``Tkinter`` frame containing a canvas and scrollbars.
``CanvasFrame`` uses a ``ScrollWatcherWidget`` to ensure that all of
the canvas widgets contained on its canvas are within its
scrollregion.  In order for ``CanvasFrame`` to make these checks,
all canvas widgets must be registered with ``add_widget`` when they
are added to the canvas; and destroyed with ``destroy_widget`` when
they are no longer needed.

If a ``CanvasFrame`` is created with no parent, then it will create
its own main window, including a "Done" button and a "Print"
button.
Nc                 p  ^  Uc  [        5       T l        T R                  R                  S5        T R                  R                  SU 4S j5        T R                  R                  ST R                  5        T R                  R                  ST R                  5        OUT l        [        T R                  5      =T l        n[        U40 UD6=T l        n[        T R                  SS9n[        T R                  S	S9nUR                  US
'   UR                  US
'   UR                  US'   UR                  US'   UR                  SSS9  UR                  SSS9  UR                  SSSS9  SR                  US   US   5      nXtS'   [        U5      T l        Uc!  T R                  SSS9  T R#                  5         gg)aR  
Create a new ``CanvasFrame``.

:type parent: Tkinter.BaseWidget or Tkinter.Tk
:param parent: The parent ``Tkinter`` widget.  If no parent is
    specified, then ``CanvasFrame`` will create a new main
    window.
:param kw: Keyword arguments for the new ``Canvas``.  See the
    documentation for ``Tkinter.Canvas`` for more information.
NNLTKz<Control-p>c                 $   > TR                  5       $ r   )print_to_file)r8  r0   s    r7   <lambda>&CanvasFrame.__init__.<locals>.<lambda>  s    t7I7I7Kr:   z<Control-x><Control-q>
horizontalorientverticalrN  xscrollcommandrW  rg   rX  )r  rQ  rf   rO  rL   bothrU  expandr  rQ  z	0 0 {} {}rG   rM   r\  rq  r  )r   _parenttitler   rp   r	   _framer   _canvasr   xviewr^  r_  r]  formatrL  _scrollwatcher_init_menubar)r0   r2   kwframer1   
xscrollbar
yscrollbarr\  s   `       r7   r8   CanvasFrame.__init__  s    >4DLLLv&LLm-KLLLmT\\:LLmT\\:!DL $DLL11e &u 3 33vt{{<@
t{{:>
 &
9 &
9#->> #->> Sw/Sx0167 #))&/6(;KL!-~1&9 >IIQVI,  r:   c                    [        U R                  5      n[        USS9nUR                  SSU R                  SS9  UR                  SSU R                  SS9  UR                  S	SUS
9  U R                  R                  US9  g )Nr   )tearoffzPrint to PostscriptzCtrl-p)label	underlinerN  acceleratorExitrL   zCtrl-xFile)r  r  menu)r  )r   rs  add_commandrf  rp   add_cascadeconfig)r0   menubarfilemenus      r7   rz  CanvasFrame._init_menubar"  s    t||$+'&& 	 	 	
 	At|| 	 	
 	&AHE)r:   c                 d   Uc  SS/n[        USS9nU(       d  gU R                  5       u  p4pVU R                  R                  UUUS-   US-   US-   US-   SSS9nUR	                  S	S
5      n[        US5       nUR                  UR                  S5      5        SSS5        g! , (       d  f       g= f)z
Print the contents of this ``CanvasFrame`` to a postscript
file.  If no filename is given, then prompt the user for one.

:param filename: The name of the file to print the tree to.
:type filename: str
:rtype: None
N)zPostscript files.ps)z	All files*r  )	filetypesdefaultextensionrD   r   )rf   rg   rG   rM   	pagewidth
pageheightpagexpageyz 0 scalefont z 9 scalefont wbutf8)r   r\  rv  
postscriptreplaceopenwriteencode)	r0   filenameftypesx0y0r  hr  fs	            r7   rf  CanvasFrame.print_to_file3  s     13EFF(6ERH**,\\,,a%q5!e1u - 	

  ''I
(D!QGGJ%%f-. "!!s   7!B!!
B/c                     U R                   S   R                  5       u  pp4[        U5      [        U5      [        U5      [        U5      4$ )zo
:return: The current scroll region for the canvas managed by
    this ``CanvasFrame``.
:rtype: 4-tuple of int
r\  )rv  r]  r  )r0   ri   rj   rk   rl   s        r7   r\  CanvasFrame.scrollregionQ  s?      <<7==?BR#b'3r733r:   c                     U R                   $ )zM
:return: The canvas managed by this ``CanvasFrame``.
:rtype: Tkinter.Canvas
)rv  rA   s    r7   r1   CanvasFrame.canvasZ  s    
 ||r:   c                     Ub  Uc  U R                  XU5      u  p#UR                  5       u  pEpgUR                  X$-
  X5-
  5        U R                  R	                  U5        g)a  
Register a canvas widget with this ``CanvasFrame``.  The
``CanvasFrame`` will ensure that this canvas widget is always
within the ``Canvas``'s scrollregion.  If no coordinates are
given for the canvas widget, then the ``CanvasFrame`` will
attempt to find a clear area of the canvas for it.

:type canvaswidget: CanvasWidget
:param canvaswidget: The new canvas widget.  ``canvaswidget``
    must have been created on this ``CanvasFrame``'s canvas.
:type x: int
:param x: The initial x coordinate for the upper left hand
    corner of ``canvaswidget``, in the canvas's coordinate
    space.
:type y: int
:param y: The initial y coordinate for the upper left hand
    corner of ``canvaswidget``, in the canvas's coordinate
    space.
N)
_find_roomr@   rX   ry  rR  )r0   rQ  rf   rg   ri   rj   rk   rl   s           r7   
add_widgetCanvasFrame.add_widgeta  s^    ( 9	__\a8FQ (,,.!&!&) 	%%l3r:   c           	         U R                  5       u  pEpgUR                  5       nUR                  5       n	XU-
  :  a  gXU-
  :  a  gUR                  5       u  ppUR	                  XL-
  S-
  X]-
  S-
  5        Uba  Un[        XWU	-
  [        Xu-
  U	-
  S-  5      5       H;  nU R                  R                  US-
  US-
  X-   S-   X-   S-   5      (       a  M8  X4s  $    Uba  Un[        XFU-
  [        Xd-
  U-
  S-  5      5       H;  nU R                  R                  US-
  US-
  X-   S-   X-   S-   5      (       a  M8  X4s  $    [        XWU	-
  [        Xu-
  U	-
  S-  5      5       Hd  n[        XFU-
  [        Xd-
  U-
  S-  5      5       H=  nU R                  R                  US-
  US-
  X-   S-   X-   S-   5      (       a  M8  X4s  s  $    Mf     g)z)
Try to find a space for a given widget.
)r   r   2   r[  r   )	r\  rG   rM   r@   rX   ra  r  rv  find_overlapping)r0   r   	desired_x	desired_yrU  rI  rX  r  r  r  ri   rj   rk   rl   rf   rg   s                   r7   r  CanvasFrame._find_room  s    #'"3"3"5ELLNMMOs ";;=DINCHrM2 A3aci!mr-A)BC||44E1q5!%!)QUQY  6M	 D  A4C1AR0G,HI||44E1q5!%!)QUQY  6M	 J s!GS#)a-2)=%>?A4C1AR0G,HI||44E1q5!%!)QUQY  6M	 J @ r:   c                 F    U R                  U5        UR                  5         g)zi
Remove a canvas widget from this ``CanvasFrame``.  This
deregisters the canvas widget, and destroys it.
N)remove_widgetrp   rP  s     r7   destroy_widgetCanvasFrame.destroy_widget  s    
 	<(r:   c                 :    U R                   R                  U5        g r   )ry  r  rP  s     r7   r  CanvasFrame.remove_widget  s    ((6r:   c                 >    U R                   R                  " U40 UD6  g)z^
Pack this ``CanvasFrame``.  See the documentation for
``Tkinter.Pack`` for more information.
N)ru  r]  r0   cnfr{  s      r7   r]  CanvasFrame.pack  s    
 	##r:   c                 b    U R                   c  gU R                   R                  5         SU l         g)zv
Destroy this ``CanvasFrame``.  If this ``CanvasFrame`` created a
top-level window, then this will close that window.
N)rs  rp   r0   r8  s     r7   rp   CanvasFrame.destroy  s(    
 <<r:   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 frame is created from a non-interactive program (e.g.
from a secript); otherwise, the frame will close as soon as
the script completes.
N)r   rs  rd  r0   argskwargss      r7   rd  CanvasFrame.mainloop  s%     99t.v.r:   )rv  ru  rs  ry  r   NN)r   r   r   r   r   r8   rz  rf  r\  r1   r  r  r  r  r]  rp   rd  r   r   r:   r7   rb  rb    sJ    +!Z*"/<44<'R7  $	/r:   rb  c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
ShowTexti  z
A ``Tkinter`` window used to display a text.  ``ShowText`` is
typically used by graphical tools to display help text, or similar
information.
Nc                 <   Ub  Uc  U R                  X4U5      u  pEUc  [        5       =U l        nO[        U5      =U l        nUR	                  U5        [        USU R                  S9nUR                  SS9  [        U5      n	U	R                  SSS9  [        U	SS	9n
U
R                  S
SS9  [        U	4SXES.UD6nUR                  SU5        SUS'   UR                  SSSS9  UR                  U
S'   U
R                  US'   UR                  SU R                  5        UR                  SU R                  5        UR                  SU R                  5        UR                  SU R                  5        UR                  SU R                  5        U
R                  5         g )NOkrM  rO  rP  rL   ro  rr  rm  rk  rX  rg   rY  word)wraprG   rM   r\  disabledr   rU  )rQ  rq  r  rN  rW  rK  rf   r  <Return><Escape>)find_dimentionsr   _topr   rt  r   rp   r]  r	   r   r   rc  r^  r_  r   focus)r0   rootrt  r   rG   rM   textbox_optionsrI  btbf	scrollbartextboxs               r7   r8   ShowText.__init__  sj   =FN"224GOU < d"DI&tn,DI		%3T4<<8	HCj'c*5	G#.sWuWWud#%&8&}}	)$-MM ! 	dll#dll#dll#T\\*T\\* 	r:   c                    UR                  S5      nUc  [        S U 5       5      n[        US5      nSnU HE  n[        U5      U:  a.  US U R	                  S5      nXgS  nUS-  n[        U5      U:  a  M.  US-  nMG     [        US5      nX#4$ )N
c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r=   ).0lines     r7   	<genexpr>+ShowText.find_dimentions.<locals>.<genexpr>  s     73t99s   P   r    rL      )r]  r  r^  r=   rfind)r0   r   rG   rM   linesmaxwidthr  brks           r7   r  ShowText.find_dimentions  s    

4 =777H"%E Dd)e#6El((-Dz! d)e# aKF  VRr:   c                 b    U R                   c  g U R                   R                  5         S U l         g r   r  rp   r  s     r7   rp   ShowText.destroy  &    99			r:   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 window is created from a non-interactive program (e.g.
from a secript); otherwise, the window will close as soon as
the script completes.
N)r   r  rd  r  s      r7   rd  ShowText.mainloop  s%     99		D+F+r:   )r  r  )
r   r   r   r   r   r8   r  rp   rd  r   r   r:   r7   r  r    s    !F$	,r:   r  c                   B    \ rS rSrSr SS jrS rS rS rS r	S	 r
S
rg)EntryDialogi*  z
A dialog box for entering
Nc                    Xl         X l        X@l        [        [	        S[        U5      S-  S-  5      5      n[        U5      U l        U(       a  U R                  R                  U5        [        U R                  5      nUR                  SSSSSS9  U(       a  [        XsS	9nUR                  S
SSS9  [        XvS9U l        U R                  R                  SSSS9  U R                  R                  SU5        [        U R                  SSS9n	U	R                  SSSS9  [        U R                  5      n
U
R                  SSSSS9  [        U
SU R                   SS9nUR                  SSS9  [        U
SU R"                  SSS9nUR                  SSS9  [        U
SU R$                  SS9nUR                  SS9  U R                  R'                  S U R"                  5        U R                  R'                  S!U R                   5        U R                  R'                  S"U R                   5        U R                  R)                  5         g )#NrT  rK   rD   rL   ro  r   r[  )rq  r  padxpadyipadyr   rI  r  )rQ  rh   r  r  rf   )rq  r  r  r   sunken)borderwidthrelief)r  r  r  )rq  r  r  r  Cancelr  )r   rN  rG   rX  )rQ  r  r  active)r   rN  rG   defaultrU  ApplyrP  r  ri  r  )rs  _original_text_set_callbackr  r  r=   r   r  rt  r	   r]  r
   r   _entryrc  r   _cancel_ok_applyr   r  )r0   r2   original_textinstructionsset_callbackrt  rG   
entryframer  dividerbuttonsr  s               r7   r8   EntryDialog.__init__/  s    +)CC.2Q678V$	IIOOE" 499%
qvAARHj4AFFcF3J4"51m, 		qB#QR0 		"ACaa874<<qI	G!$7txxq(S	F#7$++QG	F		z488,		}dll3		z4<<0r:   c                     U R                   R                  SS5        U R                   R                  SU R                  5        U R                  (       a  U R	                  U R                  5        g g )Nr   r\  )r  rr   rc  r  r  r  s     r7   _resetEntryDialog._resetZ  sR    1e$1d112t223 r:   c                 T     U R                  5         U R                  5         g !    N= fr   )r	  _destroyr  s     r7   r  EntryDialog._cancel`  s%    	KKM 		s   # 'c                 D    U R                  5         U R                  5         g r   )r   r  r  s     r7   r  EntryDialog._okg  s    r:   c                 z    U R                   (       a*  U R                  U R                  R                  5       5        g g r   )r  r  getr  s     r7   r   EntryDialog._applyk  s)    t{{01 r:   c                 b    U R                   c  g U R                   R                  5         S U l         g r   r  r  s     r7   r  EntryDialog._destroyo  r  r:   )r  r  rs  r  r  )r;  r;  NN)r   r   r   r   r   r8   r	  r  r  r   r  r   r   r:   r7   r  r  *  s-    
 SW)V42r:   r  c                       \ rS rSrSr/ 4S jr\S 5       r\S 5       rSS jr	S r
SS	 jrS
 rS rS rS rSS jr0 4S jr0 4S jrS rS rS rS rS rSrg)ColorizedListi{  a  
An abstract base class for displaying a colorized list of items.
Subclasses should define:

- ``_init_colortags``, which sets up Text color tags that
  will be used by the list.
- ``_item_repr``, which returns a list of (text,colortag)
  tuples that make up the colorized representation of the
  item.

:note: Typically, you will want to register a callback for
    ``'select'`` that calls ``mark`` on the given item.
c                 2   Xl         0 U l        0 U l        U R                  UR	                  5       5        U R
                  R                  SU R                  5        U R
                  R                  SU R                  5        SU l	        U R                  U5        g)z
Construct a new list.

:param parent: The Tk widget that contains the colorized list
:param items: The initial contents of the colorized list.
:param options:
z
<KeyPress>z<ButtonPress>N)rs  
_callbacks_marks_init_itemframecopy_textwidgetr   	_keypress_buttonpress_itemsr_  )r0   r2   r+   optionss       r7   r8   ColorizedList.__init__  s{       	W\\^, 	lDNN;ot/@/@A r:   c                     g)z
Set up any colortags that will be used by this colorized list.
E.g.:
    textwidget.tag_config('terminal', foreground='black')
Nr   )r0   
textwidgetr   s      r7   _init_colortagsColorizedList._init_colortags  r   r:   c                     g)z
Return a list of (text, colortag) tuples that make up the
colorized representation of the item.  Colorized
representations may not span multiple lines.  I.e., the text
strings returned may not contain newline characters.
Nr   r0   items     r7   
_item_reprColorizedList._item_repr  r   r:   Nc                 D    Uc  U R                   SS $ U R                   U   $ )z6
:return: A list of the items contained by this list.
N)r  )r0   r  s     r7   r  ColorizedList.get  s&     =;;q>!;;u%%r:   c                 D   [        U5      nU R                  U:X  a  g[        U5      U l        SU R                  S'   U R                  R                  SS5        U Hb  nU R	                  U5       H.  u  p4SU;  d   S5       eU R                  R                  SX45        M0     U R                  R                  SS5        Md     U R                  R                  SS5        U R                  R                  S	S5        S
U R                  S'   U R                  R                  5         g)z2
Modify the list of items contained by this list.
Nr   r   1.0r\  r  z!item repr may not contain newlinez	end-1charrc  r  )	r*   r  r  rr   r)  rc  mark_setr  clear)r0   r+   r(  r   colortags        r7   r_  ColorizedList.set  s     U;;%5k$,!u-D"&//$"74'L)LL'  ''t> #8 ##E40	  	U3!!(E2$.!r:   c                     Uc8  U R                   R                  5         U R                  R                  SSS5        gU R                  R                  U5      nU R                   U	 SUS-   -  SUS-   -  pCU R                  R                  SX45        g)z
Remove highlighting from the given item; or from every item,
if no item is given.
:raise ValueError: If ``item`` is not contained in the list.
:raise KeyError: If ``item`` is not marked.
N	highlightr.  	end+1char%d.0rL   rD   )r  r0  r  
tag_remover  r  r0   r(  r  r  r\  s        r7   unmarkColorizedList.unmark  s     <KK''UKHKK%%d+ED!"eai0&EAI2FC''U@r:   c                     SU R                   U'   U R                  R                  U5      nSUS-   -  SUS-   -  pCU R                  R	                  SX45        g)zX
Highlight the given item.
:raise ValueError: If ``item`` is not contained in the list.
rL   r6  rD   r4  N)r  r  r  r  tag_addr8  s        r7   markColorizedList.mark  sU    
 D!!$'%!),f	.B  e9r:   c                 F    U R                  5         U R                  U5        g)zx
Remove any current highlighting, and mark the given item.
:raise ValueError: If ``item`` is not contained in the list.
N)r9  r=  r'  s     r7   markonlyColorizedList.markonly  s    
 			$r:   c                 |    U R                   R                  U5      nU R                  R                  SUS-   -  5        g)zh
Adjust the view such that the given item is visible.  If
the item is already visible, then do nothing.
r6  rL   N)r  r  r  see)r0   r(  r  s      r7   viewColorizedList.view  s5    
 !!$'Vuqy12r:   c                     US:X  a  / SQnOUS:X  a  / SQnOU/nU H"  nSU R                   R                  U0 5      U'   M$     g)a  
Register a callback function with the list.  This function
will be called whenever the given event occurs.

:param event: The event that will trigger the callback
    function.  Valid events are: click1, click2, click3,
    space, return, select, up, down, next, prior, move
:param func: The function that should be called when
    the event occurs.  ``func`` will be called with a
    single item as its argument.  (The item selected
    or the item moved to).
selectclick1r  returnrX   updownnextpriorrL   N)r  
setdefaultr0   r   funceventsr8  s        r7   add_callbackColorizedList.add_callback		  sI     H2Ff_4FWFA67DOO&&q"-d3 r:   c                     Uc$  [        U R                  R                  5       5      nOUS:X  a  / SQnOUS:X  a  / SQnOU/nU H&  nUc  U R                  U	 M   U R                  U   U	 M(     g!    M0  = f)zk
Deregister a callback function.  If ``func`` is none, then
all callbacks are removed for the given event.
NrG  rH  rX   rK  )r*   r  keysrQ  s        r7   remove_callbackColorizedList.remove_callback 	  s{    
 =$//..01Fh2Ff_4FWFA|OOA&*40 s   A..A3c                 >    U R                   R                  " U40 UD6  g r   )
_itemframer]  r  s      r7   r]  ColorizedList.pack;	  s    S'B'r:   c                 >    U R                   R                  " U/UQ76   g r   )r[  gridr  s      r7   r^  ColorizedList.grid?	  s    S&2&r:   c                 8    U R                   R                  5         g r   )r  r  rA   s    r7   r  ColorizedList.focusC	  s     r:   c                    [        U R                  5      U l        UR                  SS5        [	        U R                  40 UD6U l        [        U R                  SSS9U l        U R
                  R                  U R                  R                  S9  U R                  R                  U R
                  R                  S9  U R                  R                  SS	S
9  U R
                  R                  SSSS9  U R
                  R                  SSSSS9  U R                  U R
                  U5        U R
                  R                  SSS9  U R
                  R                  SSSSSS9  U R
                  R                  SS5        g )N
backgroundz#e0e0e0r   rm  )	takefocusrl  )rW  rV  rX  rg   rY  rL   ro  rU  rp  r4  z#e0ffff1raised)rc  borderr  selr;  )
foreground)ri  rc  rg  r  )r	   rs  r[  rP  r   r  r   _textscrollr  r_  r^  r]  r`  r$  r  )r0   r   s     r7   r  ColorizedList._init_itemframeK	  s\   - 	<3;7;$T__*Ut/?/?/C/CD(8(8(>(>?75QV&A 	##Ic( 	$ 	
 	T--w7 	##Eb#9##bRa 	$ 	
 	"";6r:   c                     XR                   ;  a  g SUs=::  a  [        U R                  5      :  a  O  OU R                  U   nOS n[        U R                   U   R	                  5       5       H  nU" U5        M     g )Nr   )r  r=   r  r*   rW  )r0   r   itemnumr(  cb_funcs        r7   _fire_callbackColorizedList._fire_callbackd	  s`    '*#dkk**;;w'DDDOOE2779:GDM ;r:   c                     SUR                   UR                  4-  nU R                  R                  U5      n[	        UR                  S5      S   5      S-
  nU R                  SUR                  -  U5        g )Nz@%d,%d.r   rL   zclick%d)rf   rg   r  r  r  r]  ro  r   )r0   r   clicklocinsert_pointrm  s        r7   r  ColorizedList._buttonpressn	  sg    uww00''--h7l((-a01A5I		17;r:   c                 \   UR                   S:X  d  UR                   S:X  af  U R                  R                  S5      n[        UR	                  S5      S   5      S-
  nU R                  UR                   R                  5       U5        g UR                   S:X  a  SnO:UR                   S	:X  a  S
nO'UR                   S:X  a  SnOUR                   S:X  a  SnOgU R                  R                  SSU-   5        U R                  R                  S5        U R                  R                  SSS5        U R                  R                  SSS5        U R                  R                  S5      n[        UR	                  S5      S   5      S-
  nU R                  UR                   R                  5       U5        g)NReturnr  rc  rr  r   rL   Downz+1lineUpz-1lineNextz+10linesPriorz-10linescontinuerh  r.  r5  zinsert linestartzinsert lineendbreak)keysymr  r  r  r]  ro  lowerr/  rC  r7  r<  )r0   r   rt  rm  deltas        r7   r  ColorizedList._keypresst	  sk   <<8#u||w'>++11(;L,,,S1!459G 2 2 4g>\\V#E\\T!E\\V#E\\W$E!!(Hu,<=X&##E5+>  (:<LM''--h7l((-a01A5ELL..0':r:   )r  r[  r  r  rs  rj  r  r   )r   r   r   r   r   r8   r   r$  r)  r  r_  r9  r=  r@  rD  rT  rX  r]  r^  r  r  ro  r  r  r   r   r:   r7   r  r  {  s     &( 8    &.A :38.6  (  '!72<r:   r  c                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
MutableOptionMenui	  c                    UR                  S5      U l        SU;   a  US	 [        5       =U l        n[	        U5      S:  a  UR                  US   5        SUS[        SSS.nUR                  U5        [        R                  " XSU5        SU l
        [        U S	SS
9U l        U R                  R                  U l        / U l        U H  nU R!                  U5        M     U R                  U S	'   g )NrN  r   rD   rL   r  )r  textvariableindicatoronr  rh   highlightthickness
menubuttontk_optionMenur  )r  r  )r  	_callbackr   	_variabler=   r_  r   rY   r   r8   
widgetNamer   _menu_wmenuname_valuesadd)r0   mastervaluesr   variabler{  r5   s          r7   r8   MutableOptionMenu.__init__	  s     Y/	" %.K/v;?LL# $"#
 			'lB7)$VQ7


EHHUO  zzVr:   c                    ^  UT R                   ;   a  g U4U 4S jjnT R                  R                  XS9  T R                   R                  U5        g )Nc                 (   > TR                  U 5        g r   )r_  )r5   r0   s    r7   r_  "MutableOptionMenu.add.<locals>.set	  s    HHUOr:   )r  rN  )r  r  r  r   )r0   r5   r_  s   `  r7   r  MutableOptionMenu.add	  sC    DLL  	 	

U8E"r:   c                     U R                   R                  U5        U R                  (       a  U R                  U5        g g r   )r  r_  r  )r0   r5   s     r7   r_  MutableOptionMenu.set	  s,    5!>>NN5! r:   c                     U R                   R                  U5      nU R                   U	 U R                  R                  X"5        g r   )r  r  r  rr   )r0   r5   rg  s      r7   r   MutableOptionMenu.remove	  s3    LLu%LLO

!r:   c                 R    US:X  a  U R                   $ [        R                  " X5      $ )Nr  )_MutableOptionMenu__menur   r   r~  s     r7   r   MutableOptionMenu.__getitem__	  s$    6>;;!!$--r:   c                 >    [         R                  " U 5        SU l        g)z,Destroy this widget and the associated menu.N)r   rp   r  rA   s    r7   rp   MutableOptionMenu.destroy	  s    4 
r:   )r  r  r  r  r  r  N)r   r   r   r   r8   r  r_  r   r   rp   r   r   r:   r7   r  r  	  s     "<#"
 .
r:   r  c                     S n S n[        SSSS9nUR                  5       n[        USSS9n[        US	SS
S9n[        X5SS9n[        USSS
S9n[	        X7SS9n[        X8SSSSS9n	[        U[        US5      [        US5      [        US5      [        US5      [        US5      [        US5      [        US5      5      n
[        USS5      n[        X9XKXjS
S9n[        USSS
S9n[        X<U5      n[        X>SSS9nUR                  USS5        U	R                  U 5        UR                  U5        UR                  U 5        UR                  U5        UR                  U5        UR                  5         g )!z;
A simple demonstration showing how to use canvas widgets.
c                 .    SSK Jn  SU" SS5      -  U S'   g )Nr   randintz#00%04d'  r  randomr  cwr  s     r7   r  demo.<locals>.fill	  s    "D!116
r:   c                 .    SSK Jn  SU" SS5      -  U S'   g )Nr   r  z#ff%04dr  r   r  r  s     r7   r   demo.<locals>.color	  s    "'!T"227r:   r[  i,  )closeenoughrG   rM   z
hiya thererL   )r   zo  o
||
___
  Ur  )r   r   redr  zo  o
||
\___/)r   cyanrK   )r  r   rG   r  r  rf   r!  zy: r1  rg   r   rT  )r  ztry clicking
and dragginggreen4)r   rG   <   N)rb  r1   r   r  r  r  r  r  r=  r$  r  r  r   rd  )r  r   cfr  ct3ct2coctcpr   equationr  cstack
prompt_msgcszzs                   r7   demor  	  sy   
2
3
 
3s	;B
		A
Q
2C
Q,8
LC	AE	*B	A)Q	IB	Q%	(B	1v!B	GB	Q!1cQ!1e1cQ
#1c	H 1b!EBIF	'1hJ 
:	.B	qHA	6BMM"b"MM$MM%MM$NN5NN5KKMr:   __main__N)*r   abcr   r   tkinterr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   tkinter.filedialogr   	nltk.utilr   r   r   r  rn  r  r  r  r  r  r$  r=  rL  rb  r  r  r  r  r  r   r   r:   r7   <module>r     s4  8 (     1 a
W a
RE) E)Pj: jZ7,l 7,t8' 8vv-( v-r4,) 4,n8,+ 8,vi&\ i&Xi&, i&X9, 9xN2, N2li/ i/bK, K,fI IbS Sv<
 <H0h zF r:   