
`]c           @   s   d  Z  d d l m Z d d l Z d d l m Z m Z m Z m Z m	 Z	 d e f d     YZ
 d e f d     YZ d	   Z e d
 k r e   n  d S(   sC   
Tkinter widgets for displaying multi-column listboxes and tables.
i(   t   divisionN(   t   Framet   Labelt   Listboxt	   Scrollbart   Tkt   MultiListboxc           B   si  e  Z d  Z e d d d e d d  Z e d d d d d	 d
 d d d d  Z e d d d d d d d e d d d d d e  Z d= i  d  Z
 d   Z d   Z d   Z e d    Z e d    Z e d    Z d   Z d   Z d   Z d= d= e d  Z i  d  Z d    Z i  d!  Z i  d"  Z d= d#  Z d$   Z d= d%  Z d&   Z d'   Z d(   Z d= d= d= d)  Z  d= d= d= d*  Z! d= d= d= d+  Z" d,   Z# d-   Z$ d.   Z% d/   Z& d0   Z' d1   Z( d2   Z) d3   Z* d4   Z+ d5   Z, d6   Z- d7   Z. d8   Z/ d9   Z0 d:   Z1 d;   Z2 d<   Z3 e Z4 e Z5 e Z6 e. Z7 e/ Z8 e$ Z9 e0 Z: RS(>   s  
    A multi-column listbox, where the current selection applies to an
    entire row.  Based on the MultiListbox Tkinter widget
    recipe from the Python Cookbook (http://code.activestate.com/recipes/52266/)

    For the most part, ``MultiListbox`` methods delegate to its
    contained listboxes.  For any methods that do not have docstrings,
    see ``Tkinter.Listbox`` for a description of what that method does.
    t
   backgrounds   #888t	   takefocust   highlightthicknessi   t   borderwidtht   relieft   raisedt   fonts   helvetica -16 bolds   #444t
   foregroundt   whitet   selectborderwidthi    t   exportselectiont   selectbackgroundt   activestylet   nonec            s-  t  | t  r* t t |   } t } n t } t |  d k rQ t d   n  t |    _	 g    _
 g    _ | d# k r d g t |  } n' t |  t |  k r t d   n  |   _ t j   |   j    j d d d xt   j	  D]\ } }   j | d | | | rt   d |   j }	   j j |	  |	 j d | d d d	 d
 d d d d  | |	 _ n  t     j  }
   j
 j |
  |
 j d | d d d	 d
 d d d d  | |
 _ |
 j d   j  |
 j d   j  |
 j d   f d    |
 j d   f d    |
 j d   f d    |
 j d   f d    |
 j d   f d    |
 j d d    |	 j d   j  q W  j d   j    j d   f d      j d   f d      j d   f d       j d!   f d"      j | |  d# S($   s/  
        Construct a new multi-column listbox widget.

        :param master: The widget that should contain the new
            multi-column listbox.

        :param columns: Specifies what columns should be included in
            the new multi-column listbox.  If ``columns`` is an integer,
            the it is the number of columns to include.  If it is
            a list, then its length indicates the number of columns
            to include; and each element of the list will be used as
            a label for the corresponding column.

        :param cnf, kw: Configuration parameters for this widget.
            Use ``label_*`` to configure all labels; and ``listbox_*``
            to configure all listboxes.  E.g.:

                >>> mlb = MultiListbox(master, 5, label_foreground='red')
        i    s   Expected at least one columni   s*   Expected one column_weight for each columnt   weightt   textt   columnt   rowt   stickyt   newst   padxt   padys
   <Button-1>s   <B1-Motion>s
   <Button-4>c            s     j  d  S(   Ni(   t   _scroll(   t   e(   t   self(    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   <lambda>   t    s
   <Button-5>c            s     j  d 
 S(   Ni   (   R   (   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <MouseWheel>c            s     j  |  j  S(   N(   R   t   delta(   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s
   <Button-2>c            s     j  |  j |  j  S(   N(   t	   scan_markt   xt   y(   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <B2-Motion>c            s     j  |  j |  j  S(   N(   t   scan_dragtoR$   R%   (   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s
   <B1-Leave>c         S   s   d S(   Nt   break(    (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <Up>c            s     j  d d  S(   NR"   i(   t   select(   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <Down>c            s     j  d d  S(   NR"   i   (   R(   (   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <Prior>c            s     j  d   j    S(   NR"   (   R(   t	   _pagesize(   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   s   <Next>c            s     j  d   j    S(   NR"   (   R(   R)   (   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR       R!   N(   t
   isinstancet   intt   listt   ranget   Falset   Truet   lent
   ValueErrort   tuplet   _column_namest
   _listboxest   _labelst   Nonet   _column_weightsR   t   __init__t   FRAME_CONFIGt   grid_rowconfiguret	   enumeratet   grid_columnconfigureR   t   LABEL_CONFIGt   appendt   gridt   column_indexR   t   LISTBOX_CONFIGt   bindt   _selectt   _resize_columnt	   configure(   R   t   mastert   columnst   column_weightst   cnft   kwt   include_labelst   it   labelt   lt   lb(    (   R   s.   lib/python2.7/site-packages/nltk/draw/table.pyR8   C   sT    				((	c         C   s9  | j  j d  r t Sd |  _ | j  |  k r x t |  j  D]A \ } } t | j | j	   | j
    d k  r> | |  _ q> q> Wne | j | j  j
   d k r | j  j |  _ n7 | j d k  r | j  j d k r | j  j d |  _ n  |  j d k	 r1| j  j d |  j  | j  j d | j |  j  t St Sd S(	   s   
        Callback used to resize a column of the table.  Return ``True``
        if the column is actually getting resized (if the user clicked
        on the far left or far right 5 pixels of a label); and
        ``False`` otherwies.
        s   <ButtonRelease>i
   i   i    i   s   <Motion>s   <ButtonRelease-%d>N(   t   widgetRB   R.   R6   t   _resize_column_indexR;   R4   t   absR$   t   winfo_xt   winfo_widthR@   t   _resize_column_motion_cbt   numt   _resize_column_buttonrelease_cbR/   (   R   t   eventRL   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRD      s"    		)!	c         C   sw   |  j  |  j } | j   | d } | j | j j   } | j   | j   } t d | d | | |  | d <d  S(   Nt   widthi   (   R4   RQ   RT   R$   RP   RS   t   max(   R   RX   RO   t	   charwidtht   x1t   x2(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRU      s
    c         C   s+   | j  j d | j  | j  j d  d  S(   Ns   <ButtonRelease-%d>s   <Motion>(   RP   t   unbindRV   (   R   RX   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRW      s    c         C   s   |  j  S(   sh   
        A tuple containing the names of the columns used by this
        multi-column listbox.
        (   R3   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   column_names   s    c         C   s   t  |  j  S(   s  
        A tuple containing the ``Tkinter.Label`` widgets used to
        display the label of each column.  If this multi-column
        listbox was created without labels, then this will be an empty
        tuple.  These widgets will all be augmented with a
        ``column_index`` attribute, which can be used to determine
        which column they correspond to.  This can be convenient,
        e.g., when defining callbacks for bound events.
        (   R2   R5   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   column_labels   s    c         C   s   t  |  j  S(   sY  
        A tuple containing the ``Tkinter.Listbox`` widgets used to
        display individual columns.  These widgets will all be
        augmented with a ``column_index`` attribute, which can be used
        to determine which column they correspond to.  This can be
        convenient, e.g., when defining callbacks for bound events.
        (   R2   R4   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt	   listboxes   s    	c         C   sM   | j  j | j  } |  j d d  |  j |  |  j |  |  j   d  S(   Ni    t   end(   RP   t   nearestR%   t   selection_cleart   selection_sett   activatet   focus(   R   R   RL   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRC      s
    c         C   s(   x! |  j  D] } | j | d  q
 Wd S(   Nt   unitR'   (   R4   t   yview_scroll(   R   R"   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR      s    c         C   s&   t  |  j d   t  |  j d   S(   s2   :return: The number of rows that makes up one pages
   @0,1000000s   @0,0(   R+   t   index(   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR)     s    c         C   s   | d k	 r' | d k	 r' t d   n  | d k	 ru t |  j    d k rX d | } qu t |  j   d  | } n  |  j d d  | d k	 r t t | d  |  j   d  } |  j	 |  | r |  j
 |  q n  d S(   s  
        Set the selected row.  If ``index`` is specified, then select
        row ``index``.  Otherwise, if ``delta`` is specified, then move
        the current selection by ``delta`` (negative numbers for up,
        positive numbers for down).  This will not move the selection
        past the top or the bottom of the list.

        :param see: If true, then call ``self.see()`` with the newly
            selected index, to ensure that it is visible.
        s$   specify index or delta, but not bothi    iRb   i   N(   R6   R1   R0   t   curselectionR+   Rd   t   minRZ   t   sizeRe   t   see(   R   Rj   R"   Rn   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR(     s    "c         K   s   t  t | j    t | j     } x t | j    D] \ } } | j d  se | j d  r x |  j D] } | j i | | d 6 qo Wq; | j d  s | j d  r xC |  j D] } | j i | | d 6 q Wq; t j |  i | | 6 q; Wd S(   s8  
        Configure this widget.  Use ``label_*`` to configure all
        labels; and ``listbox_*`` to configure all listboxes.  E.g.:

                >>> mlb = MultiListbox(master, 5)
                >>> mlb.configure(label_foreground='red')
                >>> mlb.configure(listbox_foreground='red')
        t   label_s   label-i   t   listbox_s   listbox-i   N(   t   dictR,   t   itemst
   startswithR5   RE   R4   R   (   R   RI   RJ   t   keyt   valRM   t   listbox(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRE   /  s    	(c         C   s   |  j  i | | 6 d S(   s|   
        Configure this widget.  This is equivalent to
        ``self.configure({key,val``)}.  See ``configure()``.
        N(   RE   (   R   Rt   Ru   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   __setitem__C  s    c         K   s+   x$ |  j  D] } | j | | |  q
 Wd S(   s   
        Configure all table cells in the given row.  Valid keyword
        arguments are: ``background``, ``bg``, ``foreground``, ``fg``,
        ``selectbackground``, ``selectforeground``.
        N(   R4   t   itemconfigure(   R   t	   row_indexRI   RJ   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   rowconfigureJ  s    c         K   s   |  j  | } t t | j    t | j     } xw t | j    D]c \ } } | d k r xH t | j    D] } | j | i | | 6 qs WqH | j i | | 6 qH Wd S(	   s   
        Configure all table cells in the given column.  Valid keyword
        arguments are: ``background``, ``bg``, ``foreground``, ``fg``,
        ``selectbackground``, ``selectforeground``.
        R   t   bgR   t   fgR   t   selectforegroundN(   R   R{   R   R|   R   R}   (   R4   Rq   R,   Rr   R-   Rm   Rx   RE   (   R   t	   col_indexRI   RJ   RO   Rt   Ru   RL   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   columnconfigureS  s    (     	c         K   s    |  j  | } | j | | |  S(   s   
        Configure the table cell at the given row and column.  Valid
        keyword arguments are: ``background``, ``bg``, ``foreground``,
        ``fg``, ``selectbackground``, ``selectforeground``.
        (   R4   Rx   (   R   Ry   R~   RI   RJ   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRx   j  s    c         G   s~   x8 | D]0 } t  |  t  |  j  k r t d   q q Wx< t |  j t t |     D] \ } } | j | |  qZ Wd S(   s0  
        Insert the given row or rows into the table, at the given
        index.  Each row value should be a tuple of cell values, one
        for each column in the row.  Index may be an integer or any of
        the special strings (such as ``'end'``) accepted by
        ``Tkinter.Listbox``.
        sD   rows should be tuples whose length is equal to the number of columnsN(   R0   R3   R1   t   zipR4   R,   t   insert(   R   Rj   t   rowst   eltRO   t   elts(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   w  s    +c         C   s_   g  |  j  D] } | j | |  ^ q
 } | rQ g  t |   D] } t |  ^ q; St |  Sd S(   s  
        Return the value(s) of the specified row(s).  If ``last`` is
        not specified, then return a single row value; otherwise,
        return a list of row values.  Each row value is a tuple of
        cell values, one for each column in the row.
        N(   R4   t   getR   R2   (   R   t   firstt   lastRO   t   valuesR   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    (#c   
      C   s   |  j  d d d |  \ } } } } |  j | j |  \ } } } }	 t |  t |  t |  t |  t |  t |	  f S(   s   
        Return the bounding box for the given table cell, relative to
        this widget's top-left corner.  The bounding box is a tuple
        of integers ``(left, top, width, height)``.
        R   i    R   (   t	   grid_bboxR4   t   bboxR+   (
   R   R   t   colt   dxt   dyt   _R$   R%   t   wt   h(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    $"c         C   sE   |  j  r |  j  | j   n  |  j | j   |  j | d d d S(   s1  
        Hide the given column.  The column's state is still
        maintained: its values will still be returned by ``get()``, and
        you must supply its values when calling ``insert()``.  It is
        safe to call this on a column that is already hidden.

        :see: ``show_column()``
        R   i    N(   R5   t   grid_forgetRa   R<   (   R   R~   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   hide_column  s    		c         C   s   |  j  | } |  j rH |  j | j d | d d d d d d d d  n  |  j | j d | d d d d d d d d  |  j | d	 | d
 S(   s   
        Display a column that has been hidden using ``hide_column()``.
        It is safe to call this on a column that is not hidden.
        R   R   i    R   R   R   R   i   R   N(   R7   R5   R?   R4   R<   (   R   R~   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   show_column  s    	"c         C   s)   g  |  j  D] } | j | | |  ^ q
 S(   sK  
        Add a binding to each ``Tkinter.Label`` widget in this
        mult-column listbox that will call ``func`` in response to the
        event sequence.

        :return: A list of the identifiers of replaced binding
            functions (if any), allowing for their deletion (to
            prevent a memory leak).
        (   R`   RB   (   R   t   sequencet   funct   addRM   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   bind_to_labels  s    
c         C   s+   x$ |  j  D] } | j | | |  q
 Wd S(   sM  
        Add a binding to each ``Tkinter.Listbox`` widget in this
        mult-column listbox that will call ``func`` in response to the
        event sequence.

        :return: A list of the identifiers of replaced binding
            functions (if any), allowing for their deletion (to
            prevent a memory leak).
        N(   Ra   RB   (   R   R   R   R   Rv   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   bind_to_listboxes  s    
c         C   s&   |  j  | | |  |  j | | |  S(   sc  
        Add a binding to each ``Tkinter.Label`` and ``Tkinter.Listbox``
        widget in this mult-column listbox that will call ``func`` in
        response to the event sequence.

        :return: A list of the identifiers of replaced binding
            functions (if any), allowing for their deletion (to
            prevent a memory leak).
        (   R   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   bind_to_columns  s    
c         O   s   |  j  d j | |   S(   Ni    (   R4   Rk   (   R   t   argst   kwargs(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRk     s    c         O   s   |  j  d j | |   S(   Ni    (   R4   t   selection_includes(   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         O   s   |  j  d j | |   S(   Ni    (   R4   t   itemcget(   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         O   s   |  j  d j | |   S(   Ni    (   R4   Rm   (   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRm     s    c         O   s   |  j  d j | |   S(   Ni    (   R4   Rj   (   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRj     s    c         O   s   |  j  d j | |   S(   Ni    (   R4   Rc   (   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRc     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   Rf   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRf     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   t   delete(   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   R#   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR#     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   R&   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR&     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   Rn   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRn     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   t   selection_anchor(   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   Rd   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRd     s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   Re   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRe     s    c         O   s*   x# |  j  D] } | j | |   } q
 W| S(   N(   R4   t   yview(   R   R   R   RO   t   v(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   #  s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   t   yview_moveto(   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   (  s    c         O   s(   x! |  j  D] } | j | |   q
 Wd  S(   N(   R4   Ri   (   R   R   R   RO   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRi   ,  s    N(;   t   __name__t
   __module__t   __doc__Rq   R/   R9   R=   R.   RA   R6   R8   RD   RU   RW   t   propertyR_   R`   Ra   RC   R   R)   R(   RE   Rw   Rz   R   Rx   R   R   R   R   R   R   R   R   Rk   R   R   Rm   Rj   Rc   Rf   R   R#   R&   Rn   R   Rd   Re   R   R   Ri   t
   itemconfigt	   rowconfigt   columnconfigt   select_anchort   select_cleart   select_includest
   select_set(    (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR      s   			^	!						$																							t   Tablec           B   s  e  Z d  Z d# d# e e d# i  d  Z d   Z d   Z d   Z d# d# d# d  Z	 i  d  Z
 i  d  Z d# d  Z d# d# d# d	  Z d# d# d# d
  Z d# d# d# d  Z e
 Z e Z e 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 d   Z  d   Z! d# d# e d  Z" d d  Z# d   Z$ e d  Z% d   Z& d# e' d   Z( e' e' d!  Z) e' Z* d"   Z+ RS($   s  
    A display widget for a table of values, based on a ``MultiListbox``
    widget.  For many purposes, ``Table`` can be treated as a
    list-of-lists.  E.g., table[i] is a list of the values for row i;
    and table.append(row) adds a new row with the given lits of
    values.  Individual cells can be accessed using table[i,j], which
    refers to the j-th column of the i-th row.  This can be used to
    both read and write values from the table.  E.g.:

        >>> table[i,j] = 'hello'

    The column (j) can be given either as an index number, or as a
    column name.  E.g., the following prints the value in the 3rd row
    for the 'First Name' column:

        >>> print(table[3, 'First Name'])
        John

    You can configure the colors for individual rows, columns, or
    cells using ``rowconfig()``, ``columnconfig()``, and ``itemconfig()``.
    The color configuration for each row will be preserved if the
    table is modified; however, when new rows are added, any color
    configurations that have been made for *columns* will not be
    applied to the new row.

    Note: Although ``Table`` acts like a widget in some ways (e.g., it
    defines ``grid()``, ``pack()``, and ``bind()``), it is not itself a
    widget; it just contains one.  This is because widgets need to
    define ``__getitem__()``, ``__setitem__()``, and ``__nonzero__()`` in
    a way that's incompatible with the fact that ``Table`` behaves as a
    list-of-lists.

    :ivar _mlb: The multi-column listbox used to display this table's data.
    :ivar _rows: A list-of-lists used to hold the cell values of this
        table.  Each element of _rows is a row value, i.e., a list of
        cell values, one for each column in the row.
    c	         K   s  t  |  |  _ | |  _ t |  |  _ t d   t |  D  |  _ | d k r^ g  |  _	 n/ g  | D] }
 g  |
 D] } | ^ qr ^ qe |  _	 x |  j	 D] }
 |  j
 |
  q Wt |  j | | | |	  |  _ |  j j d d d t d d  | rKt |  j d d d	 |  j j } | j |  j j d
 d <| j d d d d  | |  _ n  d |  _ | rx6 t |  j j  D] \ } } | j d |  j  qmWn  |  j   d S(   s  
        Construct a new Table widget.

        :type master: Tkinter.Widget
        :param master: The widget that should contain the new table.
        :type column_names: list(str)
        :param column_names: A list of names for the columns; these
            names will be used to create labels for each column;
            and can be used as an index when reading or writing
            cell values from the table.
        :type rows: list(list)
        :param rows: A list of row values used to initialze the table.
            Each row value should be a tuple of cell values, one for
            each column in the row.
        :type scrollbar: bool
        :param scrollbar: If true, then create a scrollbar for the
            new table widget.
        :type click_to_sort: bool
        :param click_to_sort: If true, then create bindings that will
            sort the table's rows by a given column's values if the
            user clicks on that colum's label.
        :type reprfunc: function
        :param reprfunc: If specified, then use this function to
            convert each table cell value to a string suitable for
            display.  ``reprfunc`` has the following signature:
            reprfunc(row_index, col_index, cell_value) -> str
            (Note that the column is specified by index, not by name.)
        :param cnf, kw: Configuration parameters for this widget's
            contained ``MultiListbox``.  See ``MultiListbox.__init__()``
            for details.
        c         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0RL   t   c(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pys	   <genexpr>  s    t   sidet   leftt   expandt   fillt   botht   orientt   verticalt   commandi    t   yscrollcommandt   rightR%   s
   <Button-1>N(   R0   t   _num_columnst	   _reprfuncR   t   _frameRq   R;   t   _column_name_to_indexR6   t   _rowst	   _checkrowR   t   _mlbt   packR/   R   R   t   setRa   t
   _scrollbart   _sortkeyR`   RB   t   _sortt   _fill_table(   R   RF   R_   R   RH   t	   scrollbart   click_to_sortt   reprfuncRI   RJ   R   R   t   sbRL   RN   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR8   p  s*    +	/!	c         O   s   |  j  j | |   d S(   sr   Position this table's main frame widget in its parent
        widget.  See ``Tkinter.Frame.pack()`` for more info.N(   R   R   (   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         O   s   |  j  j | |   d S(   sr   Position this table's main frame widget in its parent
        widget.  See ``Tkinter.Frame.grid()`` for more info.N(   R   R?   (   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR?     s    c         C   s   |  j  j   d S(   s-   Direct (keyboard) input foxus to this widget.N(   R   Rg   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRg     s    c         C   s   |  j  j | | |  d S(   sk   Add a binding to this table's main frame that will call
        ``func`` in response to the event sequence.N(   R   RB   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRB     s    c         K   s   |  j  j | | |  d S(   s%   :see: ``MultiListbox.rowconfigure()``N(   R   Rz   (   R   Ry   RI   RJ   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRz     s    c         K   s)   |  j  |  } |  j j | | |  d S(   s(   :see: ``MultiListbox.columnconfigure()``N(   R@   R   R   (   R   R~   RI   RJ   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         K   s(   |  j  |  } |  j j | | | |  S(   s&   :see: ``MultiListbox.itemconfigure()``(   R@   R   Rx   (   R   Ry   R~   RI   RJ   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRx     s    c         C   s   |  j  j | | |  S(   s'   :see: ``MultiListbox.bind_to_labels()``(   R   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         C   s   |  j  j | | |  S(   s*   :see: ``MultiListbox.bind_to_listboxes()``(   R   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         C   s   |  j  j | | |  S(   s(   :see: ``MultiListbox.bind_to_columns()``(   R   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         C   s   |  j  |  |  j j | |  |  j d k	 rf g  t |  D]! \ } } |  j | | |  ^ q< } n  |  j j | |  |  j r |  j   n  d S(   sT  
        Insert a new row into the table, so that its row index will be
        ``row_index``.  If the table contains any rows whose row index
        is greater than or equal to ``row_index``, then they will be
        shifted down.

        :param rowvalue: A tuple of cell values, one for each column
            in the new row.
        N(	   R   R   R   R   R6   R;   R   t   _DEBUGt   _check_table_vs_mlb(   R   Ry   t   rowvaluet   jR   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    
7	c         C   s8   x | D] } |  j  |  q W|  j r4 |  j   n  d S(   s   
        Add new rows at the end of the table.

        :param rowvalues: A list of row values used to initialze the
            table.  Each row value should be a tuple of cell values,
            one for each column in the row.
        N(   R>   R   R   (   R   t	   rowvaluesR   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   extend  s    	c         C   s3   |  j  t |  j  |  |  j r/ |  j   n  d S(   s   
        Add a new row to the end of the table.

        :param rowvalue: A tuple of cell values, one for each column
            in the new row.
        N(   R   R0   R   R   R   (   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR>     s    	c         C   s6   g  |  _  |  j j d d  |  j r2 |  j   n  d S(   s0   
        Delete all rows in this table.
        i    Rb   N(   R   R   R   R   R   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   clear%  s    		c         C   st   t  | t  r t d   nR t  | t  r_ t |  d k r_ |  j | d |  j | d  St |  j |  Sd S(   s  
        Return the value of a row or a cell in this table.  If
        ``index`` is an integer, then the row value for the ``index``th
        row.  This row value consists of a tuple of cell values, one
        for each column in the row.  If ``index`` is a tuple of two
        integers, ``(i,j)``, then return the value of the cell in the
        ``i``th row and the ``j``th column.
        s   Slicing not supportedi   i    i   N(   R*   t   sliceR1   R2   R0   R   R@   (   R   Rj   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   __getitem__.  s
    	! c         C   s  t  | t  r t d   nzt  | t  r t |  d k r | d |  j | d  } } |  j | g  } | |  j | | <|  j d k	 r |  j | | |  } n  |  j
 j | j | |  |  j
 j | j | d  |  j |  n |  j | g  } |  j |  t |  |  j | <|  j d k	 rdg  t |  D]! \ } } |  j | | |  ^ q:} n  |  j
 j | |  |  j
 j | d  |  j |  d S(   s  
        Replace the value of a row or a cell in this table with
        ``val``.

        If ``index`` is an integer, then ``val`` should be a row value
        (i.e., a tuple of cell values, one for each column).  In this
        case, the values of the ``index``th row of the table will be
        replaced with the values in ``val``.

        If ``index`` is a tuple of integers, ``(i,j)``, then replace the
        value of the cell in the ``i``th row and ``j``th column with
        ``val``.
        s   Slicing not supportedi   i    i   N(   R*   R   R1   R2   R0   R@   t   _save_config_infoR   R   R6   R   Ra   R   R   t   _restore_config_infoR   R,   R;   (   R   Rj   Ru   RL   R   t   config_cookieR   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyRw   >  s&    !7c         C   s   t  | t  r t d   n  t  | t  rN t |  d k rN t d   n  |  j | =|  j j |  |  j r~ |  j	   n  d S(   sA   
        Delete the ``row_index``th row from this table.
        s   Slicing not supportedi   s   Cannot delete a single cell!N(
   R*   R   R1   R2   R0   R   R   R   R   R   (   R   Ry   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   __delitem__e  s    !
	c         C   s   t  |  j  S(   s<   
        :return: the number of rows in this table.
        (   R0   R   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   __len__r  s    c         C   s>   t  |  |  j k r: t d | t  |  |  j f   n  d S(   s   
        Helper function: check that a given row value has the correct
        number of elements; and if not, raise an exception.
        s"   Row %r has %d columns; expected %dN(   R0   R   R1   (   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   x  s    c         C   s
   |  j  j S(   s1   A list of the names of the columns in this table.(   R   R_   (   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR_     s    c         C   sA   t  | t  r2 d | k o) |  j k  n r2 | S|  j | Sd S(   s   
        If ``i`` is a valid column index integer, then return it as is.
        Otherwise, check if ``i`` is used as the name for any column;
        if so, return that column's index.  Otherwise, raise a
        ``KeyError`` exception.
        i    N(   R*   R+   R   R   (   R   RL   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR@     s    .c         C   s   |  j  j |  j |   d S(   s$   :see: ``MultiListbox.hide_column()``N(   R   R   R@   (   R   R@   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         C   s   |  j  j |  j |   d S(   s$   :see: ``MultiListbox.show_column()``N(   R   R   R@   (   R   R@   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c         C   s+   |  j  j   } | r# t | d  Sd Sd S(   s   
        Return the index of the currently selected row, or None if
        no row is selected.  To get the row value itself, use
        ``table[table.selected_row()]``.
        i    N(   R   Rk   R+   R6   (   R   t   sel(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   selected_row  s    c         C   s   |  j  j | | |  d S(   s   :see: ``MultiListbox.select()``N(   R   R(   (   R   Rj   R"   Rn   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR(     s    t   togglec         C   s   | d
 k r t  d   n  |  j |  } |  j d t  } | d k rg | |  j k rg |  j j   n1 |  j j d t j	 |  d | d k  | |  _ |  j
   |  j | d t d t |  j r |  j   n  d	 S(   s  
        Sort the rows in this table, using the specified column's
        values as a sort key.

        :param column_index: Specifies which column to sort, using
            either a column index (int) or a column's label name
            (str).

        :param order: Specifies whether to sort the values in
            ascending or descending order:

              - ``'ascending'``: Sort from least to greatest.
              - ``'descending'``: Sort from greatest to least.
              - ``'toggle'``: If the most recent call to ``sort_by()``
                sorted the table by the same column (``column_index``),
                then reverse the rows; otherwise sort in ascending
                order.
        t	   ascendingt
   descendingR   sB   sort_by(): order should be "ascending", "descending", or "toggle".t   index_by_idRt   t   reverseRn   N(   R   R   R   (   R1   R@   R   R/   R   R   R   t   sortt   operatort
   itemgetterR   R   R   R   (   R   R@   t   orderR   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   sort_by  s    	
	c         C   s7   | j  j } |  j j |  r" d S|  j |  d Sd S(   sL   Event handler for clicking on a column label -- sort by
        that column.t   continueN(   RP   R@   R   RD   R   (   R   RX   R@   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s
    c         C   s   |  j  j d d  xv t |  j  D]e \ } } |  j d k	 ru g  t |  D]! \ } } |  j | | |  ^ qK } n  |  j  j d |  q# Wd S(   s  
        Re-draw the table from scratch, by clearing out the table's
        multi-column listbox; and then filling it in with values from
        ``self._rows``.  Note that any cell-, row-, or column-specific
        color configuration that has been done will be lost.  The
        selection will also be lost -- i.e., no row will be selected
        after this call completes.
        i    Rb   N(   R   R   R;   R   R   R6   R   (   R   t   save_configRL   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s
    	7c            s    t      f d   d D  S(   Nc         3   s1   |  ]' } |  j  j    |  d  f Vq d S(   iN(   R   R   (   R   t   k(   R   t   rR   (    s.   lib/python2.7/site-packages/nltk/draw/table.pys	   <genexpr>  s   R   R}   R   R   (   R   R}   R   R   (   Rq   (   R   R   R   (    (   R   R   R   s.   lib/python2.7/site-packages/nltk/draw/table.pyt   _get_itemconfig  s       c            s   | d k r* t t t   j    } n    j   } | r^ | d k	 r^ t   j |  } n  | r t   f d   | D  } n t   f d   | D  } | | f S(   s*  
        Return a 'cookie' containing information about which row is
        selected, and what color configurations have been applied.
        this information can the be re-applied to the table (after
        making modifications) using ``_restore_config_info()``.  Color
        configuration information will be saved for any rows in
        ``row_indices``, or in the entire table, if
        ``row_indices=None``.  If ``index_by_id=True``, the the cookie
        will associate rows with their configuration information based
        on the rows' python id.  This is useful when performing
        operations that re-arrange the rows (e.g. ``sort``).  If
        ``index_by_id=False``, then it is assumed that all rows will be
        in the same order when ``_restore_config_info()`` is called.
        c         3   sP   |  ]F } t    j |  g  t   j  D] }   j | |  ^ q) f Vq d  S(   N(   t   idR   R-   R   R   (   R   R   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pys	   <genexpr>*  s   c         3   sC   |  ]9 } | g  t    j  D] }   j | |  ^ q f Vq d  S(   N(   R-   R   R   (   R   R   R   (   R   (    s.   lib/python2.7/site-packages/nltk/draw/table.pys	   <genexpr>2  s   N(   R6   R,   R-   R0   R   R   R   Rq   (   R   t   row_indicesR   t	   selectiont   config(    (   R   s.   lib/python2.7/site-packages/nltk/draw/table.pyR     s    c   	      C   sG  | \ } } | d k r. |  j j d d  n  | r xt |  j  D] \ } } t |  | k r x> t |  j  D]* } |  j j | | | t |  |  qr Wn  t |  | k rD |  j j	 | d | qD qD Wnn | d k	 r |  j j	 | d | n  xF | D]> } x5 t |  j  D]$ } |  j j | | | | |  qWqWd S(   sy   
        Restore selection & color configuration information that was
        saved using ``_save_config_info``.
        i    Rb   Rn   N(
   R6   R   Rd   R;   R   R   R-   R   Rx   R(   (	   R   t   cookieR   Rn   R   R   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   8  s    + c         C   s	  x2 |  j  j D]$ } t |   | j   k s t  q Wx) |  D]! } t |  |  j k s< t  q< W|  j t |  j  j  k s t  x t |   D]r \ } } xc t |  D]U \ } } |  j d k	 r |  j | | |  } n  |  j  j
 |  | | k s t  q Wq Wd S(   s  
        Verify that the contents of the table's ``_rows`` variable match
        the contents of its multi-listbox (``_mlb``).  This is just
        included for debugging purposes, to make sure that the
        list-modifying operations are working correctly.
        N(   R   Ra   R0   Rm   t   AssertionErrorR   R_   R;   R   R6   R   (   R   R   R   RL   R   t   cell(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   Z  s    "!N(,   R   R   R   R6   R/   R8   R   R?   Rg   RB   Rz   R   Rx   R   R   R   R   R   R   R   R   R>   R   R   Rw   R   R   R   R   R_   R@   R   R   R   R(   R   R   R   R   R.   R   R   R   R   (    (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR   I  sV   %K										'							)		)c    
   	      s!  t        j d   f d    t   d j   d d d d d g d d   }  |  j d	 t d
 d  d d l m } d d l m } x t	 t
 | j   d    D] \ } } | d d k r q n  | j   } x | j |  D]y } y | j   d j   } Wn d } n Xy | j   d j   } Wn d } n X|  j | | j   | | g  q Wq W|  j d d d |  j d d d |  j d d d |  j d d d x` t t |    D]L } xC d D]; }	 |  | |	 f d k r|  j | |	 d d d d qqWqW  j   d  S(   Ns   <Control-q>c            s
     j    S(   N(   t   destroy(   R   (   t   root(    s.   lib/python2.7/site-packages/nltk/draw/table.pyR    u  R!   s   Word Synset Hypernym HyponymRH   i    i   R   c         S   s   d | S(   Ns     %s(    (   RL   R   t   s(    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyR    {  R!   R   R   R   i(   t   wordnet(   t   browni  t   Ns   *none*t   WordR   s   #afat   Synsets   #efet   Hypernyms   #feet   Hyponyms   #ffeR   s   #666R}   (   R   R   (   R   RB   R   t   splitR   R/   t   nltk.corpusR   R   t   sortedR   t   tagged_wordst   lowert   synsetst	   hypernymst
   definitionR>   R   R-   R0   R   t   mainloop(
   t   tableR   R   t   wordt   post   synsett	   hyper_deft   hypo_defR   R   (    (   R   s.   lib/python2.7/site-packages/nltk/draw/table.pyt   demos  sD    	)

'!t   __main__(   R   t
   __future__R    R   t   six.moves.tkinterR   R   R   R   R   R   t   objectR   R  R   (    (    (    s.   lib/python2.7/site-packages/nltk/draw/table.pyt   <module>
   s   (  2  ,	+