
    g-Y                        d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d d       Z# G d! d"      Z$ G d# d$      Z% G d% d&      Z& G d' d(e      Z'd) Z(e)d*k(  r e(        y+y+),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                       e Zd ZdZd%dZd Zd Zd Zd Zd Z	d	 Z
d
 Zd&dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd'dZd Zd'dZd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"e#d"        Z$d# Z%d$ Z&y)(CanvasWidgeta-  
    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                    | j                   t        k(  rt        d      t        |t              st        d      || _        || _        t        | d      sg | _        d| _	        d| _
        d| _        dx| _        | _        i | _        d| _        t!        |j#                               D ]
  \  }}|| |<    | j%                          | j'                         D ]w  }| j
                  j)                  |d| j*                         | j
                  j)                  |d| j*                         | j
                  j)                  |d| j*                         y y)	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          C/var/www/openai/venv/lib/python3.12/site-packages/nltk/draw/util.py__init__zCanvasWidget.__init__   s    >>\)DEE&&)011 t67 DO   ())  0KD%DJ 1 	 ::<CMM""3(94??KMM""3(94??KMM""3(94??K      c                     | j                   ryt        | j                               dk(  rt        d       | j                  j
                  | j                          S )a  
        :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r/   s    r6   r>   zCanvasWidget.bbox   sI     ==tyy{q Y''!t}}!!499;//r8   c                     t        | j                               dk(  rt        d       | j                  j                  | j                          }|d   |d   z
  S )z
        :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>   r/   r>   s     r6   widthzCanvasWidget.width   Q     tyy{q Y''!t}}!!499;/Awa  r8   c                     t        | j                               dk(  rt        d       | j                  j                  | j                          }|d   |d   z
  S )z
        :return: The height of this canvas widget's bounding box, in
            its ``Canvas``'s coordinate space.
        :rtype: int
        r   r:         rB   rC   s     r6   heightzCanvasWidget.height  rE   r8   c                     | j                   S )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    r?   s    r6   r1   zCanvasWidget.parent  s     }}r8   c                     | j                   S )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   r?   s    r6   child_widgetszCanvasWidget.child_widgets  s     r8   c                     | j                   S )zi
        :return: The canvas that this canvas widget is bound to.
        :rtype: Tkinter.Canvas
        )r   r?   s    r6   r0   zCanvasWidget.canvas!      
 }}r8   c                     ||cxk(  rdk(  ry | j                         D ]  }| j                  j                  |||       ! | j                  r| j                  j	                  |        yy)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)r/   dxdyr5   s       r6   rP   zCanvasWidget.move(  s[     =q= 99;CMMsB+ ==MM  & r8   c                 H   | j                         \  }}}}|dk(  r| j                  ||z
  ||z
         |dk(  r!| j                  ||dz  z
  |dz  z
  ||z
         |dk(  r| j                  ||z
  ||z
         |dk(  r!| j                  ||z
  ||dz  z
  |dz  z
         |dk(  r| j                  ||z
  ||z
         |dk(  r!| j                  ||dz  z
  |dz  z
  ||z
         |dk(  r| j                  ||z
  ||z
         |d	k(  r"| j                  ||z
  ||dz  z
  |dz  z
         y
y
)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NrA   NEESESSWWN)r>   rP   )r/   xyanchorx1y1x2y2s           r6   movetozCanvasWidget.moveto>  s8    BBT>IIa"fa"f%S=IIa"q&j26)1r62T>IIa"fa"f%S=IIa"fa"q&j2612T>IIa"fa"f%S=IIa"q&j26)1r62T>IIa"fa"f%S=IIa"fa"q&j2612 r8   c                    | j                   | j                   j                          y| j                         D ]V  }| j                  j	                  |d       | j                  j	                  |d       | j                  j	                  |d       X  | j                  j
                  | j                           d| _        y)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r/   r5   s     r6   rf   zCanvasWidget.destroy^  s     ==$MM!!#99;CMM$$S*;<MM$$S*;<MM$$S*;<  	diik*r8   c                     | j                   s|j                   ry| j                  ryd| _        | j                  |       | j                  r| j                  j	                  |        d| _        y)a  
        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
        NrH   r   )r"   r#   _updater    rQ   r/   childs     r6   rQ   zCanvasWidget.updatew  sY     ==ENN ?? 	U ==MM  & r8   c                     | j                   ry| j                  D ]  }|j                           | j                          y)z^
        Arrange this canvas widget and all of its descendants.

        :rtype: None
        N)r"   r   manager+   rl   s     r6   ro   zCanvasWidget.manage  s.     ==__ELLN %r8   c                     | j                   t        d      g }|| j                         z  }| j                  D ]  }||j	                         z  } |S )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<   )r/   r<   rm   s      r6   r<   zCanvasWidget.tags  sR     == JKK

__EEJJL D %r8   c                 8    |dk(  r|| _         yt        d|z        )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=   r/   r3   r4   s      r6   __setitem__zCanvasWidget.__setitem__  s%     ;$D3d:;;r8   c                 @    |dk(  r| j                   S t        d|z        )z
        :return: the value of the attribute ``attr``.  See the class
            documentation for a list of attributes supported by this
            canvas widget.
        :rtype: (any)
        rr   rs   rt   r/   r3   s     r6   __getitem__zCanvasWidget.__getitem__  s)     ;###3d:;;r8   c                 4    d| j                   j                  z  S )z]
        :return: a string representation of this canvas widget.
        :rtype: str
        z<%s>)r   __name__r?   s    r6   __repr__zCanvasWidget.__repr__  s    
 ////r8   c                 v    d| _         | j                         D ]  }| j                  j                  |d       ! y)zL
        Temporarily hide this canvas widget.

        :rtype: None
        rH   hiddenstateNr"   r<   r   
itemconfigri   s     r6   hidezCanvasWidget.hide  2     99;CMM$$S$9 r8   c                 v    d| _         | j                         D ]  }| j                  j                  |d       ! y)zD
        Show a hidden canvas widget.

        :rtype: None
        r   normalr   Nr   ri   s     r6   showzCanvasWidget.show  r   r8   c                     | j                   S )zU
        :return: True if this canvas widget is hidden.
        :rtype: bool
        )r"   r?   s    r6   r~   zCanvasWidget.hidden  rN   r8   c                 "    || j                   |<   y)aF  
        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'   )r/   callbackbuttons      r6   
bind_clickzCanvasWidget.bind_click  s     $, r8   c                 0    d| _         || j                  d<   y)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.
        rH   dragN)r(   r'   )r/   r   s     r6   	bind_dragzCanvasWidget.bind_drag  s     #+ r8   c                 .    	 | j                   |= y#  Y yxY w)a.  
        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   )r/   r   s     r6   unbind_clickzCanvasWidget.unbind_click
  s    	  (	    c                 .    	 | j                   d= y#  Y yxY w)zK
        Remove a callback that was registered with ``bind_drag``.
        r   Nr   r?   s    r6   unbind_dragzCanvasWidget.unbind_drag  s    	  (	r   c                    | j                   j                  d      s6| j                   j                  d      s| j                   j                  d      ry| j                   j                  d       || _        |j                  dk(  r.| }|*|d   r|j                  |       n|j                         }|*| j                   j                  d|j                  z  | j                         y)	a  
        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>rH   rr   <ButtonRelease-%d>)r   bindunbindr$   num_CanvasWidget__start_dragr1   _CanvasWidget__release_cb)r/   eventwidgets      r6   
