
4Ic           @   sm   d  Z  d d k Td d k Z d e f d     YZ d e f d     YZ d   Z e d	 j o e   n d S(
   sC   
Tkinter widgets for displaying multi-column listboxes and tables.
i(   t   *Nt   MultiListboxc           B   s{  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 e	 h  d  Z
 d   Z d   Z d   Z e d   d d Z e d   d d Z e d   d d Z d   Z d    Z d!   Z e	 e	 e d"  Z h  d#  Z d$   Z h  d%  Z h  d&  Z e	 d'  Z d(   Z e	 d)  Z d*   Z d+   Z d,   Z e	 e	 e	 d-  Z  e	 e	 e	 d.  Z! e	 e	 e	 d/  Z" d0   Z# d1   Z$ d2   Z% d3   Z& d4   Z' d5   Z( d6   Z) d7   Z* d8   Z+ d9   Z, d:   Z- d;   Z. d<   Z/ d=   Z0 d>   Z1 d?   Z2 d@   Z3 e Z4 e Z5 e Z6 e. Z7 e/ Z8 e$ Z9 e0 Z: RS(A   s  
    A multi-column listbox, where the current selection applies to an
    entire row.  Based on the 'U{MultiListbox Tkinter widget
    <http://code.activestate.com/recipes/52266/>}' recipe from the
    Python Cookbook.

    For the most part, C{MultiListbox}'s methods just delegate to its
    contained listboxes.  For any methods that do not have docstrings,
    see C{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            s1  t  | t  o t |  } t } n t } t |  d j o t d   n t |    _ g    _	 g    _
 | d# j o d g t |  } n* t |  t |  j o t d   n |   _ t i   |   i    i d d d xt   i  D]\ } }   i | d | | | o] t   d |   i }	   i
 i |	  |	 i d | d d d	 d
 d d d d  | |	 _ n t     i  }
   i	 i |
  |
 i d | d d d	 d
 d d d d  | |
 _ |
 i d   i  |
 i d   i  |
 i d   f d    |
 i d   f d    |
 i d   f d    |
 i d   f d    |
 i d   f d    |
 i d d    |	 i d   i  q W  i d   i    i d   f d      i d   f d      i d   f d       i d!   f d"      i | |  d# S($   s8  
        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 C{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 C{label_*} to configure all labels; and C{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     i  d   S(   i(   t   _scroll(   t   e(   t   self(    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   <lambda>|   s    s
   <Button-5>c            s     i  d  
 S(   i   (   R   (   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   }   s    s   <MouseWheel>c            s     i  |  i  S(    (   R   t   delta(   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   ~   s    s
   <Button-2>c            s     i  |  i |  i  S(    (   t	   scan_markt   xt   y(   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s   <B2-Motion>c            s     i  |  i |  i  S(    (   t   scan_dragtoR   R   (   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s
   <B1-Leave>c         S   s   d  S(   t   break(    (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s   <Up>c            s     i  d  d  S(   R   i(   t   select(   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s   <Down>c            s     i  d  d  S(   R   i   (   R"   (   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s   <Prior>c            s     i  d    i    S(   R   (   R"   t	   _pagesize(   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s   <Next>c            s     i  d    i    S(   R   (   R"   R#   (   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    N(   t
   isinstancet   intt   ranget   Falset   Truet   lent	   ValuErrort   tuplet   _column_namest
   _listboxest   _labelst   Nonet
   ValueErrort   _column_weightst   Framet   __init__t   FRAME_CONFIGt   grid_rowconfiguret	   enumeratet   grid_columnconfiguret   Labelt   LABEL_CONFIGt   appendt   gridt   column_indext   Listboxt   LISTBOX_CONFIGt   bindt   _selectt   _resize_columnt	   configure(   R   t   mastert   columnst   column_weightst   cnft   kwt   include_labelst   it   labelt   lt   lb(    (   R   s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR3   ;   sV    
			 ((	c         C   sL  | i  i d  o t Sn d |  _ | i  |  j o[ x t |  i  D]C \ } } t | i | i	   | i
    d j  o | |  _ qD qD Wnk | i | i  i
   d j o | i  i |  _ n; | i d j  o* | i  i d j o | i  i d |  _ n |  i d j	 o; | i  i d |  i  | i  i d | i |  i  t Sn t Sd S(	   s   
        Callback used to resize a column of the table.  Return C{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
        C{False} otherwies.
        s   <ButtonRelease>i
   i   i    i   s   <Motion>s   <ButtonRelease-%d>N(   t   widgetR?   R'   R/   t   _resize_column_indexR6   R-   t   absR   t   winfo_xt   winfo_widthR<   t   _resize_column_motion_cbt   numt   _resize_column_buttonrelease_cbR(   (   R   t   eventRI   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRA      s$    		 *#
c         C   s   |  i  |  i } | i   t | d  } | i | i i   } | i   | i   } t d | d t | | |   | d <d  S(   Nt   widthi   (	   R-   RN   RQ   t   floatR   RM   RP   t   maxR%   (   R   RU   RL   t	   charwidtht   x1t   x2(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRR      s
    c         C   s+   | i  i d | i  | i  i d  d  S(   Ns   <ButtonRelease-%d>s   <Motion>(   RM   t   unbindRS   (   R   RU   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRT      s    c         C   s   |  i  S(    (   R,   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    t   docs_   
        A tuple containing the names of the columns used by this
        multi-column listbox.c         C   s   t  |  i  S(    (   R+   R.   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    s  
        A tuple containing the C{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
        C{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.c         C   s   t  |  i  S(    (   R+   R-   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    sN  
        A tuple containing the C{Tkinter.Listbox} widgets used to
        display individual columns.  These widgets will all be
        augmented with a C{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.c         C   sM   | i  i | i  } |  i d d  |  i |  |  i |  |  i   d  S(   Ni    t   end(   RM   t   nearestR   t   selection_cleart   selection_sett   activatet   focus(   R   R   RI   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR@      s
    c         C   s(   x! |  i  D] } | i | d  q
 Wd S(   Nt   unitR!   (   R-   t   yview_scroll(   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    
 c         C   s&   t  |  i d   t  |  i d   S(   s2   @return: The number of rows that makes up one pages
   @0,1000000s   @0,0(   R%   t   index(   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR#      s    c         C   s   | d j	 o | d j	 o t d   n | d j	 oE t |  i    d j o d | } q| t |  i   d  | } n |  i d d  | d j	 oK t t | d  |  i   d  } |  i	 |  | o |  i
 |  q n d S(   s  
        Set the selected row.  If C{index} is specified, then select
        row C{index}.  Otherwise, if C{delta} is specified, then move
        the current selection by C{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 C{self.see()} with the newly
            selected index, to ensure that it is visible.
        s$   specify index or delta, but not bothi    iR^   i   N(   R/   R0   R)   t   curselectionR%   R`   t   minRX   t   sizeRa   t   see(   R   Rf   R   Rj   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR"      s    "c         K   s   t  | i   | i    } x | i   D] \ } } | i d  p | i d  o2 x |  i D]  } | i h  | | d < q_ Wq) | i d  p | i d  o2 xH |  i D]  } | i h  | | d < q Wq) t i |  h  | | < q) Wd S(   s6  
        Configure this widget.  Use C{label_*} to configure all
        labels; and C{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   dictt   itemst
   startswithR.   RB   R-   R2   (   R   RF   RG   t   keyt   valRJ   t   listbox(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRB     s    	  
 " 
 "c         C   s   |  i  h  | | < d S(   sz   
        Configure this widget.  This is equivalent to
        C{self.configure({key,val})}.  See L{configure()}.
        N(   RB   (   R   Rp   Rq   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   __setitem__-  s    c         K   s+   x$ |  i  D] } | i | | |  q
 Wd S(   s   
        Configure all table cells in the given row.  Valid keyword
        arguments are: C{background}, C{bg}, C{foreground}, C{fg},
        C{selectbackground}, C{selectforeground}.
        N(   R-   t   itemconfigure(   R   t	   row_indexRF   RG   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   rowconfigure4  s    
 c         K   s   |  i  | } t | i   | i    } xw | i   D]i \ } } | d j o: xM t | i    D] } | i | h  | | < qb Wq6 | i h  | | < q6 Wd S(	   s   
        Configure all table cells in the given column.  Valid keyword
        arguments are: C{background}, C{bg}, C{foreground}, C{fg},
        C{selectbackground}, C{selectforeground}.
        R   t   bgR	   t   fgR   t   selectforegroundN(   s
   backgrounds   bgs
   foregrounds   fgs   selectbackgrounds   selectforeground(   R-   Rm   Rn   R&   Ri   Rt   RB   (   R   t	   col_indexRF   RG   RL   Rp   Rq   RI   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   columnconfigure<  s     
 'c         K   s    |  i  | } | i | | |  S(   s   
        Configure the table cell at the given row and column.  Valid
        keyword arguments are: C{background}, C{bg}, C{foreground},
        C{fg}, C{selectbackground}, C{selectforeground}.
        (   R-   Rt   (   R   Ru   Rz   RF   RG   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRt   L  s    c         G   sz   x: | D]2 } t  |  t  |  i  j o t d   q q Wx6 t |  i t |    D] \ } } | i | |  qV Wd S(   s.  
        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 C{'end'}) accepted by
        C{Tkinter.Listbox}.
        sD   rows should be tuples whose length is equal to the number of columnsN(   R)   R,   R0   t   zipR-   t   insert(   R   Rf   t   rowst   eltRL   t   elts(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR}   Y  s      c         C   st   g  } |  i  D] } | | i | |  q ~ } | o/ g  } t |   D] } | t |  qH ~ Sn t |  Sd S(   s  
        Return the value(s) of the specified row(s).  If C{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(   R-   t   getR|   R+   (   R   t   firstt   lastt   _[1]RL   t   valuest   _[2]R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   h  s    0/c   
      C   s   |  i  d d d |  \ } } } } |  i | i |  \ } } } }	 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 C{(left, top, width, height)}.
        R   i    R   (   t	   grid_bboxR-   t   bboxR%   (
   R   R   t   colt   dxt   dyt   _R   R   t   wt   h(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   u  s    $"c         C   sG   |  i  o |  i  | i   n |  i | i   |  i | d d d S(   s.  
        Hide the given column.  The column's state is still
        maintained: its values will still be returned by L{get()}, and
        you must supply its values when calling L{insert()}.  It is
        safe to call this on a column that is already hidden.

        @see: L{show_column()}
        R   i    N(   R.   t   grid_forgett	   listboxesR7   (   R   Rz   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   hide_column  s    	
c         C   s   |  i  | } |  i o3 |  i | i d | d d d d d d d d  n |  i | i d | d d d d d d d d  |  i | d	 | d
 S(   s   
        Display a column that has been hidden using L{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(   R1   R.   R;   R-   R7   (   R   Rz   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   show_column  s    
c         C   s1   g  } |  i  D] } | | i | | |  q ~ S(   sL  
        Add a binding to each C{Tkinter.Label} widget in this
        mult-column listbox that will call C{func} in response to the
        event C{sequence}.

        @return: A list of the identifiers of replaced binding
            functions (if any), allowing for their deletion (to
            prevent a memory leak).
        (   t   column_labelsR?   (   R   t   sequencet   funct   addR   RJ   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   bind_to_labels  s    
c         C   s+   x$ |  i  D] } | i | | |  q
 Wd S(   sN  
        Add a binding to each C{Tkinter.Listbox} widget in this
        mult-column listbox that will call C{func} in response to the
        event C{sequence}.

        @return: A list of the identifiers of replaced binding
            functions (if any), allowing for their deletion (to
            prevent a memory leak).
        N(   R   R?   (   R   R   R   R   Rr   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   bind_to_listboxes  s    

 c         C   s&   |  i  | | |  |  i | | |  S(   sc  
        Add a binding to each C{Tkinter.Label} and C{Tkinter.Listbox}
        widget in this mult-column listbox that will call C{func} in
        response to the event C{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%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   bind_to_columns  s    
c         O   s   |  i  d i | |   S(   Ni    (   R-   Rg   (   R   t   argst   kwargs(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRg     s    c         O   s   |  i  d i | |   S(   Ni    (   R-   t   selection_includes(   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         O   s   |  i  d i | |   S(   Ni    (   R-   t   itemcget(   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         O   s   |  i  d i | |   S(   Ni    (   R-   Ri   (   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRi     s    c         O   s   |  i  d i | |   S(   Ni    (   R-   Rf   (   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRf     s    c         O   s   |  i  d i | |   S(   Ni    (   R-   R_   (   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR_     s    c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   Rb   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRb     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   t   delete(   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   R   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   R    (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   Rj   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRj     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   t   selection_anchor(   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   R`   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR`     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   Ra   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRa     s    
 c         O   s*   x# |  i  D] } | i | |   } q
 W| S(   N(   R-   t   yview(   R   R   R   RL   t   v(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   t   yview_moveto(   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    
 c         O   s(   x! |  i  D] } | i | |   q
 Wd  S(   N(   R-   Re   (   R   R   R   RL   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRe     s    
 (;   t   __name__t
   __module__t   __doc__Rm   R(   R4   R9   R'   R>   R/   R3   RA   RR   RT   t   propertyt   column_namesR   R   R@   R   R#   R"   RB   Rs   Rv   R{   Rt   R}   R   R   R   R   R   R   R   Rg   R   R   Ri   Rf   R_   Rb   R   R   R    Rj   R   R`   Ra   R   R   Re   t
   itemconfigt	   rowconfigt   columnconfigt   select_anchort   select_cleart   select_includest
   select_set(    (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s   
		^	 									#																						t   Tablec           B   s  e  Z d  Z e e e e e h  d  Z d   Z d   Z d   Z e e e d  Z	 h  d  Z
 h  d  Z e d  Z e e e d	  Z e e e d
  Z e e e 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   d d Z d   Z d   Z d   Z  d   Z! e e e d  Z" d d  Z# d   Z$ e d   Z% d!   Z& e e' d"  Z( e' e' d#  Z) e' Z* d$   Z+ RS(%   s  
    A display widget for a table of values, based on a L{MultiListbox}
    widget.  For many purposes, C{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 L{rowconfig()}, L{columnconfig()}, and L{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 I{columns} will not be
    applied to the new row.

    Note: Although C{Table} acts like a widget in some ways (e.g., it
    defines L{grid()}, L{pack()}, and L{bind()}), it is not itself a
    widget; it just contains one.  This is because widgets need to
    define C{__getitem__()}, C{__setitem__()}, and C{__nonzero__()} in
    a way that's incompatible with the fact that C{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 j o g  |  _	 n@ g  }
 | D]( } |
 g  } | D] } | | q ~ qk ~
 |  _	 x |  i	 D] } |  i
 |  q Wt |  i | | | |	  |  _ |  i i d d d t d d  | o[ t |  i d d d	 |  i i } | i |  i i d
 d <| i d d d d  | |  _ n d |  _ | o: x7 t |  i i  D] \ } } | i d |  i  qWn |  i   d S(   s  
        Construct a new Table widget.

        @type master: C{Tkinter.Widget}
        @param master: The widget that should contain the new table.

        @type column_names: C{list} of C{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: C{list} of C{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: C{bool}
        @param scrollbar: If true, then create a scrollbar for the
            new table widget.
            
        @type click_to_sort: C{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: C{function}
        @param reprfunc: If specified, then use this function to
            convert each table cell value to a string suitable for
            display.  C{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 C{MultiListbox}.  See L{MultiListbox.__init__()}
            for details.
        c         s   s%   x |  ] \ } } | | f Vq Wd  S(   N(    (   t   .0RI   t   c(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pys	   <genexpr>`  s    t   sidet   leftt   expandt   fillt   botht   orientt   verticalt   commandi    t   yscrollcommandt   rightR   s
   <Button-1>N(   R)   t   _num_columnst	   _reprfuncR2   t   _frameRm   R6   t   _column_name_to_indexR/   t   _rowst	   _checkrowR   t   _mlbt   packR(   t	   ScrollbarR   t   setR   t
   _scrollbart   _sortkeyR   R?   t   _sortt   _fill_table(   R   RC   R   R~   RE   t	   scrollbart   click_to_sortt   reprfuncRF   RG   R   R   R   R   t   sbRI   RK   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR3   1  s0    +		?
 	 c         O   s   |  i  i | |   d S(   sq   Position this table's main frame widget in its parent
        widget.  See C{Tkinter.Frame.pack()} for more info.N(   R   R   (   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         O   s   |  i  i | |   d S(   sq   Position this table's main frame widget in its parent
        widget.  See C{Tkinter.Frame.grid()} for more info.N(   R   R;   (   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR;     s    c         C   s   |  i  i   d S(   s-   Direct (keyboard) input foxus to this widget.N(   R   Rc   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRc     s    c         C   s   |  i  i | | |  d S(   sm   Add a binding to this table's main frame that will call
        C{func} in response to the event C{sequence}.N(   R   R?   (   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR?     s    c         K   s   |  i  i | | |  d S(   s$   @see: L{MultiListbox.rowconfigure()}N(   R   Rv   (   R   Ru   RF   RG   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRv     s    c         K   s)   |  i  |  } |  i i | | |  d S(   s'   @see: L{MultiListbox.columnconfigure()}N(   R<   R   R{   (   R   Rz   RF   RG   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR{     s    c         K   s(   |  i  |  } |  i i | | | |  S(   s%   @see: L{MultiListbox.itemconfigure()}(   R<   R   Rt   (   R   Ru   Rz   RF   RG   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRt     s    c         C   s   |  i  i | | |  S(   s&   @see: L{MultiListbox.bind_to_labels()}(   R   R   (   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         C   s   |  i  i | | |  S(   s)   @see: L{MultiListbox.bind_to_listboxes()}(   R   R   (   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         C   s   |  i  i | | |  S(   s'   @see: L{MultiListbox.bind_to_columns()}(   R   R   (   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c         C   s   |  i  |  |  i i | |  |  i d j	 o@ g  } t |  D]" \ } } | |  i | | |  qA ~ } n |  i i | |  |  i o |  i   n d S(   sR  
        Insert a new row into the table, so that its row index will be
        C{row_index}.  If the table contains any rows whose row index
        is greater than or equal to C{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   R/   R6   R   t   _DEBUGt   _check_table_vs_mlb(   R   Ru   t   rowvalueR   t   jR   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR}     s    
9c         C   s:   x | D] } |  i  |  q W|  i o |  i   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%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   extend  s     c         C   s5   |  i  t |  i  |  |  i o |  i   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}   R)   R   R   R   (   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR:     s    c         C   s8   g  |  _  |  i i d d  |  i o |  i   n d S(   s0   
        Delete all rows in this table.
        i    R^   N(   R   R   R   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   clear  s    	c         C   s|   t  | t  o t d   nY t  | t  o7 t |  d j o$ |  i | d |  i | d  Sn t |  i |  Sd S(   s  
        Return the value of a row or a cell in this table.  If
        C{index} is an integer, then the row value for the C{index}th
        row.  This row value consists of a tuple of cell values, one
        for each column in the row.  If C{index} is a tuple of two
        integers, C{(i,j)}, then return the value of the cell in the
        C{i}th row and the C{j}th column.
        s   Slicing not supportedi   i    i   N(   R$   t   sliceR0   R+   R)   R   R<   (   R   Rf   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   __getitem__  s
    	#$c         C   s  t  | t  o t d   nt  | t  o t |  d j o | d |  i | d  } } |  i | g  } | |  i | | <|  i d j	 o |  i | | |  } n |  i
 i | i | |  |  i
 i | i | d  |  i |  n |  i | g  } |  i |  t |  |  i | <|  i d j	 o@ g  } t |  D]" \ } } | |  i | | |  qF~ } n |  i
 i | |  |  i
 i | d  |  i |  d S(   s  
        Replace the value of a row or a cell in this table with
        C{val}.

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

        If C{index} is a tuple of integers, C{(i,j)}, then replace the
        value of the cell in the C{i}th row and C{j}th column with
        C{val}.
        s   Slicing not supportedi   i    i   N(   R$   R   R0   R+   R)   R<   t   _save_config_infoR   R   R/   R   R   R}   R   t   _restore_config_infoR   t   listR6   (   R   Rf   Rq   RI   R   t   config_cookieR   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyRs     s&    #@c         C   s   t  t t  o t d   n t  | t  o# t |  d j o t d   n |  i | =|  i i |  |  i	 o |  i
   n d S(   s@   
        Delete the C{row_index}th row from this table.
        s   Slicing not supportedi   s   Cannot delete a single cell!N(   R$   Rf   R   R0   R+   R)   R   R   R   R   R   (   R   Ru   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   __delitem__!  s    #
c         C   s   t  |  i  S(   s<   
        @return: the number of rows in this table.
        (   R)   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   __len__-  s    c         C   s@   t  |  |  i j o& t d | t  |  |  i 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(   R)   R   R0   (   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   3  s    c         C   s
   |  i  i S(    (   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   @  s    R]   s:   
        A list of the names of the columns in this table.c         C   sH   t  | t  o) d | j o |  i j  n o | Sn |  i | Sd S(   s   
        If C{i} is a valid column index integer, then return it as is.
        Otherwise, check if C{i} is used as the name for any column;
        if so, return that column's index.  Otherwise, raise a
        C{KeyError} exception.
        i    N(   R$   R%   R   R   (   R   RI   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR<   C  s    1c         C   s   |  i  i |  i |   d S(   s#   @see: L{MultiListbox.hide_column()}N(   R   R   R<   (   R   R<   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   P  s    c         C   s   |  i  i |  i |   d S(   s#   @see: L{MultiListbox.show_column()}N(   R   R   R<   (   R   R<   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR   T  s    c         C   s0   |  i  i   } | o t | d  Sn d Sd S(   s   
        Return the index of the currently selected row, or C{None} if
        no row is selected.  To get the row value itself, use
        C{table[table.selected_row()]}.
        i    N(   R   Rg   R%   R/   (   R   t   sel(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   selected_row\  s    c         C   s   |  i  i | | |  d S(   s   @see: L{MultiListbox.select()}N(   R   R"   (   R   Rf   R   Rj   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR"   f  s    t   togglec         C   s   | d
 j o t  d   n |  i |  } |  i d t  } | d j o! | |  i j o |  i i   n2 |  i i d t i	 |  d | d j  | |  _ |  i
   |  i | d t d t |  i o |  i   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 (C{int}) or a column's label name
            (C{str}).
            
        @param order: Specifies whether to sort the values in
            ascending or descending order:

              - C{'ascending'}: Sort from least to greatest.
              - C{'descending'}: Sort from greatest to least.
              - C{'toggle'}: If the most recent call to C{sort_by()}
                sorted the table by the same column C({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_idRp   t   reverseRj   N(   s	   ascendings
   descendings   toggle(   R0   R<   R   R(   R   R   R   t   sortt   operatort
   itemgetterR   R   R   R   (   R   R<   t   orderR   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   sort_byn  s    	
c         C   s<   | i  i } |  i i |  o d Sn |  i |  d Sd S(   sL   Event handler for clicking on a column label -- sort by
        that column.t   continueN(   RM   R<   R   RA   R   (   R   RU   R<   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s
    c         C   s   |  i  i d d  x t |  i  D]o \ } } |  i d j	 o@ g  } t |  D]" \ } } | |  i | | |  qP ~ } n |  i  i 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
        C{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    R^   N(   R   R   R6   R   R   R/   R}   (   R   t   save_configRI   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    	 @c            s    t      f d   d D  S(   Nc         3   s5   x. |  ]' } |  i  i    |  d  f Vq Wd S(   iN(   R   R   (   R   t   k(   R   t   rR   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pys	   <genexpr>  s   	R	   Ry   R   R   (   s
   foregrounds   selectforegrounds
   backgrounds   selectbackground(   Rm   (   R   R   R   (    (   R   R   R   s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   _get_itemconfig  s     c            s   | t  j o t t   i   } n   i   } | o$ | t  j	 o t   i |  } n | o  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 L{_restore_config_info()}.  Color
        configuration information will be saved for any rows in
        C{row_indices}, or in the entire table, if
        C{row_indices=None}.  If C{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. C{sort}).  If
        C{index_by_id=False}, then it is assumed that all rows will be
        in the same order when C{_restore_config_info()} is called.
        c         3   s\   xU |  ]N } t    i |  g  } t   i  D] } |   i | |  q0 ~ f Vq Wd  S(   N(   t   idR   R&   R   R   (   R   R   R   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pys	   <genexpr>  s   	c         3   sO   xH |  ]A } | g  } t    i  D] } |   i | |  q# ~ f Vq Wd  S(   N(   R&   R   R   (   R   R   R   R   (   R   (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pys	   <genexpr>  s   	(   R/   R&   R)   R   R   R   Rm   (   R   t   row_indicesR   t	   selectiont   config(    (   R   s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    c   	      C   sQ  | \ } } | d j o |  i i d d  n | o xt |  i  D] \ } } t |  | j oB x? t |  i  D]* } |  i i | | | t |  |  qv Wn t |  | j o |  i i	 | d | qG qG Wnq | d j	 o |  i i	 | d | n xF | D]> } x5 t |  i  D]$ } |  i i | | | | |  q!WqWd S(   sx   
        Restore selection & color configuration information that was
        saved using L{_save_config_info}.
        i    R^   Rj   N(
   R/   R   R`   R6   R   R   R&   R   Rt   R"   (	   R   t   cookieR   Rj   R   R   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s&      ,"  c      
   C   s  x4 |  i  i D]& } t |   | i   j p t  q Wx+ |  D]# } t |  |  i j p t  q> W|  i t |  i  i  j p t  x t |   D]v \ } } xg t |  D]Y \ } } |  i d j	 o |  i | | |  } n |  i  i
 |  | | j p t  q Wq Wd S(   s  
        Verify that the contents of the table's L{_rows} variable match
        the contents of its multi-listbox (L{_mlb}).  This is just
        included for debugging purposes, to make sure that the
        list-modifying operations are working correctly.
        N(   R   R   R)   Ri   t   AssertionErrorR   R   R6   R   R/   R   (   R   R   R   RI   R   t   cell(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s     $ !#  (,   R   R   R   R/   R(   R3   R   R;   Rc   R?   Rv   R{   Rt   R   R   R   R   R   R   R}   R   R:   R   R   Rs   R   R   R   R   R   R<   R   R   R   R"   R   R   R   R   R'   R   R   R   R   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     sT   %Q						
			(								
&		%c    
         s  t        i d   f d    t   d i   d d d d d g d d   }  |  i d	 t d
 d  d d k l } d d k l } x t	 t
 | i   d    D] \ } } | d d j o q n | i   } x | i |  D]q } | i   d g d } | i   d g d } |  i | t | d d  t | d d  t | d d  g  q Wq W|  i d d d |  i d d d |  i d d d |  i d d d xb t t |    D]N } xE d  D]= }	 |  | |	 f d j o  |  i | |	 d d d d qqWqW  i   d  S(!   Ns   <Control-q>c            s
     i    S(    (   t   destroy(   R   (   t   root(    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR     s    s   Word Synset Hypernym HyponymRE   i    i   R   c         S   s   d  | S(   s     %s(    (   RI   R   t   s(    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyR      s    R   R   R   i(   t   wordnet(   t   browni  t   Nt    t
   definitions   *none*t   WordR   s   #afat   Synsets   #efet   Hypernyms   #feet   Hyponyms   #ffeR	   s   #666Ry   (   R   R   (   t   TkR?   R   t   splitR   R(   t   nltk.corpusR   R   t   sortedR   t   tagged_wordst   lowert   synsetst	   hypernymst   hyponymsR:   t   getattrR   R&   R)   R   t   mainloop(
   t   tableR   R   t   wordt   post   synsett   hypert   hypoR   R   (    (   R   s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pyt   demo  s@    	  	  t   __main__(	   R   t   utilR   R2   R   t   objectR   R  R   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/draw/table.pys   <module>   s   
   	!