
    /h                     x    S r SSKrSSKJrJrJrJrJr   " S S\5      r " S S5      r	S r
\S	:X  a  \
" 5         gg)
zC
Tkinter widgets for displaying multi-column listboxes and tables.
    N)FrameLabelListbox	ScrollbarTkc            
          \ rS rSrSr\" SSSS9r\" SSSS	S
S9r\" SSSSSSSS9rS0 4S jr	S r
S rS r\S 5       r\S 5       r\S 5       rS rS rS rS;S jr0 4S jrS r0 4S jr0 4S jrS<S  jrS! rS<S" jrS# rS$ rS% rS=S& jrS=S' jr S=S( jr!S) r"S* r#S+ r$S, r%S- r&S. r'S/ r(S0 r)S1 r*S2 r+S3 r,S4 r-S5 r.S6 r/S7 r0S8 r1S9 r2\r3\r4\r5\-r6\.r7\#r8\/r9S:r:g)>MultiListbox   a  
A multi-column listbox, where the current selection applies to an
entire row.  Based on the MultiListbox Tkinter widget
recipe from the Python Cookbook (https://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.
z#888T   )
background	takefocushighlightthicknessraisedzhelvetica -16 boldz#444white)borderwidthrelieffontr   
foregroundr   Fnone)r   selectborderwidthr   exportselectionselectbackgroundactivestyler   Nc           	        ^  [        U[        5      (       a  [        [        U5      5      nSnOSn[	        U5      S:X  a  [        S5      e[        U5      T l        / T l        / T l	        Uc  S/[	        U5      -  nO#[	        U5      [	        U5      :w  a  [        S5      eUT l
        [        R                  " T U40 T R                  D6  T R                  SSS9  [        T R                  5       GH  u  pxT R!                  XsU   S9  U(       aL  [#        T 4S	U0T R$                  D6n	T R                  R'                  U	5        U	R)                  USS
SSS9  Xyl        [-        T 40 T R.                  D6n
T R                  R'                  U
5        U
R)                  USS
SSS9  Xzl        U
R1                  ST R2                  5        U
R1                  ST R2                  5        U
R1                  SU 4S j5        U
R1                  SU 4S j5        U
R1                  SU 4S j5        U
R1                  SU 4S j5        U
R1                  SU 4S j5        U
R1                  SS 5        U
R1                  ST R4                  5        GM     T R1                  ST R4                  5        T R1                  SU 4S j5        T R1                  SU 4S j5        T R1                  SU 4S j5        T R1                  S U 4S! j5        T R6                  " U40 UD6  g)"a  
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,
    then 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.:
        >>> root = Tk()  # doctest: +SKIP
        >>> MultiListbox(root, ["Subject", "Sender", "Date"], label_foreground='red').pack()  # doctest: +SKIP
FTr   zExpected at least one columnNr   z*Expected one column_weight for each columnweighttextnewscolumnrowstickypadxpady
<Button-1>z<B1-Motion>z
<Button-4>c                 &   > TR                  S5      $ )N_scrolleselfs    G/var/www/auris/envauris/lib/python3.13/site-packages/nltk/draw/table.py<lambda>'MultiListbox.__init__.<locals>.<lambda>       DLL,<    z
<Button-5>c                 &   > TR                  S5      $ )Nr   r(   r*   s    r-   r.   r/      r0   r1   z<MouseWheel>c                 :   > TR                  U R                  5      $ N)r)   deltar*   s    r-   r.   r/      s    dll177.Cr1   z
<Button-2>c                 P   > TR                  U R                  U R                  5      $ r4   )	scan_markxyr*   s    r-   r.   r/      s    DNN133,Dr1   z<B2-Motion>c                 P   > TR                  U R                  U R                  5      $ r4   )scan_dragtor8   r9   r*   s    r-   r.   r/      s    T-=-=acc133-Gr1   z
<B1-Leave>c                     g)Nbreak )r+   s    r-   r.   r/      s    Gr1   z<Up>c                 "   > TR                  SS9$ )Nr'   r5   selectr*   s    r-   r.   r/      s    DKKbK$9r1   z<Down>c                 "   > TR                  SS9$ )Nr   r@   rA   r*   s    r-   r.   r/      s    dkkk&:r1   z<Prior>c                 @   > TR                  TR                  5       * S9$ Nr@   rB   	_pagesizer*   s    r-   r.   r/      s    t{{$..:J9J{'Kr1   z<Next>c                 >   > TR                  TR                  5       S9$ rE   rF   r*   s    r-   r.   r/      s    dkk8Hk&Ir1   )
isinstanceintlistrangelen
ValueErrortuple_column_names
_listboxes_labels_column_weightsr   __init__FRAME_CONFIGgrid_rowconfigure	enumerategrid_columnconfigurer   LABEL_CONFIGappendgridcolumn_indexr   LISTBOX_CONFIGbind_select_resize_column	configure)r,   mastercolumnscolumn_weightscnfkwinclude_labelsilabelllbs   `          r-   rT   MultiListbox.__init__>   s   * gs##5>*G"N!Nw<1;<< #7^ !S3w</N CL0IJJ- 	tV9t'8'89q+!$"4"45HA%%aq0A%B $@U@d.?.?@##A&aQvAAF!" 5!4!45BOO""2&GG1!FGCO GGL$,,/GGM4<<0GGL"<=GGL"<=GGN$CDGGL"DEGGM#GH GGL"34GGL$"5"56= 6D 			, 3 34 			&9:		(:;		)KL		(IJ 	s!b!r1   c                 "   UR                   R                  S5      (       a  gSU l        UR                   U L ab  [        U R                  5       HH  u  p#[        UR                  UR                  5       UR                  5       -   -
  5      S:  d  MB  X l        MJ     OUR                  UR                   R                  5       S-
  :  a  UR                   R                  U l        OHUR                  S:  a8  UR                   R                  S:w  a  UR                   R                  S-
  U l        U R                  bZ  UR                   R                  SU R                  5        UR                   R                  S	UR                  -  U R                  5        g
g)z
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.
z<ButtonRelease>FN
      r   r   <Motion><ButtonRelease-%d>T)widgetr^   _resize_column_indexrW   rQ   absr8   winfo_xwinfo_widthr\   _resize_column_motion_cbnum_resize_column_buttonrelease_cb)r,   eventrh   rk   s       r-   r`   MultiListbox._resize_column   s1    <<.// %)!<<4"4??3uww"**,1A"ABCbH01- 4 WW002Q67(-(A(AD%WWq[U\\66!;(-(A(AA(ED% $$0LLj$*G*GHLL$uyy0$2V2V r1   c                 8   U R                   U R                     nUR                  5       US   -  nUR                  UR                  R                  5       -   nUR                  5       UR                  5       -   n[        S[        US   XE-
  U-  -   5      5      US'   g )Nwidth   )rQ   rs   rv   r8   rr   ru   maxrJ   )r,   rz   rk   	charwidthx1x2s         r-   rw   %MultiListbox._resize_column_motion_cb   s    __T667NN$r'{2	WWu||++--ZZ\BNN,,!SGI/E!EFG7r1   c                     UR                   R                  SUR                  -  5        UR                   R                  S5        g )Nrq   rp   )rr   unbindrx   )r,   rz   s     r-   ry   ,MultiListbox._resize_column_buttonrelease_cb   s0    0599<=J'r1   c                     U R                   $ )zP
A tuple containing the names of the columns used by this
multi-column listbox.
)rP   r,   s    r-   column_namesMultiListbox.column_names   s     !!!r1   c                 ,    [        U R                  5      $ )a  
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.
)rO   rR   r   s    r-   column_labelsMultiListbox.column_labels   s     T\\""r1   c                 ,    [        U R                  5      $ )a)  
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.
)rO   rQ   r   s    r-   	listboxesMultiListbox.listboxes   s     T__%%r1   c                     UR                   R                  UR                  5      nU R                  SS5        U R	                  U5        U R                  U5        U R                  5         g )Nr   end)rr   nearestr9   selection_clearselection_setactivatefocus)r,   r+   rh   s      r-   r_   MultiListbox._select   sM    HHQSS!Q&1a