__press_cbzCanvasWidget.__press_cb%  s     MM23}}!!"56}}!!"56 	Z(  99>F$+&''.	 $ 	/%));T=N=NOr8   c                     | j                   j                  d| j                         |j                  | _        |j
                  | _        y)z|
        Begin dragging this object:
          - register a motion callback
          - record the drag coordinates
        r   N)r   r   _CanvasWidget__motion_cbr]   r%   r^   r&   r/   r   s     r6   __start_dragzCanvasWidget.__start_dragI  s4     	:t'7'78r8   c                     | j                  |j                  | j                  z
  |j                  | j                  z
         |j                  | _        |j                  | _        y)z
        Handle a motion event:
          - move this object to the new location
          - record the new drag coordinates
        N)rP   r]   r%   r^   r&   r   s     r6   __motion_cbzCanvasWidget.__motion_cbS  sB     			%''DMM)577T]]+BCr8   c                    | j                   j                  d|j                  z         | j                   j                  d       |j                  | j                  j                  z
  dk  rt        |j                  | j                  j                  z
        t        |j                  | j                  j                  z
        z   dk  r| j                  rc|j                  dk(  rT| j                  | j                  j                  | j                  z
  | j                  j                  | j                  z
         | j                  |j                         d| _        y|j                  dk(  r| j                          d| _        y)z
        Handle a release callback:
          - unregister motion & button release callbacks.
          - decide whether they clicked, dragged, or cancelled
          - call the appropriate handler.
        r   r   d      rH   N)r   r   r   timer$   absr]   r^   r(   rP   r%   r&   _CanvasWidget__click_CanvasWidget__dragr   s     r6   __release_cbzCanvasWidget.__release_cb]  s	    	1EII=>Z( JJ***S0EGGdllnn,-EGGdllnn4L0MMPQQ EIIN		LLNNT]]2DLLNNT]]4R LL#  YY!^KKMr8   c                     | j                   r(d| j                  v r| j                  d   }	  ||        yy| j                  | j                  j	                          yy#  t        d| z         Y yxY w)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   )r/   cbs     r6   __dragzCanvasWidget.__dragx  st     )))%%f-BtH * ]]&MM  " 'B9D@As   A A/c                     || j                   v r| j                   |   } ||        y| j                  | j                  j                  |       yy)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   )r/   r   r   s      r6   __clickzCanvasWidget.__click  sL     T%%%!!&)BtH ]]&MM!!&) 'r8   c                     t        | d      sg | _        |j                  t        | d      | |_        | j                  j	                  |       y)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=   appendrl   s     r6   _add_child_widgetzCanvasWidget._add_child_widget  sL     t67 DO>>%w&;<==u%r8   c                 H    | j                   j                  |       d|_        y)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    rl   s     r6   _remove_child_widgetz!CanvasWidget._remove_child_widget  s     	u%r8   c                      y)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 r?   s    r6   r,   zCanvasWidget._tags      r8   c                      y)a  
        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   r?   s    r6   r+   zCanvasWidget._manage  r   r8   c                      y)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   rl   s     r6   rk   zCanvasWidget._update  r   r8   N)rU   )rH   )'r{   
__module____qualname____doc__r7   r>   rD   rI   r1   rL   r0   rP   rd   rf   rQ   ro   r<   rv   ry   r|   r   r   r~   r   r   r   r   r.   r   r   r   r   r   r   r   r   r,   r+   rk   r   r8   r6   r   r   >   s    qf2Lp0	!	!',3@26
<
<0::, ,"PH  6# *(&((  r8   r   )	metaclassc                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)

TextWidgeta  
    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                 r    || _         |j                  dd|      | _        t        j                  | |fi | y)a  
        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.
        rH   textN)_textcreate_text_tagr   r7   )r/   r0   r   r2   s       r6   r7   zTextWidget.__init__  s9     
&&q!$&7	dF6g6r8   c                     |dv r4|dk(  rd}| j                         j                  | j                  ||i       y t        j	                  | ||       y )N)colorfontjustifyrD   r   fill)r0   r   r   r   rv   ru   s      r6   rv   zTextWidget.__setitem__  sG    88wKKM$$TYYu>$$T47r8   c                    |dk(  r3t        | j                         j                  | j                  |            S |dv r1|dk(  rd}| j                         j                  | j                  |      S t        j                  | |      S )NrD   )r   r   r   r   r   )intr0   itemcgetr   r   ry   rx   s     r6   ry   zTextWidget.__getitem__  sp    7?t{{}--dii>??11w;;=))$))T::++D$77r8   c                     | j                   gS r   r   r?   s    r6   r,   zTextWidget._tags      		{r8   c                 V    | j                         j                  | j                  d      S )zV
        :return: The text displayed by this text widget.
        :rtype: str
        TEXT)r0   r   r   r?   s    r6   r   zTextWidget.text  s!    
 {{}%%dii88r8   c                     | j                         j                  | j                  |       | j                          | j                         j	                  |        yy)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)r0   r   r   r1   rQ   )r/   r   s     r6   set_textzTextWidget.set_text  sF     	   6;;=$KKM  & %r8   c                      d| j                   z  S )Nz
