JL ivdZddlZddlmZmZmZmZmZGddeZGddZ dZ e d k(re yy) zC Tkinter widgets for displaying multi-column listboxes and tables. N)FrameLabelListbox ScrollbarTkc eZdZdZedddZeddddd Zedd d d dd d ZdifdZdZ dZ dZ e dZ e dZe dZdZdZdZd9dZifdZdZifdZifdZd:dZd Zd:d!Zd"Zd#Zd$Zd;d%Zd;d&Zd;d'Z d(Z!d)Z"d*Z#d+Z$d,Z%d-Z&d.Z'd/Z(d0Z)d1Z*d2Z+d3Z,d4Z-d5Z.d6Z/d7Z0d8Z1eZ2eZ3eZ4e,Z5e-Z6e"Z7e.Z8y)< MultiListboxa 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 takefocushighlightthicknessraisedzhelvetica -16 boldz#444white) borderwidthrelieffontr foregroundrFnone)rselectborderwidthr exportselectionselectbackground activestyler Nc t|trtt|}d}nd}t |dk(r t dt |_g_g_ |dgt |z}n"t |t |k7r t d|_ tj|fijjddtjD]\}}j!||||rPt#fd |ij$} jj'| | j)|dd dd || _t-fij.} jj'| | j)|dd dd || _| j1d j2| j1d j2| j1dfd| j1dfd| j1dfd| j1dfd| j1dfd| j1dd| j1d j4j1d j4j1dfdj1dfdj1dfdj1d fd!j6|fi|y)"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 FTrzExpected at least one columnNr z*Expected one column_weight for each columnweighttextnewscolumnrowstickypadxpady z z c&jdS)N_scrolleselfs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/draw/table.pyz'MultiListbox.__init__..DLL,<z c&jdS)Nr r'r)s r,r-z'MultiListbox.__init__..r.r/z c:j|jSN)r(deltar)s r,r-z'MultiListbox.__init__..sdll177.Cr/z cPj|j|jSr2) scan_markxyr)s r,r-z'MultiListbox.__init__..sDNN133,Dr/z cPj|j|jSr2) scan_dragtor6r7r)s r,r-z'MultiListbox.__init__..sT-=-=acc133-Gr/z cy)Nbreak)r*s r,r-z'MultiListbox.__init__..sr/zc(jdS)Nr&r3selectr)s r,r-z'MultiListbox.__init__..sDKKbK$9r/zc(jdS)Nr r>r?r)s r,r-z'MultiListbox.__init__..sdkkk&:r/zcFjj SNr>r@ _pagesizer)s r,r-z'MultiListbox.__init__..st{{$..:J9J{'Kr/zcDjjSrCrDr)s r,r-z'MultiListbox.__init__..sdkk8Hk&Ir/) isinstanceintlistrangelen ValueErrortuple _column_names _listboxes_labels_column_weightsr__init__ FRAME_CONFIGgrid_rowconfigure enumerategrid_columnconfigurer LABEL_CONFIGappendgrid column_indexrLISTBOX_CONFIGbind_select_resize_column configure) r+mastercolumnscolumn_weightscnfkwinclude_labelsilabelllbs ` r,rRzMultiListbox.__init__>s* gs #5>*G"N!N w<1 ;< <#7^   !S3w</N  CL 0IJ J- tV9t'8'89 q+!$"4"45 7HAu  % %aq0A % B$@U@d.?.?@ ##A&aQvAAF!"5!4!45B OO " "2 & GG1!FG CBO GGL$,, / GGM4<< 0 GGL"< = GGL"< = GGN$C D GGL"D E GGM#G H GGL"3 4 GGL$"5"5 6= 7D , 3 34 &9: (:; )KL (IJ s!b!r/c |jjdryd|_|j|ur`t|jD]G\}}t |j |j|jzz dksA||_In|j |jjdz kDr|jj|_nF|j dkr7|jjdk7r|jjdz |_|jZ|jjd|j|jjd |jz|jy y) 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. zFN rr T) widgetr\_resize_column_indexrUrOabsr6winfo_x winfo_widthrZ_resize_column_motion_cbnum_resize_column_buttonrelease_cb)r+eventrfris r,r^zMultiListbox._resize_columns7 <<  . /%)! <<4 "4??3 22uww"**,1A"ABCbH01D- 2WW 002Q6 7(- (A(AD % WWq[U\\66!;(- (A(AA(ED %  $ $ 0 LL  j$*G*G H LL  $uyy0$2V2V r/c:|j|j}|j|dz }|j|jj z}|j |jz}t dt|d||z |zz|d<y)Nwidth)rOrprsr6rorrmaxrH)r+rwri charwidthx1x2s r,rtz%MultiListbox._resize_column_motion_cbs __T66 7NN$r'{2 WWu||++- - ZZ\BNN, ,!SGRI/E!EFG7 r/c|jjd|jz|jjdy)Nrnrm)rounbindru)r+rws r,rvz,MultiListbox._resize_column_buttonrelease_cbs0 0599<= J'r/c|jS)zh A tuple containing the names of the columns used by this multi-column listbox. )rNr+s r, column_nameszMultiListbox.column_namess !!!r/c,t|jS)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. )rMrPrs r, column_labelszMultiListbox.column_labelssT\\""r/c,t|jS)aY 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. )rMrOrs r, listboxeszMultiListbox.listboxessT__%%r/c|jj|j}|jdd|j ||j ||j y)Nrend)ronearestr7selection_clear selection_setactivatefocus)r+r*rfs r,r]zMultiListbox._selectsM HH  QSS ! Q& 1 a r/cJ|jD]}|j|dy)Nunitr;rO yview_scroll)r+r3ris r,r(zMultiListbox._scrolls&// +B OOE6 * +r/clt|jdt|jdz S)z2:return: The number of rows that makes up one pagez @0,1000000z@0,0)rHindexrs r,rEzMultiListbox._pagesizes)4::l+,s4::f3E/FFFr/cj| | td|At|jdk(rd|z}nt|jd|z}|j dd|Mt t |d|jdz }|j||r|j|yyy)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 bothrr&rr ) rLrK curselectionrHrminr{sizerseer+rr3rs r,r@zMultiListbox.selects  E$5CD D  4$$&'1,U D--/23e; Q&  E1 tyy{Q7E   u % r/c tt|jt|jz}t|jD]\}}|jds|jdr(|jD]}|j |dd|iP|jds|jdr(|j D]}|j |dd|itj |||iy)a 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_zlabel-Nlistbox_zlistbox-)dictrIitems startswithrPr_rOr)r+rcrdkeyvalrglistboxs r,r_zMultiListbox.configure*s4 $tBHHJ'778SYY[) 2HC~~h'3>>(+C!\\4EOOSWcN34 +s~~j/I#6G%%s12wn56sCj1 2r/c*|j||iy)z| Configure this widget. This is equivalent to ``self.configure({key,val``)}. See ``configure()``. N)r_)r+rrs r, __setitem__zMultiListbox.__setitem__?s Sz"r/c N|jD]}|j||fi|y)z Configure all table cells in the given row. Valid keyword arguments are: ``background``, ``bg``, ``foreground``, ``fg``, ``selectbackground``, ``selectforeground``. NrO itemconfigure)r+ row_indexrcrdris r, rowconfigurezMultiListbox.rowconfigureFs. // 3B B  Y 2r 2 3r/c p|j|}tt|jt|jz}t|jD]O\}}|dvr3t |j D]}|j |||i=|j||iQy)z Configure all table cells in the given column. Valid keyword arguments are: ``background``, ``bg``, ``foreground``, ``fg``, ``selectbackground``, ``selectforeground``. )r bgrfgrselectforegroundN)rOrrIrrJrrr_)r+ col_indexrcrdrirrrfs r,columnconfigurezMultiListbox.columnconfigureOs __Y '4 $tBHHJ'778SYY[) )HCrwwy)4A$$Qc 34 c3Z( )r/c H|j|}|j||fi|S)z Configure the table cell at the given row and column. Valid keyword arguments are: ``background``, ``bg``, ``foreground``, ``fg``, ``selectbackground``, ``selectforeground``. r)r+rrrcrdris r,rzMultiListbox.itemconfigurefs, __Y 'r 35"55r/c|D].}t|t|jk7s%tdt|jt t|D]\}}|j |g|y)a0 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)rKrNrLziprOrIinsert)r+rrowseltrieltss r,rzMultiListbox.insertssx C3x3t1122 8  DOOT#t*-=> $HB BIIe #d # $r/c|jDcgc]}|j||}}|rt|Dcgc] }t|c}St|Scc}wcc}w)a 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. )rOgetrrM)r+firstlastrivaluesr s r,rzMultiListbox.getsU15@""&&%@@ *-v,73E#J7 7= A7s AAc|jd|\}}}}|j|j|\}}}} t|t|zt|t|zt|t| fS)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_bboxrObboxrH) r+r coldxdy_r6r7whs r,rzMultiListbox.bboxsp ~~!C~8 B1__S)..s3 1a1vBQ#b'!13q63q6AAr/c|jr|j|j|j|j|j|dy)a1 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()`` rrN)rP grid_forgetrrV)r+rs r, hide_columnzMultiListbox.hide_columnsH << LL # / / 1 y!--/ !!)A!6r/c|j|}|jr#|j|j|dddd|j|j|dddd|j ||y)z Display a column that has been hidden using ``hide_column()``. It is safe to call this on a column that is not hidden. rrrr rN)rQrPrYrOrV)r+rrs r, show_columnzMultiListbox.show_columns %%i0 << LL # ( ( aQQ )   "''!F (  !!)F!;r/cb|jDcgc]}|j|||c}Scc}w)aK 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). )rr\)r+sequencefuncaddrgs r,bind_to_labelszMultiListbox.bind_to_labelss,>B=O=OPE 8T3/PPPs,cL|jD]}|j|||y)aM 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)rr\)r+rrrrs r,bind_to_listboxeszMultiListbox.bind_to_listboxess'~~ .G LL4 - .r/cP|j||||j|||zS)ac 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). )rrr+rrrs r,bind_to_columnszMultiListbox.bind_to_columnss4""8T37$:P:P dC;   r/c@|jdj|i|SNr)rOrr+argskwargss r,rzMultiListbox.curselections#.tq!..???r/c@|jdj|i|Sr)rOselection_includesrs r,rzMultiListbox.selection_includess#4tq!44dEfEEr/c@|jdj|i|Sr)rOitemcgetrs r,rzMultiListbox.itemcgets#*tq!**D;F;;r/c@|jdj|i|Sr)rOrrs r,rzMultiListbox.sizes#&tq!&&777r/c@|jdj|i|Sr)rOrrs r,rzMultiListbox.indexs#'tq!''888r/c@|jdj|i|Sr)rOrrs r,rzMultiListbox.nearests#)tq!))4:6::r/cJ|jD]}|j|i|yr2)rOrr+rrris r,rzMultiListbox.activates(// )B BKK ( ( )r/cJ|jD]}|j|i|yr2)rOdeleters r,rzMultiListbox.deletes(// 'B BIIt &v & 'r/cJ|jD]}|j|i|yr2)rOr5rs r,r5zMultiListbox.scan_marks(// *B BLL$ )& ) *r/cJ|jD]}|j|i|yr2)rOr9rs r,r9zMultiListbox.scan_dragto s(// ,B BNND +F + ,r/cJ|jD]}|j|i|yr2)rOrrs r,rzMultiListbox.sees(// $B BFFD #F # $r/cJ|jD]}|j|i|yr2)rOselection_anchorrs r,rzMultiListbox.selection_anchors*// 1B B   0 0 1r/cJ|jD]}|j|i|yr2)rOrrs r,rzMultiListbox.selection_clears*// 0B B   / / 0r/cJ|jD]}|j|i|yr2)rOrrs r,rzMultiListbox.selection_sets*// .B B  d -f - .r/cL|jD]}|j|i|}Sr2)rOyview)r+rrrivs r,rzMultiListbox.yviews/// *B$)&)A *r/cJ|jD]}|j|i|yr2)rO yview_movetors r,rzMultiListbox.yview_moveto$(// -B BOOT ,V , -r/cJ|jD]}|j|i|yr2rrs r,rzMultiListbox.yview_scroll(rr/NNTr2NNN)9__name__ __module__ __qualname____doc__rrSrWr[rRr^rtrvpropertyrrrr]r(rEr@r_rrrrrrrrrrrrrrrrrrrrr5r9rrrrrrr itemconfig rowconfig columnconfig select_anchor select_clearselect_includes select_setr<r/r,r r s6TaPL ! LN8<X"|BH("" # #&& G H2*#+-3.0).6$" !B 7 <& Q .  &@F<89;)'*,$10. --JI"L$M"L(OJr/r ceZdZdZdddddifdZdZdZdZd&dZifd Z ifd Z d'd Z d&d Z d&d Z d&dZe Ze Ze ZdZdZdZdZdZdZdZdZdZedZdZdZdZdZ d(dZ!d)dZ"dZ#d*d Z$d!Z%d+d#Z&d,d$Z'd"Z( d%Z)y)-Tablea 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  jt||_||_t||_t |D cic]\} } | |  c} } |_|g|_n%|D cgc]} | D cgc]} | c} c} } |_|jD]} |j| t|j|||fi| |_ |jjddd|rlt|jd|jj}|j|jjdd <|jd d ||_d|_|rCt |jj$D]!\} }|j'd |j(#|j+ycc} } wcc} wcc} } w)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. NleftTboth)sideexpandfillvertical)orientcommandryscrollcommandrightr7)rr r$)rK _num_columns _reprfuncr_framerU_column_name_to_index_rows _checkrowr _mlbpackrrsetr _scrollbar_sortkeyrr\_sort _fill_table)r+r`rrrb scrollbar click_to_sortreprfuncrcrdrfcr rsbrhs r,rRzTable.__init__lstV -!Fm 9B<9P%Qv1ad%Q" <DJ6:;sc*1*;DJ:: C NN3  !lNCVSUV  F4f= 4;;z499??SB79vvDII   "#3 4 GGsG + DO !$))"9"9: 11|TZZ0 1 =&R +;s F$ F/$ F* -F/*F/c<|jj|i|y)zrPosition this table's main frame widget in its parent widget. See ``Tkinter.Frame.pack()`` for more info.N)rrrs r,rz Table.pack  $)&)r/c<|jj|i|y)zrPosition this table's main frame widget in its parent widget. See ``Tkinter.Frame.grid()`` for more info.N)rrYrs r,rYz Table.gridr#r/c8|jjy)z-Direct (keyboard) input foxus to this widget.N)rrrs r,rz Table.focuss r/c>|jj|||y)zkAdd a binding to this table's main frame that will call ``func`` in response to the event sequence.N)rr\rs r,r\z Table.binds xs+r/c @|jj||fi|y)z%:see: ``MultiListbox.rowconfigure()``N)rr)r+rrcrds r,rzTable.rowconfigures y#44r/c b|j|}|jj||fi|y)z(:see: ``MultiListbox.columnconfigure()``N)rZrr)r+rrcrds r,rzTable.columnconfigures-%%i0 ! !!)S7B7r/c b|j|}|jj|||fi|S)z&:see: ``MultiListbox.itemconfigure()``)rZrr)r+rrrcrds r,rzTable.itemconfigures2%%i0 &tyy&&y)SGBGGr/c<|jj|||S)z':see: ``MultiListbox.bind_to_labels()``)rrrs r,rzTable.bind_to_labelssyy''$<> %>G>Q4:Qy!Q/H H- ;;  $ $ &  sB"cn|D]}|j||jr|jyy)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)rXr.r/)r+ rowvaluesr0s r,extendz Table.extend s7" "H KK ! " ;;  $ $ & r/c|jt|j||jr|j yy)z 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)rrKrr.r/r+r0s r,rXz Table.appends2 C OX. ;;  $ $ & r/cg|_|jjdd|jr|j yy)z0 Delete all rows in this table. rrN)rrrr.r/rs r,clearz Table.clear!s7  E" ;;  $ $ & r/ct|tr tdt|tr5t |dk(r'|j |d|j |dSt|j |S)a 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 supportedrr )rGslicerLrMrKrrZ)r+rs r, __getitem__zTable.__getitem__*si eU #45 5 u %#e*/::eAh'(9(9%((CD DE*+ +r/c t|tr tdt|trt |dk(r|d|j |d}}|j |g}||j||<|j|j|||}|jj|j|||jj|j|dz|j|y|j |g}|j|t||j|<|j.t!|Dcgc]\}}|j|||}}}|jj|||jj|dz|j|ycc}}w)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``. r:r;rr N)rGr<rLrMrKrZ_save_config_inforrrrrr_restore_config_inforrIrU)r+rrrfr1 config_cookiers r,rzTable.__setitem__:s| eU #45 5u %#e*/8T..uQx8qA 22A37M"DJJqM! ~~)nnQ3/ II   " ) )!S 1 II   " ) )!a% 0  % %m 4!22E7;M NN3  $S DJJu ~~)AJ3Pv1t~~eQ2PP II  UC ( II  UQY '  % %m 4QsF=ct|tr tdt|trt |dk(r td|j |=|j j||jr|jyy)zA Delete the ``row_index``th row from this table. r:r;zCannot delete a single cell!N) rGr<rLrMrKrrrr.r/)r+rs r, __delitem__zTable.__delitem__asq i '45 5 i 'C Na,?;< < JJy ! # ;;  $ $ & r/c,t|jS)z< :return: the number of rows in this table. )rKrrs r,__len__z Table.__len__ns4::r/c|t||jk7r$td|t||jfzy)z 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)rKrrLr6s r,rzTable._checkrowtsD x=D-- -4S]D,=,=>?  .r/c.|jjS)z1A list of the names of the columns in this table.)rrrs r,rzTable.column_namessyy%%%r/cpt|trd|cxkr|jkr|S|j|S)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)rGrHrr)r+rfs r,rZzTable.column_indexs= a !q"<4+<+<"<H#=--a0 0r/cX|jj|j|y)z$:see: ``MultiListbox.hide_column()``N)rrrZr+rZs r,rzTable.hide_column d// =>r/cX|jj|j|y)z$:see: ``MultiListbox.show_column()``N)rrrZrJs r,rzTable.show_columnrKr/cX|jj}|rt|dSy)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()]``. rN)rrrH)r+sels r, selected_rowzTable.selected_rows* ii$$& s1v; r/c>|jj|||y)z:see: ``MultiListbox.select()``N)rr@rs r,r@z Table.selects s+r/c|dvr td|j|}|jd}|dk(r*||jk(r|jj n:|jj tj||dk(||_|j|j|dd|jr|jy y ) a 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 descendingtogglezBsort_by(): order should be "ascending", "descending", or "toggle".T) index_by_idrTrS)rreverse)rUrN) rLrZr?rrrVsortoperator itemgetterrr@r.r/)r+rZorderrAs r,sort_byz Table.sort_bys& = =W ((6 ..4.@  H !> JJ   JJOO'' 5@U  )DM  !!-Tt!L ;;  $ $ & r/c|jj}|jj|ry|j |y)zLEvent handler for clicking on a column label -- sort by that column.continue)rorZrr^r[)r+rwrZs r,rz Table._sorts;||00  99 # #E * LL &r/c .|jjddt|jD][\}}|j.t|Dcgc]\}}|j |||}}}|jj d|]ycc}}w)a 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. rrN)rrrUrrr)r+ save_configrfr r1rs r,rzTable._fill_tables} E" + )FAs~~)=Fs^L6Aqt~~aA.LL II  UC ( )LsBc jdDcic]#}||jj|||d%c}Scc}w)N)rrr rr&)rr)r+rr ks r,_get_itemconfigzTable._get_itemconfigsA  tyy##Aq!,R0 0   s(0Fc $|'ttt|j}|j }|r|t |j|}|r]|Dcic]L}t |j|t|j Dcgc]}|j||c}N}}}||fS|Dcic]6}|t|j Dcgc]}|j||c}8}}}||fScc}wcc}}wcc}wcc}}w)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. )rIrJrKrrOidrrc)r+ row_indicesrU selectionrar configs r,r?zTable._save_config_info s%  uS_56K%%' 904::i01I  % 4::a=!8=d>O>O8P$34D((A.$F&  %d>O>O8PQ1D((A.QQF &  $Rs03DC<)D:D D0D <DD c N|\}}||jjdd|rt|jD]\}}t ||vrFt |j D].}|jj|||t ||0t ||k(sh|jj||y||jj|||D]?}t |j D]%}|jj|||||'Ay)zy Restore selection & color configuration information that was saved using ``_save_config_info``. Nrr)r) rrrUrrerJrrr@) r+cookierUrrgrhrar r s r,r@zTable._restore_config_info3s# # 6   II % %a / #DJJ/ 13c7f$"4#4#45J //1fRWoa6HIJc7i'II$$QC$0  1$    4 @t001@AII++Aq&)A,?@ @r/c|jjD] }t||jk(r J|D]}t||jk(rJ|jt|jj k(sJt |D]Z\}}t |D]G\}}|j|j|||}|jj|||k(rGJ\y)a 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) rrrKrrrrUrr)r+rr rfr1cells r,r/zTable._check_table_vs_mlbUs99&& +Ct9 * ** + 1Cs8t000 00 1  C (>(>$????o 3FAs$S> 34>>->>!Q5Dyy}}Q'*d222 3 3r/rr2r)rT)T)NF)FF)*rrrrrRrrYrr\rrrrrrrrrrr4rXr8r=rrCrErrrrZrrrOr@r[rrrcr?r@r.r/r<r/r,rrEs$T Mh* * , +-5.08 H =@>I"LJ '( ' '', %5N ' && 1?? ,''R & )  &!P@<F#3r/rc t jd fdt djgdd}|j dd d d lm}m}tt|jdd D]\}}|d d k7r|j}|j|D]i} |jd j} |jd j}|j||j||gk|j!dd|j!dd|j!dd|j!ddt#t%|D])}dD]"} ||| fdk(s|j'|| dd$+ j)y#d}YxYw#d}YxYw)Nz c$jSr2)destroy)r*roots r,r-zdemo..qs t||~r/zWord Synset Hypernym Hyponym)rr r r c d|zS)Nz %sr<)rfr1ss r,r-zdemo..ws &1*r/)rbrTr)r r r)brownwordnetiNz*none*Wordz#afa)r Synsetz#efeHypernymz#feeHyponymz#ffe)rxryz#666)rr)rr\rsplitr nltk.corpusrsrtsortedr tagged_wordslowersynsets hypernyms definitionrXrrJrKrmainloop) tablersrtwordpossynset hyper_defhypo_defr rrps @r,demoros 4DIIm56  &,,.#,  E  JJdJ(*C 2 2 4Tc :;< K c q6S= zz|ood+ KF %",,.q1<<>  $!++-a0;;= LL$ 1 1 3YI J K K v&1 xF3 zf5 yV4SZ - FS&[!X-  FV!   MMO% %$  $#s5!F<!G<GG __main__) rrXtkinterrrrrrr rrrr<r/r,rsK88b5bba3a3T'T zFr/