r1   c                 N    U R                    H  nUR                  US5        M     g)Nunitr=   rQ   yview_scroll)r,   r5   rk   s      r-   r)   MultiListbox._scroll   s!    //BOOE6* "r1   c                 l    [        U R                  S5      5      [        U R                  S5      5      -
  $ )z2:return: The number of rows that makes up one pagez
@0,1000000z@0,0)rJ   indexr   s    r-   rG   MultiListbox._pagesize   s)    4::l+,s4::f3E/FFFr1   c                 ~   Ub  Ub  [        S5      eUbB  [        U R                  5       5      S:X  a  SU-   nO[        U R                  5       S   5      U-   nU R	                  SS5        UbR  [        [        US5      U R                  5       S-
  5      nU R                  U5        U(       a  U R                  U5        ggg)a  
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.
Nz$specify index or delta, but not bothr   r'   r   r   )
rN   rM   curselectionrJ   r   minr   sizer   seer,   r   r5   r   s       r-   rB   MultiListbox.select  s     E$5CDD 4$$&'1,U
D--/23e; 	Q& E1tyy{Q7Eu% 	 r1   c                 L   [        [        UR                  5       5      [        UR                  5       5      -   5      n[        UR                  5       5       H  u  p4UR                  S5      (       d  UR                  S5      (       a+  U R                   H  nUR                  USS U05        M     M\  UR                  S5      (       d  UR                  S5      (       a+  U R                   H  nUR                  USS U05        M     M  [        R
                  " XU05        M     g)aj  
Configure this widget.  Use ``label_*`` to configure all
labels; and ``listbox_*`` to configure all listboxes.  E.g.:

        >>> master = Tk()  # doctest: +SKIP
        >>> mlb = MultiListbox(master, 5)  # doctest: +SKIP
        >>> mlb.configure(label_foreground='red')  # doctest: +SKIP
        >>> mlb.configure(listbox_foreground='red')  # doctest: +SKIP
label_zlabel-   Nlistbox_zlistbox-   )dictrK   items
startswithrR   ra   rQ   r   )r,   re   rf   keyvalri   listboxs          r-   ra   MultiListbox.configure*  s     4		$tBHHJ'778SYY[)HC~~h''3>>(+C+C!\\EOOSWcN3 *
++s~~j/I/I#G%%s12wn5  / Cj1 *r1   c                 (    U R                  X05        g)zd
Configure this widget.  This is equivalent to
``self.configure({key,val``)}.  See ``configure()``.
N)ra   )r,   r   r   s      r-   __setitem__MultiListbox.__setitem__?  s    
 	z"r1   c                 P    U R                    H  nUR                  " X40 UD6  M     g)z
Configure all table cells in the given row.  Valid keyword
arguments are: ``background``, ``bg``, ``foreground``, ``fg``,
``selectbackground``, ``selectforeground``.
NrQ   itemconfigure)r,   	row_indexre   rf   rk   s        r-   rowconfigureMultiListbox.rowconfigureF  s%     //BY2r2 "r1   c                 x   U R                   U   n[        [        UR                  5       5      [        UR                  5       5      -   5      n[        UR                  5       5       HR  u  pVUS;   a5  [	        UR                  5       5       H  nUR                  XuU05        M     M@  UR                  XV05        MT     g)z
Configure all table cells in the given column.  Valid keyword
arguments are: ``background``, ``bg``, ``foreground``, ``fg``,
``selectbackground``, ``selectforeground``.
)r   bgr   fgr   selectforegroundN)rQ   r   rK   r   rL   r   r   ra   )r,   	col_indexre   rf   rk   r   r   rh   s           r-   columnconfigureMultiListbox.columnconfigureO  s     __Y'4		$tBHHJ'778SYY[)HC   rwwy)A$$Qc
3 * cZ( *r1   c                 F    U R                   U   nUR                  " X40 UD6$ )z
Configure the table cell at the given row and column.  Valid
keyword arguments are: ``background``, ``bg``, ``foreground``,
``fg``, ``selectbackground``, ``selectforeground``.
r   )r,   r   r   re   rf   rk   s         r-   r   MultiListbox.itemconfiguref  s(     __Y'	5"55r1   c                     U H0  n[        U5      [        U R                  5      :w  d  M'  [        S5      e   [        U R                  [        [        U6 5      5       H  u  pEUR                  " U/UQ76   M     g)a   
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``.
zDrows should be tuples whose length is equal to the number of columnsN)rM   rP   rN   ziprQ   rK   insert)r,   r   rowseltrk   eltss         r-   r   MultiListbox.inserts  sj     C3x3t1122 8   DOOT#t*-=>HBIIe#d# ?r1   c                     U R                    Vs/ s H  o3R                  X5      PM     nnU(       a"  [        U6  Vs/ s H  n[        U5      PM     sn$ [        U5      $ s  snf s  snf )z
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.
)rQ   getr   rO   )r,   firstlastrk   valuesr!   s         r-   r   MultiListbox.get  sV     15@"&&%@*-v,7,3E#J,77= 	 A7s
   AA$c                     U R                  SUS9u  p4  nU R                  U   R                  U5      u  pgp[        U5      [        U5      -   [        U5      [        U5      -   [        U5      [        U	5      4$ )z
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   )r!   r    )	grid_bboxrQ   bboxrJ   )
r,   r!   coldxdy_r8   r9   whs
             r-   r   MultiListbox.bbox  sj     ~~!C~81__S)..s3
a1vBQ#b'!13q63q6AAr1   c                     U R                   (       a  U R                   U   R                  5         U R                  U   R                  5         U R                  USS9  g)a  
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   r   N)rR   grid_forgetr   rX   )r,   r   s     r-   hide_columnMultiListbox.hide_column  sH     <<LL#//1y!--/!!)A!6r1   c                     U R                   U   nU R                  (       a   U R                  U   R                  USSSSS9  U R                  U   R                  USSSSS9  U R	                  XS9  g)zx
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   r   r   r   N)rS   rR   r[   rQ   rX   )r,   r   r   s      r-   show_columnMultiListbox.show_column  s~    
 %%i0<<LL#(( aQQ )  		"''!F 	( 	
 	!!)!;r1   c                 d    U R                    Vs/ s H  oDR                  XU5      PM     sn$ s  snf )a  
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   r^   )r,   sequencefuncaddri   s        r-   bind_to_labelsMultiListbox.bind_to_labels  s.     >B=O=OP=OE

83/=OPPPs   -c                 N    U R                    H  nUR                  XU5        M     g)a  
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)r   r^   )r,   r   r   r   r   s        r-   bind_to_listboxesMultiListbox.bind_to_listboxes  s      ~~GLL- &r1   c                 L    U R                  XU5      U R                  XU5      -   $ )a+  
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       r-   bind_to_columnsMultiListbox.bind_to_columns  s0     ""837$:P:PC;
 
 	
r1   c                 @    U R                   S   R                  " U0 UD6$ Nr   )rQ   r   r,   argskwargss      r-   r   MultiListbox.curselection  s!    q!..???r1   c                 @    U R                   S   R                  " U0 UD6$ r   )rQ   selection_includesr   s      r-   r   MultiListbox.selection_includes  s!    q!44dEfEEr1   c                 @    U R                   S   R                  " U0 UD6$ r   )rQ   itemcgetr   s      r-   r   MultiListbox.itemcget  s!    q!**D;F;;r1   c                 @    U R                   S   R                  " U0 UD6$ r   )rQ   r   r   s      r-   r   MultiListbox.size  s!    q!&&777r1   c                 @    U R                   S   R                  " U0 UD6$ r   )rQ   r   r   s      r-   r   MultiListbox.index  s!    q!''888r1   c                 @    U R                   S   R                  " U0 UD6$ r   )rQ   r   r   s      r-   r   MultiListbox.nearest  s!    q!))4:6::r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r   r,   r   r   rk   s       r-   r   MultiListbox.activate  s!    //BKK(( "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   deleter  s       r-   r  MultiListbox.delete  s!    //BIIt&v& "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r7   r  s       r-   r7   MultiListbox.scan_mark  s!    //BLL$)&) "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r;   r  s       r-   r;   MultiListbox.scan_dragto  s!    //BNND+F+ "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r   r  s       r-   r   MultiListbox.see  s!    //BFFD#F# "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   selection_anchorr  s       r-   r  MultiListbox.selection_anchor  s#    //B00 "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r   r  s       r-   r   MultiListbox.selection_clear  s#    //B// "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   r   r  s       r-   r   MultiListbox.selection_set  s#    //Bd-f- "r1   c                 P    U R                    H  nUR                  " U0 UD6nM     W$ r4   )rQ   yview)r,   r   r   rk   vs        r-   r  MultiListbox.yview  s(    //B$)&)A "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   )rQ   yview_movetor  s       r-   r  MultiListbox.yview_moveto$  !    //BOOT,V, "r1   c                 N    U R                    H  nUR                  " U0 UD6  M     g r4   r   r  s       r-   r   MultiListbox.yview_scroll(  r  r1   )rP   rS   rR   rQ   rs   NNTr4   NNN);__name__
__module____qualname____firstlineno____doc__r   rU   rY   r]   rT   r`   rw   ry   propertyr   r   r   r_   r)   rG   rB   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r7   r;   r   r  r   r   r  r  r   
itemconfig	rowconfigcolumnconfigselect_anchorselect_clearselect_includes
select_set__static_attributes__r>   r1   r-   r	   r	      s    6TaPL !L N 8< X"|BH( " " 
# 
# & &
G H  2*# +- 3 .0 ).6$"!B7<&
Q.
&@F<89;)'*,$10.
-- JI"L$M"L(OJr1   r	   c                   >   \ rS rSrSrSSSSS0 4S jrS rS rS rS(S	 jr	0 4S
 jr
0 4S jrS)S jrS(S jrS(S jrS(S jr\
r\r\rS rS rS rS rS rS rS rS rS r\S 5       rS rS rS r S r!S*S jr"S+S jr#S  r$S,S! jr%S" r&S-S$ jr'S.S% jr(S#r) S& r*S'r+g)/TableiE  ax  
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 list 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'  # doctest: +SKIP

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'])  # doctest: +SKIP
    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.
NTc	                 x   [        U5      U l        Xpl        [        U5      U l        [        U5       V
Vs0 s H  u  pX_M	     snn
U l        Uc  / U l        O)U VVs/ s H  o Vs/ s H  oPM     snPM     snnU l        U R                   H  nU R                  U5        M     [        U R                  X$U40 U	D6U l
        U R                  R                  SSSS9  U(       ae  [        U R                  SU R                  R                  S9nUR                  U R                  R                  S   S	'   UR                  S
SS9  Xl        SU l        U(       aD  [        U R                  R$                  5       H!  u  pUR'                  SU R(                  5        M#     U R+                  5         gs  snn
f s  snf s  snnf )a  
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 initialize 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.
NleftTboth)sideexpandfillvertical)orientcommandr   yscrollcommandrightr9   )r5  r7  r%   )rM   _num_columns	_reprfuncr   _framerW   _column_name_to_index_rows	_checkrowr	   _mlbpackr   r  setr   
_scrollbar_sortkeyr   r^   _sort_fill_table)r,   rb   r   r   rd   	scrollbarclick_to_sortreprfuncre   rf   rh   cr!   r  sbrj   s                   r-   rT   Table.__init__l  sl   V  -!Fm9B<9P%Q9Pvad9P%Q" <DJ6:;dsc*c1c*d;DJ::CNN3  !lCVSUV			F4f= 4;;z499??SB79vvDII"#34 GGsG+ O !$))"9"9:|TZZ0 ; 	= &R +;s   F+	F6%F10F61F6c                 <    U R                   R                  " U0 UD6  g)zjPosition this table's main frame widget in its parent
widget.  See ``Tkinter.Frame.pack()`` for more info.N)r?  rD  r   s      r-   rD  
Table.pack       	$)&)r1   c                 <    U R                   R                  " U0 UD6  g)zjPosition this table's main frame widget in its parent
widget.  See ``Tkinter.Frame.grid()`` for more info.N)r?  r[   r   s      r-   r[   
Table.grid  rR  r1   c                 8    U R                   R                  5         g)z-Direct (keyboard) input foxus to this widget.N)rC  r   r   s    r-   r   Table.focus  s    		r1   c                 <    U R                   R                  XU5        g)zcAdd a binding to this table's main frame that will call
``func`` in response to the event sequence.N)rC  r^   r   s       r-   r^   
Table.bind  s     			xs+r1   c                 >    U R                   R                  " X40 UD6  g)z%:see: ``MultiListbox.rowconfigure()``N)rC  r   )r,   r   re   rf   s       r-   r   Table.rowconfigure  s    		y44r1   c                 `    U R                  U5      nU R                  R                  " X40 UD6  g)z(:see: ``MultiListbox.columnconfigure()``N)r\   rC  r   )r,   r   re   rf   s       r-   r   Table.columnconfigure  s)    %%i0			!!)7B7r1   c                 `    U R                  U5      nU R                  R                  " XU40 UD6$ )z&:see: ``MultiListbox.itemconfigure()``)r\   rC  r   )r,   r   r   re   rf   s        r-   r   Table.itemconfigure  s.    %%i0	yy&&ySGBGGr1   c                 :    U R                   R                  XU5      $ )z':see: ``MultiListbox.bind_to_labels()``)rC  r   r   s       r-   r   Table.bind_to_labels  s    yy''<<r1   c                 :    U R                   R                  XU5      $ )z*:see: ``MultiListbox.bind_to_listboxes()``)rC  r   r   s       r-   r   Table.bind_to_listboxes  s    yy**83??r1   c                 :    U R                   R                  XU5      $ )z(:see: ``MultiListbox.bind_to_columns()``)rC  r   r   s       r-   r   Table.bind_to_columns  s    yy((==r1   c           	      Z   U R                  U5        U R                  R                  X5        U R                  b/  [	        U5       VVs/ s H  u  p4U R                  XU5      PM     nnnU R
                  R                  X5        U R                  (       a  U R                  5         ggs  snnf )a  
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)rB  rA  r   r>  rW   rC  _DEBUG_check_table_vs_mlb)r,   r   rowvaluejr  s        r-   r   Table.insert  s     	x 

).>>%>G>Q>QFQyQ/>Q   			-;;$$& 	s   B'c                 |    U H  nU R                  U5        M     U R                  (       a  U R                  5         gg)z
Add new rows at the end of the table.