[Text: %r])r   r?   s    r6   r|   zTextWidget.__repr__+  s    djj((r8   N)r{   r   r   r   r7   rv   ry   r,   r   r   r|   r   r8   r6   r   r     s*    7889
')r8   r   c                       e Zd ZdZi dddddddd	d
dddddddddddddddd ed      ddddd d!d"d#d$d%iZd& Zd' Zd( Zd) Z	e
d,d*       Zy+)-SymbolWidgeta  
    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                 `    d|d<   t        j                  | |dfi | | j                  |       y)a  
        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   r7   
set_symbol)r/   r0   r  r2   s       r6   r7   zSymbolWidget.__init__V  s0     #D&"88r8   c                     | j                   S )zz
        :return: the name of the symbol that is displayed by this
            symbol widget.
        :rtype: str
        _symbolr?   s    r6   r  zSymbolWidget.symbold  s     ||r8   c                     |t         j                  vrt        d|z        || _        | j	                  t         j                  |          y)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   )r/   r  s     r6   r  zSymbolWidget.set_symboll  sA     ---1F:;;l**623r8   c                      d| j                   z  S )Nz[Symbol: %r]r  r?   s    r6   r|   zSymbolWidget.__repr__x  s    ,,r8   c                    t               }|fd}|j                  d|       t        |d|j                        j	                  d       t        |d|  fdd	
      }|j	                  d       t        ||j                        }|j                  |d<   |j	                  dd       |j                  dd|  f       t        d      D ]  }|dv rt        t        j                  j                               D ]*  \  }}|t        |      k(  s|j!                  dd|z          n |j!                  dd|z         |j!                  ddt        |      z  d        |j#                          y)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                 $    |j                          y r   )rf   )r  tops     r6   rf   z)SymbolWidget.symbolsheet.<locals>.destroy  s    KKMr8   qQuitr   commandbottomside	helvetica      )r   rD   rI   leftr  yscrollcommandrightr^   r  r   r  )r      )r   
   endz%-10s	z%-10d  	z[%s]
N)r   r   r   rf   packr   r   yviewset
tag_configranger)   r   r  r*   chrinsertmainloop)sizer  rf   r   sbikvs           r6   symbolsheetzSymbolWidget.symbolsheet{  s>    d 	 	gs5:::IC{TE2"RH		v	sDJJ/!#
W3'4%'89sAG|\11779:1A;KKy1}5 ;
 E;?3KKx#a&0(;  	r8   N)r  )r{   r   r   r   r'  r  r7   r  r  r|   staticmethodr/  r   r8   r6   r   r   /  s   "v 	 	&	
 	 	& 	& 	F 	& 	V 	F 	v 	c#h 	 	F  	!" 	#$ 	3%G* 
4-  r8   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)AbstractContainerWidgeta  
    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                 b    || _         | j                  |       t        j                  | |fi | y)a  
        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   r7   r/   r0   rm   r2   s       r6   r7   z AbstractContainerWidget.__init__  s.     u%dF6g6r8   c                 :    | j                  | j                         y r   )rk   r4  r?   s    r6   r+   zAbstractContainerWidget._manage  s    T[[!r8   c                     | j                   S )zl
        :return: The child widget contained by this container widget.
        :rtype: CanvasWidget
        )r4  r?   s    r6   rm   zAbstractContainerWidget.child  s    
 {{r8   c                     | j                  | j                         | j                  |       || _        | j                  |       y)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   r4  r   rQ   rl   s     r6   	set_childz!AbstractContainerWidget.set_child  s7     	!!$++.u%Er8   c                 n    | j                   j                  }|dd  dk(  r|d d }d| d| j                  dS )Nir   [z: ])r   r{   r4  r/   names     r6   r|   z AbstractContainerWidget.__repr__  sC    ~~&&9 9D4&4;;/++r8   N)	r{   r   r   r   r7   r+   rm   r9  r|   r   r8   r6   r2  r2    s     7 ",r8   r2  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)	BoxWidgeta  
    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                     || _         d| _        |j                  dddd      | _        |j	                  | j                         t        j                  | ||fi | y)a9  
        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.
        rH   N)r4  _margincreate_rectangle_box	tag_lowerr2  r7   r5  s       r6   r7   zBoxWidget.__init__  sS     ++Aq!Q7	#((vuHHr8   c                     |dk(  r|| _         y |dv r-| j                         j                  | j                  ||i       y t        j                  | ||       y )Nmarginoutliner   rD   )rB  r0   r   rD  r   rv   ru   s      r6   rv   zBoxWidget.__setitem__  sJ    8 DL11KKM$$TYYu>$$T47r8   c                    |dk(  r| j                   S |dk(  r3t        | j                         j                  | j                  |            S |dv r*| j                         j                  | j                  |      S t
        j                  | |      S )NrG  rD   rH  )rB  floatr0   r   rD  r   ry   rx   s     r6   ry   zBoxWidget.__getitem__  sv    8<<W_//		4@AA11;;=))$))T::++D$77r8   c                     |j                         \  }}}}| j                  | d   dz  z   }| j                         j                  | j                  ||z
  ||z
  ||z   ||z          y )NrD   rA   )r>   rB  r0   coordsrD  )r/   rm   r`   ra   rb   rc   rG  s          r6   rk   zBoxWidget._update  s`     ::<RRW 11IIrF{BKfb6k	
r8   c                     | j                   gS r   )rD  r?   s    r6   r,   zBoxWidget._tags  r   r8   N	r{   r   r   r   r7   rv   ry   rk   r,   r   r8   r6   r@  r@    s!    
I"88
r8   r@  c                   2    e Zd ZdZd Zd Zd ZdZd Zd Z	y)	
OvalWidgeta  
    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                 n   || _         d| _        |j                  dddd      | _        |j	                  dd      | _        |j	                  dd      | _        | j                  r|j                  dddd      | _        nd| _        |j                  | j                         t        j                  | ||fi | y)a:  
        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.
        rH   circleFdoubleN)r4  rB  create_oval_ovalpop_circle_double_oval2rE  r2  r7   r5  s       r6   r7   zOvalWidget.__init__  s     ''1a3
{{8U3{{8U3<< ,,Q1a8DKDK$((vuHHr8   c                 d   | j                         }|dk(  r|| _        y |dk(  r|dk(  r| j                  |j                  | j                        \  }}}}| d   dz  }|j                  ||z
  ||z
  ||z   ||z   |j                  | j                  d      |j                  | j                  d            | _        |j                  | j                         |dk(  r0| j                  #|j                  | j                         d | _        y y y |d	v r|j                  | j                  ||i       | j                  #|d
k7  r|j                  | j                  ||i       | j                  3|d
k7  r-| j                         j                  | j                  ||i       y y y t        j                  | ||       y )NrG  rT  TrD   rA   rI  )rI  rD   FrH  r   )r0   rB  rZ  r>   rV  rU  r   rE  rh   r   r   rv   )	r/   r3   r4   cr`   ra   rb   rc   ws	            r6   rv   zOvalWidget.__setitem__6  s   KKM8 DLX}!4!"

!3BBMA%mmFFFFJJtzz9=**TZZ9 ,  DKK(~$++"9%" #:~ 11LLdE]3{{&46>T[[4-8{{&46>((tUmD ,:& $$T47r8   c                 B   |dk(  r| j                   S |dk(  r| j                  d uS |dk(  r3t        | j                         j	                  | j
                  |            S |dv r*| j                         j	                  | j
                  |      S t        j                  | |      S )NrG  rT  rD   rH  )rB  rY  rK  r0   r   rV  r   ry   rx   s     r6   ry   zOvalWidget.__getitem__T  s    8<<X<<t++W_//

DABB11;;=))$**d;;++D$77r8   g;f?c                    t         j                  }|j                         \  }}}}| j                  }| j                  rWt        ||z
        t        ||z
        }	}||	kD  r||z   dz  }
|
|dz  z
  |
|dz  z   }}n|	|kD  r||z   dz  }||	dz  z
  ||	dz  z   }}t        |d|z   z  |d|z
  z  z   dz        }|t        ||z
  |z        z   }t        |d|z   z  |d|z
  z  z   dz        }|t        ||z
  |z        z   }| j                         j                  | j                  ||z
  ||z
  ||z   ||z          | j                  F| j                         j                  | j                  ||z
  dz   ||z
  dz   ||z   dz
  ||z   dz
         y y )NrA   rH   )rQ  RATIOr>   rB  rX  r   r   r0   rM  rV  rZ  )r/   rm   Rr`   ra   rb   rc   rG  rR   rS   r^   r]   r  r  r  bots                   r6   rk   zOvalWidget._updatec  s    ::<RR <<b\3rBw<BBw"WMR!VQaZBb"WMR!VQaZB B!a%L2Q</145sBGq=))2Q<"A,.!34CbA&&JJvsV|UV^S6\	
 ;;"KKM  v!fq "fq  #r8   c                 d    | j                   | j                  gS | j                  | j                   gS r   )rZ  rV  r?   s    r6   r,   zOvalWidget._tags  s+    ;;JJ<JJ,,r8   N)
r{   r   r   r   r7   rv   ry   r`  rk   r,   r   r8   r6   rQ  rQ    s)    I.8<
8 E@-r8   rQ  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)ParenWidgeta  
    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           	          || _         |j                  ddddddd      | _        |j                  ddddddd      | _        t	        j
                  | ||fi | y)aA  
        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.
        rH   arcZ      )stylestartextentiN)r4  
create_arc_oparen_cparenr2  r7   r5  s       r6   r7   zParenWidget.__init__  sf     ((Aq!5SV(W((Aq!5TW(X((vuHHr8   c                    |dk(  rW| j                         j                  | j                  |       | j                         j                  | j                  |       y |dk(  rW| j                         j                  | j                  |       | j                         j                  | j                  |       y t        j                  | ||       y )Nr   rI  rD   rD   )r0   r   rn  ro  r   rv   ru   s      r6   rv   zParenWidget.__setitem__  s    7?KKM$$T\\5$AKKM$$T\\5$AW_KKM$$T\\$?KKM$$T\\$?$$T47r8   c                     |dk(  r*| j                         j                  | j                  d      S |dk(  r*| j                         j                  | j                  d      S t        j	                  | |      S Nr   rI  rD   )r0   r   rn  r   ry   rx   s     r6   ry   zParenWidget.__getitem__  ]    7?;;=))$,,	BBW_;;=))$,,@@++D$77r8   c                    |j                         \  }}}}t        ||z
  dz  d      }| j                         j                  | j                  ||z
  |||z   |       | j                         j                  | j
                  ||z
  |||z   |       y )N      )r>   maxr0   rM  rn  ro  r/   rm   r`   ra   rb   rc   rD   s          r6   rk   zParenWidget._update  sz     ::<RRR"WM1%T\\2:r2:rJT\\2:r2:rJr8   c                 2    | j                   | j                  gS r   )rn  ro  r?   s    r6   r,   zParenWidget._tags      dll++r8   NrO  r   r8   r6   re  re    s"    I 88K,r8   re  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)BracketWidgeta  
    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           
          || _         |j                  dddddddd      | _        |j                  dddddddd      | _        t	        j
                  | ||fi | y)a=  
        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.
        rH   N)r4  create_line_obrack_cbrackr2  r7   r5  s       r6   r7   zBracketWidget.__init__  sb     ))!Q1aAqA))!Q1aAqA((vuHHr8   c                    |dk(  rW| j                         j                  | j                  |       | j                         j                  | j                  |       y |dk(  rW| j                         j                  | j                  |       | j                         j                  | j                  |       y t        j                  | ||       y )Nr   r   rD   rr  )r0   r   r  r  r   rv   ru   s      r6   rv   zBracketWidget.__setitem__  s    7?KKM$$T\\$>KKM$$T\\$>W_KKM$$T\\$?KKM$$T\\$?$$T47r8   c                     |dk(  r*| j                         j                  | j                  d      S |dk(  r*| j                         j                  | j                  d      S t        j	                  | |      S rt  )r0   r   r  r   ry   rx   s     r6   ry   zBracketWidget.__getitem__  ru  r8   c                 .   |j                         \  }}}}t        ||z
  dz  d      }| j                         j                  | j                  ||||z
  |||z
  |||	       | j                         j                  | j
                  ||||z   |||z   |||	       y )N   rA   )r>   ry  r0   rM  r  r  rz  s          r6   rk   zBracketWidget._update  s     ::<RRR"WM1%LL"b"u*b"u*b"b	
 	LL"b"u*b"u*b"b	
r8   c                 2    | j                   | j                  gS r   )r  r  r?   s    r6   r,   zBracketWidget._tags  r|  r8   NrO  r   r8   r6   r~  r~    s!    I 88
,r8   r~  c                   j    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zej                  Zd
 Zd Zd Zy)SequenceWidgeta  
    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                     d| _         d| _        d| _        t        |      | _        |D ]  }| j                  |        t        j                  | |fi | y)aj  
        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.
        centerrH   FN_align_space_orderedr)   	_childrenr   r   r7   r/   r0   childrenr2   rm   s        r6   r7   zSequenceWidget.__init__  Q     hE""5) dF6g6r8   c                     |dk(  r|dvrt        d|z        || _        y |dk(  r|| _        y |dk(  r|| _        y t        j                  | ||       y )Nalign)r  r  r  Bad alignment: %rspaceorderedr=   r  r  r  r   rv   ru   s      r6   rv   zSequenceWidget.__setitem__  Y    7?77 !4u!<==DKW_DKY!DM$$T47r8   c                     |dk(  r| j                   S |dk(  r| j                  S |dk(  r| j                  S t        j	                  | |      S Nr  r  r  r  r  r  r   ry   rx   s     r6   ry   zSequenceWidget.__getitem__*  I    7?;;W_;;Y== ++D$77r8   c                     g S r   r   r?   s    r6   r,   zSequenceWidget._tags4      	r8   c                 v    | j                   dk(  r|S | j                   dk(  r|S | j                   dk(  r||z   dz  S y )Nr  r  r  rA   r  )r/   r  rb  s      r6   _yalignzSequenceWidget._yalign7  sC    ;;%J;;("J;;("#I?" #r8   c           	         |j                         \  }}}}| j                  ||      }| j                  D ]<  }|j                         \  }}	}
}|j                  d|| j                  |	|      z
         > | j                  rNt        | j                        dkD  r4| j                  j                  |      }|| j                  z   }t        |dz   t        | j                              D ]a  }| j                  |   j                         \  }}	}
}||kD  s+| j                  |   j                  ||z
  d       ||
|z
  | j                  z   z  }c || j                  z
  }t        |dz
  dd      D ]a  }| j                  |   j                         \  }}	}
}||
k  s+| j                  |   j                  ||
z
  d       ||
|z
  | j                  z   z  }c y y y Nr   rH   )	r>   r  r  rP   r  r;   indexr  r&  )r/   rm   r  r  r  rb  r^   r\  r`   ra   rb   rc   r  r]   r,  s                  r6   rk   zSequenceWidget._update?  s   "'**,sE3LLc"A vvxRRFF1a$,,r2../   ==S014NN((/E#A519c$..&9:#'>>!#4#9#9#; RRr6NN1%**1r615b4;;..A	 ; t{{"A519b"-#'>>!#4#9#9#; RRr6NN1%**1r615b4;;..A	 . 5=r8   c           	      <   t        | j                        dk(  ry | j                  d   }|j                         \  }}}}| j                  ||      }| j                  j	                  |      }|| j
                  z   }t        |dz   t        | j                              D ]n  }	| j                  |	   j                         \  }
}}}| j                  |	   j                  ||
z
  || j                  ||      z
         |||
z
  | j
                  z   z  }p || j
                  z
  }t        |dz
  dd      D ]n  }	| j                  |	   j                         \  }
}}}| j                  |	   j                  ||z
  || j                  ||      z
         |||