:param rowvalues: A list of row values used to initialize the
    table.  Each row value should be a tuple of cell values,
    one for each column in the row.
N)rZ   rf  rg  )r,   	rowvaluesrh  s      r-   extendTable.extend	  s2     "HKK! ";;$$& r1   c                     U R                  [        U R                  5      U5        U R                  (       a  U R	                  5         gg)zz
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   rM   rA  rf  rg  r,   rh  s     r-   rZ   Table.append  s2     	C

OX.;;$$& r1   c                     / U l         U R                  R                  SS5        U R                  (       a  U R	                  5         gg)z 
Delete all rows in this table.
r   r   N)rA  rC  r  rf  rg  r   s    r-   clearTable.clear!  s7     
		E";;$$& r1   c                    [        U[        5      (       a  [        S5      e[        U[        5      (       a6  [	        U5      S:X  a'  U R
                  US      U R                  US   5         $ [        U R
                  U   5      $ )aS  
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.
Slicing not supported   r   r   )rI   slicerN   rO   rM   rA  r\   )r,   r   s     r-   __getitem__Table.__getitem__*  so     eU##455u%%#e*/::eAh'(9(9%((CDDE*++r1   c           	         [        U[        5      (       a  [        S5      e[        U[        5      (       a  [	        U5      S:X  a  US   U R                  US   5      pCU R                  U/5      nX R                  U   U'   U R                  b  U R                  X4U5      nU R                  R                  U   R                  X25        U R                  R                  U   R                  US-   5        U R                  U5        gU R                  U/5      nU R                  U5        [        U5      U R                  U'   U R                  b/  [!        U5       VVs/ s H  u  pFU R                  XU5      PM     nnnU R                  R                  X5        U R                  R                  US-   5        U R                  U5        gs  snnf )a  
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``.
rv  rw  r   r   N)rI   rx  rN   rO   rM   r\   _save_config_inforA  r>  rC  r   r   r  _restore_config_inforB  rK   rW   )r,   r   r   rh   ri  config_cookier  s          r-   r   Table.__setitem__:  su    eU##455 u%%#e*/8T..uQx8q 22A37M"JJqM!~~)nnQ3/II"))!1II"))!a%0%%m4 !22E7;MNN3 $S	DJJu~~)AJ3Pvt~~e2PIIU(IIUQY'%%m4 Qs   Gc                 6   [        U[        5      (       a  [        S5      e[        U[        5      (       a  [	        U5      S:X  a  [        S5      eU R
                  U	 U R                  R                  U5        U R                  (       a  U R                  5         gg)z1