z
  | j
                  z   z  }p y r  )r;   r  r>   r  r  r  r&  rP   )r/   rm   r  r  r  rb  r^   r  r]   r,  r`   ra   rb   rc   s                 r6   r+   zSequenceWidget._manageX  s{   t~~!#q! #(**,sE3LLc"$$U+ DKKuqy#dnn"56A#~~a0557RRNN1""1r61t||B/C+CDb4;;&&A 7 4;;uqy"b)A#~~a0557RRNN1""1r61t||B/C+CDb4;;&&A *r8   c                 >    dt        | j                        dd z   dz   S )Nz[Sequence: rH   r  r<  reprr  r?   s    r6   r|   zSequenceWidget.__repr__q  s"    tDNN3Ab99C??r8   c                     | j                   j                  |      }|| j                   |<   | j                  |       | j                  |       | j	                  |       ya  
        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   rQ   r/   oldchildnewchildr  s       r6   replace_childzSequenceWidget.replace_childw  N     $$X. (u!!(+x(Hr8   c                     | j                   j                  |      }| j                   |= | j                  |       t        | j                         dkD  r| j	                  | j                   d          yy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;   rQ   r/   rm   r  s      r6   remove_childzSequenceWidget.remove_child  ]     $$U+NN5!!!%(t~~"KKq)* #r8   c                 ^    | j                   j                  ||       | j                  |       y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  r(  r   r/   r  rm   s      r6   insert_childzSequenceWidget.insert_child  &     	eU+u%r8   N)r{   r   r   r   r7   rv   ry   r,   r  rk   r+   r|   r   rL   r  r  r  r  r   r8   r6   r  r    sL    7&
88#/2'2@ ))H$+&r8   r  c                   j    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zej                  Zd
 Zd Zd Zy)StackWidgeta  
    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                     d| _         d| _        d| _        t        |      | _        |D ]  }| j                  |        t        j                  | |fi | y)ae  
        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  rH   FNr  r  s        r6   r7   zStackWidget.__init__  r  r8   c                     |dk(  r|dvrt        d|z        || _        y |dk(  r|| _        y |dk(  r|| _        y t        j                  | ||       y )Nr  )r  r  r  r  r  r  r  ru   s      r6   rv   zStackWidget.__setitem__  r  r8   c                     |dk(  r| j                   S |dk(  r| j                  S |dk(  r| j                  S t        j	                  | |      S r  r  rx   s     r6   ry   zStackWidget.__getitem__  r  r8   c                     g S r   r   r?   s    r6   r,   zStackWidget._tags  r  r8   c                 v    | j                   dk(  r|S | j                   dk(  r|S | j                   dk(  r||z   dz  S y )Nr  r  r  rA   r  )r/   r  r  s      r6   _xalignzStackWidget._xalign  sD    ;;& K;;'!L;;("5LA%% #r8   c                    |j                         \  }}}}| j                  ||      }| j                  D ]<  }|j                         \  }}	}
}|j                  || j                  ||
      z
  d       > | j                  rNt        | j                        dkD  r4| j                  j                  |      }|| j                  z   }t        |dz   t        | j                              D ]a  }| j                  |   j                         \  }}	}
}||	kD  s+| j                  |   j                  d||	z
         |||	z
  | j                  z   z  }c || j                  z
  }t        |dz
  dd      D ]a  }| j                  |   j                         \  }}	}
}||k  s+| j                  |   j                  d||z
         |||	z
  | j                  z   z  }c y y y r  )	r>   r  r  rP   r  r;   r  r  r&  )r/   rm   r  r  r  rb  r]   r\  r`   ra   rb   rc   r  r^   r,  s                  r6   rk   zStackWidget._update  s   "'**,sE3LLu%A vvxRRFF1t||B++Q/   ==S014NN((/Edkk!A519c$..&9:#'>>!#4#9#9#; RRr6NN1%**1a"f5b4;;..A	 ; dkk!A519b"-#'>>!#4#9#9#; RRr6NN1%**1a"f5b4;;..A	 . 5=r8   c                 <   t        | j                        dk(  ry | j                  d   }|j                         \  }}}}| j                  ||      }| j                  j	                  |      }|| j
                  z   }t        |dz   t        | j                              D ]n  }	| j                  |	   j                         \  }
}}}| j                  |	   j                  || j                  |
|      z
  ||z
         |||z
  | j
                  z   z  }p || j
                  z
  }t        |dz
  dd      D ]n  }	| j                  |	   j                         \  }
}}}| j                  |	   j                  || j                  |
|      z
  ||z
         |||z
  | j
                  z   z  }p y r  )r;   r  r>   r  r  r  r&  rP   )r/   rm   r  r  r  rb  r]   r  r^   r,  r`   ra   rb   rc   s                 r6   r+   zStackWidget._manage  s{   t~~!#q! #(**,sE3LLu%$$U+ $++uqy#dnn"56A#~~a0557RRNN1""1t||B';#;QVDb4;;&&A 7 $++uqy"b)A#~~a0557RRNN1""1t||B';#;QVDb4;;&&A *r8   c                 >    dt        | j                        dd z   dz   S )Nz[Stack: rH   r  r<  r  r?   s    r6   r|   zStackWidget.__repr__  s"    D0266<<r8   c                     | j                   j                  |      }|| j                   |<   | j                  |       | j                  |       | j	                  |       yr  r  r  s       r6   r  zStackWidget.replace_child#  r  r8   c                     | j                   j                  |      }| j                   |= | j                  |       t        | j                         dkD  r| j	                  | j                   d          yyr  r  r  s      r6   r  zStackWidget.remove_child5  r  r8   c                 ^    | j                   j                  ||       | j                  |       yr  r  r  s      r6   r  zStackWidget.insert_childC  r  r8   N)r{   r   r   r   r7   rv   ry   r,   r  rk   r+   r|   r   rL   r  r  r  r  r   r8   r6   r  r    sK    7&
88&/2'2= ))H$+&r8   r  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)SpaceWidgetah  
    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                     |dkD  r|dz  }|dkD  r|dz  }|j                  dd||d      | _        t        j                  | |fi | y)ai  
        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.
        rx  rH   r  r  N)r  r   r   r7   )r/   r0   rD   rI   r2   s        r6   r7   zSpaceWidget.__init__^  sV     19QJEA:aKF&&q!UF&D	dF6g6r8   c                     | j                         \  }}}}| j                         j                  | j                  ||||z   |       y)z
        Change the width of this space widget.

        :param width: The new width.
        :type width: int
        :rtype: None
        Nr>   r0   rM  r   )r/   rD   r`   ra   rb   rc   s         r6   	set_widthzSpaceWidget.set_widths  s<      99;RRTYYBU
B?r8   c                     | j                         \  }}}}| j                         j                  | j                  |||||z          y)z
        Change the height of this space widget.

        :param height: The new height.
        :type height: int
        :rtype: None
        Nr  )r/   rI   r`   ra   rb   rc   s         r6   
set_heightzSpaceWidget.set_height~  s<      99;RRTYYBBK@r8   c                     | j                   gS r   r   r?   s    r6   r,   zSpaceWidget._tags  r   r8   c                      y)Nz[Space]r   r?   s    r6   r|   zSpaceWidget.__repr__  s    r8   N)	r{   r   r   r   r7   r  r  r,   r|   r   r8   r6   r  r  T  s"    7*	@	Ar8   r  c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	ScrollWatcherWidgeta	  
    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                 b    |D ]  }| j                  |        t        j                  | |fi | y)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   r7   r  s        r6   r7   zScrollWatcherWidget.__init__  s1     E""5) dF6g6r8   c                 H    | j                  |       | j                  |       y)a0  
        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   rQ   r/   canvaswidgets     r6   	add_childzScrollWatcherWidget.add_child  s     	|,L!r8   c                 &    | j                  |       y)aA  
        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   r  s     r6   r  z ScrollWatcherWidget.remove_child  s     	!!,/r8   c                     g S r   r   r?   s    r6   r,   zScrollWatcherWidget._tags  r  r8   c                 $    | j                          y r   )_adjust_scrollregionrl   s     r6   rk   zScrollWatcherWidget._update  s    !!#r8   c           	         | j                         }| j                         }|d   j                         D cg c]  }t        |       }}t	        |      dk7  ry|d   |d   k  s!|d   |d   k  s|d   |d   kD  s|d   |d   kD  rOdt        |d   |d         t        |d   |d         t        |d   |d         t        |d   |d         fz  }||d<   yyc c}w )	z
        Adjust the scrollregion of this scroll-watcher's ``Canvas`` to
        include the bounding boxes of all of its children.
        scrollregionrx  Nr   rH   rA   rG   z%d %d %d %d)r>   r0   splitr   r;   minry  )r/   r>   r0   nr  s        r6   r  z(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 &2F>" ) Hs   CN)
r{   r   r   r   r7   r  r  r,   rk   r  r   r8   r6   r  r    s%    7""
0$2r8   r  c                   b    e Zd ZdZddZd ZddZd Zd ZddZ	d	 Z
d
 Zd Zi fdZd Zd Zy)CanvasFrameaS  
    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                     |t                _         j                  j                  d        j                  j                  d fd        j                  j                  d j                          j                  j                  d j                         n| _        t         j                        x _        }t        |fi |x _        }t         j                  d      }t         j                  d	      }|j                  |d
<   |j                  |d
<   |j                  |d<   |j                  |d<   |j                  dd       |j                  dd       |j                  ddd       dj                  |d   |d         }||d<   t        |       _        |$ j                  dd        j#                          yy)a  
        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                 $    j                         S r   )print_to_file)r  r/   s    r6   <lambda>z&CanvasFrame.__init__.<locals>.<lambda>  s    t7I7I7Kr8   z<Control-x><Control-q>
horizontalorientverticalr  xscrollcommandr  r^   r  )r   r  r]   r  rH   bothr  expandr   r  z	0 0 {} {}rD   rI   r  r  r   )r   _parenttitler   rf   r	   _framer   _canvasr   xviewr#  r$  r"  formatr  _scrollwatcher_init_menubar)r/   r1   kwframer0   
xscrollbar
yscrollbarr  s   `       r6   r7   z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,  r8   c                 $   t        | j                        }t        |d      }|j                  dd| j                  d       |j                  dd| j                  d       |j                  d	d|
       | j                  j                  |       y )Nr   )tearoffzPrint to PostscriptzCtrl-p)label	underliner  acceleratorExitrH   zCtrl-xFile)r  r	  menu)r  )r   r  add_commandr  rf   add_cascadeconfig)r/   menubarfilemenus      r6   r  zCanvasFrame._init_menubar"  s    t||$+'&& 	 	 	
 	At|| 	 	
 	&AHE)r8   c           
      ^   |ddg}t        |d      }|sy| j                         \  }}}}| j                  j                  |||dz   |dz   |dz   |dz   dd      }|j	                  d	d
      }t        |d      5 }|j                  |j                  d             ddd       y# 1 sw Y   yxY w)a  
        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defaultextensionrA   r   )r]   r^   rD   rI   	pagewidth
pageheightpagexpageyz 0 scalefont z 9 scalefont wbutf8)r   r  r  
postscriptreplaceopenwriteencode)	r/   filenameftypesx0y0r]  hr  fs	            r6   r  zCanvasFrame.print_to_file3  s     13EFF(6ERH**,RA\\,,a%q5!e1u - 	

  ''I
(D!QGGJ%%f-. "!!s   9!B##B,c                     | j                   d   j                         \  }}}}t        |      t        |      t        |      t        |      fS )z
        :return: The current scroll region for the canvas managed by
            this ``CanvasFrame``.
        :rtype: 4-tuple of int
        r  )r  r  r   )r/   r`   ra   rb   rc   s        r6   r  zCanvasFrame.scrollregionQ  sC      <<7==?RRBR#b'3r733r8   c                     | j                   S )ze
        :return: The canvas managed by this ``CanvasFrame``.
        :rtype: Tkinter.Canvas
        )r  r?   s    r6   r0   zCanvasFrame.canvasZ  s    
 ||r8   c                     ||| j                  |||      \  }}|j                         \  }}}}|j                  ||z
  ||z
         | j                  j	                  |       y)ad  
        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>   rP   r   r  )r/   r  r]   r^   r`   ra   rb   rc   s           r6   
add_widgetzCanvasFrame.add_widgeta  sj    ( 9	__\1a8FQ (,,.RR!b&!b&) 	%%l3r8   c           	         | j                         \  }}}}|j                         }|j                         }	|||z
  k\  ry|	||z
  k\  ry|j                         \  }
}}}|j	                  ||z
  dz
  ||z
  dz
         |_|}t        |||	z
  t        ||z
  |	z
  dz              D ]8  }| j                  j                  |dz
  |dz
  ||z   dz   ||	z   dz         r4||fc S  |_|}t        |||z
  t        ||z
  |z
  dz              D ]8  }| j                  j                  |dz
  |dz
  ||z   dz   ||	z   dz         r4||fc S  t        |||	z
  t        ||z
  |	z
  dz              D ]a  }t        |||z
  t        ||z
  |z
  dz              D ]:  }| j                  j                  |dz
  |dz
  ||z   dz   ||	z   dz         r4||fc c S  c y)z9
        Try to find a space for a given widget.
        )r   r   2   r   r   )	r  rD   rI   r>   rP   r&  r   r  find_overlapping)r/   r   	desired_x	desired_yr  r  r  rb  r]  r'  r`   ra   rb   rc   r]   r^   s                   r6   r,  zCanvasFrame._find_room  s    #'"3"3"5sE3LLNMMOs ";;=RRD2INC"HrM2 A3acCi!mr-A)BC||44E1q5!a%!)QUQY q6M	 D  A4C1AR0G,HI||44E1q5!a%!)QUQY q6M	 J sC!GS#)a-2)=%>?A4C1AR0G,HI||44E1q5!a%!)QUQY q6M	 J @ r8   c                 F    | j                  |       |j                          y)z
        Remove a canvas widget from this ``CanvasFrame``.  This
        deregisters the canvas widget, and destroys it.
        N)remove_widgetrf   r  s     r6   destroy_widgetzCanvasFrame.destroy_widget  s    
 	<(r8   c                 :    | j                   j                  |       y r   )r   r  r  s     r6   r4  zCanvasFrame.remove_widget  s    ((6r8   c                 >     | j                   j                  |fi | y)zv
        Pack this ``CanvasFrame``.  See the documentation for
        ``Tkinter.Pack`` for more information.
        N)r  r"  r/   cnfr  s      r6   r"  zCanvasFrame.pack  s    
 	##r8   c                 `    | j                   y| j                   j                          d| _         y)z
        Destroy this ``CanvasFrame``.  If this ``CanvasFrame`` created a
        top-level window, then this will close that window.
        N)r  rf   r/   r  s     r6   rf   zCanvasFrame.destroy  s(    
 <<r8   c                 R    t               ry | j                  j                  |i | y)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   r  r)  r/   argskwargss      r6   r)  zCanvasFrame.mainloop  s%     9t.v.r8   r   NN)r{   r   r   r   r7   r  r  r  r0   r-  r,  r5  r4  r"  rf   r)  r   r8   r6   r  r    sJ    +!Z*"/<44<'R7  $	/r8   r  c                   *    e Zd ZdZddZd Zd Zd Zy)ShowTextz
    A ``Tkinter`` window used to display a text.  ``ShowText`` is
    typically used by graphical tools to display help text, or similar
    information.
    Nc                 `   ||| j                  |||      \  }}|t               x| _        }nt        |      x| _        }|j	                  |       t        |d| j                        }|j                  d       t        |      }	|	j                  dd       t        |	d	      }
|
j                  d
d       t        |	fd||d|}|j                  d|       d|d<   |j                  ddd       |j                  |
d<   |
j                  |d<   |j                  d| j                         |j                  d| j                         |j                  d| j                         |j                  d| j                         |j                  d| j                         |
j                          y )NOkr  r  r  rH   r  r  r  r  r  r^   r  word)wraprD   rI   r!  disabledr   r  )r  r  r   r  r  r  r]   r\  <Return><Escape>)find_dimentionsr   _topr   r  r   rf   r"  r	   r   r   r(  r#  r$  r   focus)r/   rootr  r   rD   rI   textbox_optionsr  btbf	scrollbartextboxs               r6   r7   zShowText.__init__  sp   =FN"224GOUF < d"DI&tn,DI		%3T4<<8	HCj'c*5	G#.sWuVWWud#%&8&}}	)$-MM ! 	dll#dll#dll#T\\*T\\* 	r8   c                    |j                  d      }|t        d |D              }t        |d      }d}|D ]B  }t        |      |kD  r-|d | j	                  d      }||d  }|dz  }t        |      |kD  r-|dz  }D t        |d      }||fS )N
c              3   2   K   | ]  }t        |        y wr   )r;   ).0lines     r6   	<genexpr>z+ShowText.find_dimentions.<locals>.<genexpr>  s     73t9s   P   r    rH      )r  ry  r  r;   rfind)r/   r   rD   rI   linesmaxwidthrW  brks           r6   rJ  zShowText.find_dimentions  s    

4 =777H"%E Dd)e#6El((-CDz! d)e# aKF  VRvr8   c                 `    | j                   y | j                   j                          d | _         y r   rK  rf   r;  s     r6   rf   zShowText.destroy  &    99			r8   c                 R    t               ry | j                  j                  |i | y)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   rK  r)  r=  s      r6   r)  zShowText.mainloop  s%     9		D+F+r8   r@  )r{   r   r   r   r7   rJ  rf   r)  r   r8   r6   rB  rB    s    !F$	,r8   rB  c                   8    e Zd ZdZ	 d	dZd Zd Zd Zd Zd Z	y)
EntryDialogz#
    A dialog box for entering
    Nc                    || _         || _        || _        t        t	        dt        |      dz  dz              }t        |      | _        |r| j                  j                  |       t        | j                        }|j                  ddddd       |r!t        ||	      }|j                  d