Delete the ``row_index``th row from this table.
rv  rw  zCannot delete a single cell!N)
rI   rx  rN   rO   rM   rA  rC  r  rf  rg  )r,   r   s     r-   __delitem__Table.__delitem__a  sw     i''455i''C	Na,?;<<JJy!		#;;$$& r1   c                 ,    [        U R                  5      $ )z,
:return: the number of rows in this table.
)rM   rA  r   s    r-   __len__Table.__len__n  s     4::r1   c                 ~    [        U5      U R                  :w  a$  [        SU[        U5      U R                  4-  5      eg)zs
Helper function: check that a given row value has the correct
number of elements; and if not, raise an exception.
z"Row %r has %d columns; expected %dN)rM   r=  rN   rp  s     r-   rB  Table._checkrowt  sD    
 x=D---4S]D,=,=>?  .r1   c                 .    U R                   R                  $ )z1A list of the names of the columns in this table.)rC  r   r   s    r-   r   Table.column_names  s     yy%%%r1   c                     [        U[        5      (       a  SUs=::  a  U R                  :  a   U$   U R                  U   $ )z
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.
r   )rI   rJ   r=  r@  )r,   rh   s     r-   r\   Table.column_index  s@     a!q"<4+<+<"<H #= --a00r1   c                 X    U R                   R                  U R                  U5      5        g)z$:see: ``MultiListbox.hide_column()``N)rC  r   r\   r,   r\   s     r-   r   Table.hide_column      		d//=>r1   c                 X    U R                   R                  U R                  U5      5        g)z$:see: ``MultiListbox.show_column()``N)rC  r   r\   r  s     r-   r   Table.show_column  r  r1   c                 b    U R                   R                  5       nU(       a  [        US   5      $ g)z
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()]``.
r   N)rC  r   rJ   )r,   sels     r-   selected_rowTable.selected_row  s*     ii$$&s1v;r1   c                 <    U R                   R                  XU5        g)z:see: ``MultiListbox.select()``N)rC  rB   r   s       r-   rB   Table.select  s    		s+r1   c                    US;  a  [        S5      eU R                  U5      nU R                  SS9nUS:X  a*  XR                  :X  a  U R                  R                  5         O7U R                  R                  [        R                  " U5      US:H  S9  Xl        U R                  5         U R                  USSS9  U R                  (       a  U R                  5         g	g	)
ab  
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.
)	ascending
descendingtogglezBsort_by(): order should be "ascending", "descending", or "toggle".T)index_by_idr  r  )r   reverse)r  r   N)rN   r\   r|  rG  rA  r  sortoperator
itemgetterrI  r}  rf  rg  )r,   r\   orderr~  s       r-   sort_byTable.sort_by  s    & ==W  ((6..4.@ H!>JJ JJOO''5@U   )M 	!!-Tt!L;;$$& r1   c                     UR                   R                  nU R                  R                  U5      (       a  gU R	                  U5        g)zDEvent handler for clicking on a column label -- sort by
that column.continue)rr   r\   rC  r`   r  )r,   rz   r\   s      r-   rH  Table._sort  s>     ||00 99##E** LL&r1   c           
      4   U R                   R                  SS5        [        U R                  5       H]  u  p#U R                  b/  [        U5       VVs/ s H  u  pEU R	                  X$U5      PM     nnnU R                   R                  SU5        M_     gs  snnf )aL  
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.
r   r   N)rC  r  rW   rA  r>  r   )r,   save_configrh   r!   ri  r  s         r-   rI  Table._fill_table  ss     			E"

+FA~~)=Fs^L^6At~~aA.^LIIUC( ,Ls   Bc           	      l    S Vs0 s H"  nX0R                   R                  XU5      S   _M$     sn$ s  snf )N)r   r   r   r   r'   )rC  r(  )r,   rrM  ks       r-   _get_itemconfigTable._get_itemconfig   sF    
 yy##A!,R00
 	
 
s   )1Fc                 H   Uc'  [        [        [        U R                  5      5      5      nU R	                  5       nU(       a  Ub  [        U R                  U   5      nU(       a`  U VVs0 s HN  n[        U R                  U   5      [        U R                  5       Vs/ s H  oPR                  XE5      PM     sn_MP     nnnX64$ U VVs0 s H8  nU[        U R                  5       Vs/ s H  oPR                  XE5      PM     sn_M:     nnnX64$ s  snf s  snnf s  snf s  snnf )a  
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.
)rK   rL   rM   rA  r  idr=  r  )r,   row_indicesr  	selectionr  rM  configs          r-   r|  Table._save_config_info  s,     uS_56K %%'	904::i01I 
 %	 %A 4::a=!8=d>O>O8P$8P1((.8P$  %	      %$A d>O>O8PQ8P1((.8PQQ$  
   $ Rs0   )4DD7D	D'DDDDc           
      Z   Uu  pEUc  U R                   R                  SS5        U(       a  [        U R                  5       H  u  pg[	        U5      U;   aG  [        U R                  5       H.  nU R                   R                  XhU[	        U5         U   5        M0     [	        U5      U:X  d  Ml  U R                   R                  XcS9  M     gUb  U R                   R                  XCS9  U H@  n[        U R                  5       H$  nU R                   R                  XhXV   U   5        M&     MB     g)za
Restore selection & color configuration information that was
saved using ``_save_config_info``.
Nr   r   )r   )	rC  r   rW   rA  r  rL   r=  r   rB   )	r,   cookier  r   r  r  r  r!   rM  s	            r-   r}  Table._restore_config_info3  s    
 #	 II%%a/ #DJJ/c7f$"4#4#45		//fRWoa6HI 6c7i'II$$Q$0 0 $		   4t001AII++A&)A,? 2 r1   c                    U R                   R                   H"  n[        U 5      UR                  5       :X  a  M"   e   U  H  n[        U5      U R                  :X  a  M   e   U R                  [        U R                   R
                  5      :X  d   e[        U 5       H\  u  p2[        U5       HH  u  pEU R                  b  U R                  X4U5      nU R                   R                  U5      U   U:X  a  MH   e   M^     g)z
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)	rC  r   rM   r   r=  r   rW   r>  r   )r,   r   r!   rh   ri  cells         r-   rg  Table._check_table_vs_mlbU  s     99&&Ct9
*** 'Cs8t00000   C		(>(>$????oFA$S>>>->>!5Dyy}}Q'*d222 * &r1   )r@  r?  rC  r=  r>  rA  rF  rG  r!  r4   r   )r  )T)NF)FF),r"  r#  r$  r%  r&  rT   rD  r[   r   r^   r   r   r   r   r   r   r)  r*  r(  r   rm  rZ   rs  ry  r   r  r  rB  r'  r   r\   r   r   r  rB   r  rH  rI  r  r|  r}  rf  rg  r/  r>   r1   r-   r1  r1  E  s    $T Mh*
*
,
 +- 5 .0 8