dd       t        ||      | _        | j                  j                  ddd       | j                  j                  d|       t        | j                  dd      }	|	j                  ddd       t        | j                        }
|
j                  dddd       t        |
d| j                   d      }|j                  dd       t        |
d| j"                  dd      }|j                  dd       t        |
d| j$                  d      }|j                  d       | j                  j'                  d | j"                         | j                  j'                  d!| j                          | j                  j'                  d"| j                          | j                  j)                          y )#Nr  rG   rA   rH   r  r   r   )r  r   padxpadyipadyr   r  r]  )r  r_   rg  rr  r]   )r  r   rg  r   sunken)borderwidthrelief)r   ri  rg  )r  r   rg  rh  Cancelr  )r   r  rD   r  )r  rg  rD  active)r   r  rD   defaultr  Applyr  rH  r  rI  )r  _original_text_set_callbackr   ry  r;   r   rK  r  r	   r"  r
   r   _entryr(  r   _cancel_ok_applyr   rL  )r/   r1   original_textinstructionsset_callbackr  rD   
entryframer   dividerbuttonsrO  s               r6   r7   zEntryDialog.__init__/  s    +)CC.2Q678V$	IIOOE" 499%
qvAARHj|4AFFcF3Je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r8   c                     | j                   j                  dd       | j                   j                  d| j                         | j                  r| j	                  | j                         y y )Nr   r!  )rs  rh   r(  rq  rr  r;  s     r6   _resetzEntryDialog._resetZ  sR    1e$1d112t223 r8   c                 T    	 | j                          | j                          y #  Y xY wr   )r~  _destroyr;  s     r6   rt  zEntryDialog._cancel`  s%    	KKM 		s   # 'c                 D    | j                          | j                          y r   )rv  r  r;  s     r6   ru  zEntryDialog._okg  s    r8   c                 p    | j                   r*| j                  | j                  j                                y y r   )rr  rs  getr;  s     r6   rv  zEntryDialog._applyk  s)    t{{01 r8   c                 `    | j                   y | j                   j                          d | _         y r   ra  r;  s     r6   r  zEntryDialog._destroyo  rb  r8   )r  r  NN)
r{   r   r   r   r7   r~  rt  ru  rv  r  r   r8   r6   re  re  *  s-    
 SW)V42r8   re  c                       e Zd ZdZg fdZed        Zed        ZddZd Z	ddZ
d	 Zd
 Zd Zd ZddZi fdZi fdZd Zd Zd Zd Zd Zy)ColorizedLista  
    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                 4   || _         i | _        i | _        | j                  |j	                                | j
                  j                  d| j                         | j
                  j                  d| j                         d| _	        | j                  |       y)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)r  
_callbacks_marks_init_itemframecopy_textwidgetr   	_keypress_buttonpress_itemsr$  )r/   r1   r*   optionss       r6   r7   zColorizedList.__init__  s}       	W\\^, 	lDNN;ot/@/@A r8   c                      y)z
        Set up any colortags that will be used by this colorized list.
        E.g.:
            textwidget.tag_config('terminal', foreground='black')
        Nr   )r/   
textwidgetr  s      r6   _init_colortagszColorizedList._init_colortags  r   r8   c                      y)a  
        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   r/   items     r6   
_item_reprzColorizedList._item_repr  r   r8   Nc                 B    || j                   dd S | j                   |   S )zF
        :return: A list of the items contained by this list.
        N)r  )r/   r  s     r6   r  zColorizedList.get  s&     =;;q>!;;u%%r8   c                 :   t        |      }| j                  |k(  ryt        |      | _        d| j                  d<   | j                  j                  dd       |D ]_  }| j	                  |      D ]-  \  }}d|vsJ d       | j                  j                  d||       / | j                  j                  dd       a | j                  j                  dd       | j                  j                  d	d       d
| j                  d<   | j                  j                          y)zB
        Modify the list of items contained by this list.
        Nr   r   1.0r!  rT  z!item repr may not contain newlinez	end-1charr(  rG  )	r)   r  r  rh   r  r(  mark_setr  clear)r/   r*   r  r   colortags        r6   r$  zColorizedList.set  s     U;;%5k$,!u-D"&//$"7h4'L)LL'  ''tX> #8 ##E40	  	U3!!(E2$.!r8   c                 "   |8| j                   j                          | j                  j                  ddd       y| j                  j                  |      }| j                   |= d|dz   z  d|dz   z  }}| j                  j                  d||       y)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.0rH   rA   )r  r  r  
tag_remover  r  r/   r  r  rk  r!  s        r6   unmarkzColorizedList.unmark  s     <KK''UKHKK%%d+ED!"eai0&EAI2FCU''UC@r8   c                     d| j                   |<   | j                  j                  |      }d|dz   z  d|dz   z  }}| j                  j	                  d||       y)zp
        Highlight the given item.
        :raise ValueError: If ``item`` is not contained in the list.
        rH   r  rA   r  N)r  r  r  r  tag_addr  s        r6   markzColorizedList.mark  sY    
 D!!$'%!),f	.B  eS9r8   c                 F    | j                          | j                  |       y)z
        Remove any current highlighting, and mark the given item.
        :raise ValueError: If ``item`` is not contained in the list.
        N)r  r  r  s     r6   markonlyzColorizedList.markonly  s    
 			$r8   c                 |    | j                   j                  |      }| j                  j                  d|dz   z         y)z
        Adjust the view such that the given item is visible.  If
        the item is already visible, then do nothing.
        r  rH   N)r  r  r  see)r/   r  r  s      r6   viewzColorizedList.view  s5    
 !!$'Vuqy12r8   c                 ~    |dk(  rg d}n|dk(  rg d}n|g}|D ]!  }d| j                   j                  |i       |<   # y)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  returnrP   updownnextpriorrH   N)r  
setdefaultr/   r   funceventsr  s        r6   add_callbackzColorizedList.add_callback		  sI     H2Ff_4FWFA67DOO&&q"-d3 r8   c                     |$t        | j                  j                               }n|dk(  rg d}n|dk(  rg d}n|g}|D ]#  }|| j                  |= 	 | j                  |   |= % y#  Y +xY w)z
        Deregister a callback function.  If ``func`` is none, then
        all callbacks are removed for the given event.
        Nr  r  rP   r  )r)   r  keysr  s        r6   remove_callbackzColorizedList.remove_callback 	  s{    
 =$//..01Fh2Ff_4FWFA|OOA&*40 s   A''A+c                 >     | j                   j                  |fi | y r   )
_itemframer"  r8  s      r6   r"  zColorizedList.pack;	  s    S'B'r8   c                 >     | j                   j                  |g|  y r   )r  gridr8  s      r6   r  zColorizedList.grid?	  s    S&2&r8   c                 8    | j                   j                          y r   )r  rL  r?   s    r6   rL  zColorizedList.focusC	  s     r8   c                 *   t        | j                        | _        |j                  dd       t	        | j                  fi || _        t        | j                  dd      | _        | j
                  j                  | j                  j                         | j                  j                  | j
                  j                         | j                  j                  dd	
       | j
                  j                  ddd       | j
                  j                  dddd       | j                  | j
                  |       | j
                  j                  dd       | j
                  j                  ddddd       | j
                  j                  dd       y )N
backgroundz#e0e0e0r   r  )	takefocusr  )r  r  r  r^   r  rH   r  r  r  r  z#e0ffff1raised)r  borderrl  selr  )
foreground)r  r  r  r	  )r	   r  r  r  r   r  r   _textscrollr  r$  r#  r"  r%  r  rE  )r/   r  s     r6   r  z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 	$ 	
 	"";6r8   c                     || j                   vry d|cxk  rt        | j                        k  rn n| j                  |   }nd }t        | j                   |   j	                               D ]
  } ||        y )Nr   )r  r;   r  r)   r  )r/   r   itemnumr  cb_funcs        r6   _fire_callbackzColorizedList._fire_callbackd	  sb    '*#dkk**;;w'DDDOOE2779:GDM ;r8   c                     d|j                   |j                  fz  }| j                  j                  |      }t	        |j                  d      d         dz
  }| j                  d|j                  z  |       y )Nz@%d,%d.r   rH   zclick%d)r]   r^   r  r  r   r  r  r   )r/   r   clicklocinsert_pointr  s        r6   r  zColorizedList._buttonpressn	  sg    uww00''--h7l((-a01A5I		17;r8   c                 P   |j                   dk(  s|j                   dk(  rf| j                  j                  d      }t        |j	                  d      d         dz
  }| j                  |j                   j                         |       y |j                   dk(  rd}n7|j                   d	k(  rd
}n%|j                   dk(  rd}n|j                   dk(  rd}ny| j                  j                  dd|z          | j                  j                  d       | j                  j                  ddd       | j                  j                  ddd       | j                  j                  d      }t        |j	                  d      d         dz
  }| j                  |j                   j                         |       y)NReturnr  r(  r  r   rH   Downz+1lineUpz-1lineNextz+10linesPriorz-10linescontinuer  r  r  zinsert linestartzinsert lineendbreak)keysymr  r  r   r  r  lowerr  r  r  r  )r/   r   r  r  deltas        r6   r  z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':r8   r   )r{   r   r   r   r7   r   r  r  r  r$  r  r  r  r  r  r  r"  r  rL  r  r  r  r  r   r8   r6   r  r  {  s     &( 8    &.A :38.6  (  '!72<r8   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)MutableOptionMenuc                    |j                  d      | _        d|v r|d= t               x| _        }t	        |      dkD  r|j                  |d          d|dt        ddd}|j                  |       t        j                  | |d|       d| _
        t        | d	d
      | _        | j                  j                  | _        g | _        |D ]  }| j!                  |        | j                  | d	<   y )Nr  r   rA   rH   r\  )rk  textvariableindicatoronrl  r_   highlightthickness
menubuttontk_optionMenur  )r>  r  )r  	_callbackr   	_variabler;   r$  r   rQ   r   r7   
widgetNamer   _menu_wmenuname_valuesadd)r/   mastervaluesr  variabler  r4   s          r6   r7   zMutableOptionMenu.__init__	  s     Y/	" %.K/v;?LL# $"#
 			'flB7)$VQ7


EHHUO  zzVr8   c                      | j                   v ry |f fd	} j                  j                  ||        j                   j                  |       y )Nc                 (    j                  |        y r   )r$  )r4   r/   s    r6   r$  z"MutableOptionMenu.add.<locals>.set	  s    HHUOr8   )r  r  )r  r  r  r   )r/   r4   r$  s   `  r6   r  zMutableOptionMenu.add	  sE    DLL  	 	

UC8E"r8   c                 v    | j                   j                  |       | j                  r| j                  |       y y r   )r  r$  r  )r/   r4   s     r6   r$  zMutableOptionMenu.set	  s,    5!>>NN5! r8   c                     | j                   j                  |      }| j                   |= | j                  j                  ||       y r   )r  r  r  rh   )r/   r4   r,  s      r6   r   zMutableOptionMenu.remove	  s5    LLu%LLO

!Qr8   c                 P    |dk(  r| j                   S t        j                  | |      S )Nr  )_MutableOptionMenu__menur   ry   r=  s     r6   ry   zMutableOptionMenu.__getitem__	  s&    6>;;!!$--r8   c                 <    t        j                  |        d| _        y)z,Destroy this widget and the associated menu.N)r   rf   r  r?   s    r6   rf   zMutableOptionMenu.destroy	  s    4 
r8   N)	r{   r   r   r7   r  r$  r   ry   rf   r   r8   r6   r  r  	  s     "<#"
 .
r8   r  c                  2   d } d }t        ddd      }|j                         }t        |dd      }t        |d	dd
      }t        ||d      }t        |ddd
      }t	        ||d      }t        ||dddd      }	t        |t        |d      t        |d      t        |d      t        |d      t        |d      t        |d      t        |d            }
t        |dd      }t        ||	||||
d
      }t        |ddd
      }t        |||      }t        ||dd      }|j                  |dd       |	j                  |        |j                  |       |j                  |        |j                  |       |j                  |       |j                          y )!zC
    A simple demonstration showing how to use canvas widgets.
    c                 .    ddl m} d |dd      z  | d<   y )Nr   randintz#00%04d'  r   randomr  cwr  s     r6   r   zdemo.<locals>.fill	  s    "D!116
r8   c                 .    ddl m} d |dd      z  | d<   y )Nr   r  z#ff%04dr  r   r  r  s     r6   r   zdemo.<locals>.color	  s    "'!T"227r8   r   i,  )closeenoughrD   rI   z
hiya thererH   )rr   zo  o
||
___
  Ur  )rr   r   redrq  zo  o
||
\___/)r   cyanrG   )r   rr   rD   rG  r   r]   r   zy: r   r^   r   r  )r  ztry clicking
and dragginggreen4)r   rD   <   N)r  r0   r   rQ  re  r@  r  r   r  r  r~  r-  r   r)  )r   r   cfr\  ct3ct2coctcpr   equationr  cstack
prompt_msgcszzs                   r6   demor  	  s   
2
3
 
3s	;B
		A
Q
2C
Q,8
LC	AsE	*B	A)Q	IB	Q%	(B	1bv!B	GB	Q!1cQ!1e1cQ
#1c	H 1b!EBUBIF	'1hJ 
6:	.B	q"HA	6BMM"b"MM$MM%MM$NN5NN5KKMr8   __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   r2  r@  rQ  re  r~  r  r  r  r  r  rB  re  r  r  r  r{   r   r8   r6   <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 r8   