H
=@> I"LJ'('	'', %5N'	 & &1??
,''R&)	
&!P@< F#3r1   r1  c            	        ^
 [        5       m
T
R                  SU
4S j5        [        T
SR                  5       / SQS S9n U R	                  SSS	9  S
SKJnJn  [        [        UR                  5       S S 5      5       H  u  p4US
   S:w  a  M  UR                  5       nUR                  U5       Hh  n UR                  5       S
   R                  5       n UR                  5       S
   R                  5       nU R                  X5R                  5       Xg/5        Mj     M     U R!                  SSS9  U R!                  SSS9  U R!                  SSS9  U R!                  SSS9  [#        [%        U 5      5       H)  nS H   n	XU	4   S:X  d  M  U R'                  XSSS9  M"     M+     T
R)                  5         g !   Sn N= f!   Sn N= f)Nz<Control-q>c                 $   > TR                  5       $ r4   )destroy)r+   roots    r-   r.   demo.<locals>.<lambda>q  s    t||~r1   zWord Synset Hypernym Hyponym)r   r   r   r   c                     SU-  $ )Nz  %sr>   )rh   ri  ss      r-   r.   r  w  s    &1*r1   )rd   rL  Tr4  )r6  r7  r   )brownwordneti  Nz*none*Wordz#afa)r   Synsetz#efeHypernymz#feeHyponymz#ffe)r  r  z#666)r   r   )r   r^   r1  splitrD  nltk.corpusr  r  sortedrE  tagged_wordslowersynsets	hypernyms
definitionrZ   r*  rL   rM   r(  mainloop)tabler  r  wordpossynset	hyper_defhypo_defr!   r    r  s             @r-   demor  o  s   4DIIm56&,,.#,	E 
JJdJ(*C 2 2 4Tc :;<	q6S=zz|ood+F%",,.q1<<>	$!++-a0;;= LL$ 1 1 3YIJ ,	 = 
v&1	xF3	zf5	yV4SZ -F&[!X-  FV !  . ! 	MMO%%$	$#s   1!F/!F8/F58F>__main__)r&  r  tkinterr   r   r   r   r   r	   r1  r  r"  r>   r1   r-   <module>r     sK     8 8b5 bba3 a3T'T zF r1   