B � f�8�@s�dZddlmZmZmZmZddlmZmZm Z m Z m Z m Z ddlm Z ddlZddlZdZeejej�Zed�ZdZd Zd ZeeeeeeZd d �ZGd d�de�Zedkr�ddlmZedddd�ddlm Z e e�dS)z6 Dialog for building Tkinter accelerator key bindings �)�Toplevel�Listbox� StringVar�TclError)�Frame�Button� Checkbutton�Entry�Label� Scrollbar)� messageboxN) ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12z~!@#%^&*()_-+={}[]|;:,.<>/?)�Tab�SpaceZReturn)Z BackSpaceZDeleteZInsert)ZHomeZEndzPage Upz Page Downz Left Arrowz Right ArrowzUp Arrowz Down Arrowc$Cs|ddddddddd d d d d ddddddddddddddddddd d!d"d#d$�#}|�||�}d%|krr|tjkrr|��}d&|��S)'z3Translate from keycap symbol to the Tkinter keysym.ZspaceZ asciitildeZexclamZatZ numbersignZpercentZ asciicircumZ ampersandZasteriskZ parenleftZ parenrightZ underscoreZminusZplusZequalZ braceleftZ bracerightZ bracketleftZ bracketrightZbarZ semicolonZcolonZcommaZperiodZlessZgreaterZslashZquestionZPriorZNextZLeftZRightZUpZDownr )#r�~�!�@�#�%�^�&�*�(�)�_�-�+�=�{�}�[�]�|�;�:�,�.�<�>�/�?zPage Upz Page Downz Left Arrowz Right ArrowzUp Arrowz Down Arrowr �ShiftzKey-)�get�string�ascii_lowercase�upper)�key� modifiers�mapping�r2�7/opt/alt/python37/lib64/python3.7/idlelib/config_key.py� translate_keys   r4c@s�eZdZdZddd�dd�Zdd�Zdd �Zd d �Zd d �Zddd�Z dd�Z dd�Z dd�Z d dd�Z d!dd�Zdd�Zdd�ZdS)"� GetKeysDialogzKey Sequence ErrorF)�_htest�_utestc CsFt�||�|��|jdd�|jddd�|�|�|�|�|��|�d|j �||_ ||_ ||_ d|_ t|�|_|j�d�|��g|_x,|jD]"}t|�}|�d�|j�|�q�Wd|_|��|��|�d|��|��d|��d|��|�s |��d|��dnd f�|�sB|��|� �d S) a� parent - parent of this dialog title - string which is the title of the popup dialog action - string, the name of the virtual event these keys will be mapped to current_key_sequences - list, a list of all key sequence lists currently mapped to virtual events, for overlap checking _htest - bool, change box location when running htest _utest - bool, do not wait when running unittest �)� borderwidthF)�height�widthZWM_DELETE_WINDOW�z+%d+%d��N)!r�__init__ZwithdrawZ configureZ resizable�titleZ transientZgrab_setZprotocol�cancel�parent�action�current_key_sequences�resultr� key_string�set�set_modifiers_for_platform� modifier_varsr0�append�advanced�create_widgetsZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) �selfrBr@rCrDr6r7�modifier�variabler2r2r3r?0s@        *zGetKeysDialog.__init__cOstj||�dS)N)r � showerror)rM�args�kwargsr2r2r3rP`szGetKeysDialog.showerrorc Cs0t|ddd�|_}|jdddd�t|�}|jdd d �t|d d |jd �|_|jjddddd�t|dd |jd �|_|jjddddd�t|dd�|_ |j jdddddd�t |j d|j �d�d�}|jdd�t |j d|j ddd�}|jddd d�t|�|_ |j jddddd �i|_d}xft|j|j�D]T\}}|j�||�}t|j |j|||d!d"�} | jd|ddd#�| |j|<|d7}�q0Wt |j dd$d%�} | jddd&ddd'�t|j d(d)d*d+�|_|jjdBt��|j�d-|j�|jjdd&d&d.d/�t|j d0|jjd1�} |jj| jd2�| jddd&d.d/�t|j d3|j d4�|_!|j!jddd&d5�t|d6d�|_"|j"jdddddd�t |j"dd7|j �d8�d9d%�} | jdd�t#|j"|j d:�|_$|j$jd d;�t|�|_%|j%jddddd �t |j%ddd?�|_'|j'jddd@dddA�|�&�dS)CNr=Zsunken)r9�relief�topTZboth)�side�expand�fillZbottom�x)rUrWZOK�)�textr;�commandrr8)�row�column�padx�padyZCancel�Z keyseq_basic)�nameZnsew)r\r]�stickyr^r_zNew keys for 'z' :)rZ�w)�anchor�leftZgroove)�justify� textvariablerSr9)ZipadxZipadyrW)r\r]rbr^r<)r[rZrOZonvalueZoffvalue)r\r]r^rbz�Select the desired modifier keys above, and the final key from the list on the right. Use upper case Symbols when using the Shift modifier. (Letters will be converted automatically.))rfrZ�)r\r]� columnspanr^rb�� Zsingle)r;r:Z selectmode�endz�ns)r\r]ZrowspanrbZvertical)Zorientr[)Zyscrollcommandz Clear Keys)rZr[)r\r]riZkeyseq_advancedzEnter new binding(s) for 'z' : z2(These bindings will not be checked for validity!))rg)rWa�Key bindings are specified using Tkinter keysyms as in these samples: , , , , , . Upper case is used when the Shift modifier is present! 'Emacs style' multi-keystroke bindings are specified as follows: , where the first key is the 'do-nothing' keybinding. Multiple separate bindings for one action should be separated by a space, eg., .)r\r]rbz<< Basic Key Binding Entry)r[rZZew)r\r]Zstickr^r_)rl)(r�frameZpackr�okZ button_okZgridrAZ button_cancel�frame_keyseq_basicr rCrF�frame_controls_basicZmodifier_checkbuttons�zipr0rI�modifier_labelr+r�build_key_stringr�list_keys_final�insert�AVAILABLE_KEYS�bind�final_key_selectedr �yview�configrG� clear_key_seqZ button_clear�frame_keyseq_advancedr � advanced_keys�frame_help_advanced� toggle_level� button_level)rMrnZ frame_buttonsZ basic_titleZ basic_keysr]rNrOZlabelZcheckZ help_basicZscroll_keys_finalZadvanced_titleZ help_advancedr2r2r3rLds�                 zGetKeysDialog.create_widgetscCs4tjdkrddddg|_n dddg|_ddi|_dS) aVDetermine list of names of key modifiers for this platform. The names are used to build Tk bindings -- it doesn't matter if the keyboard has these keys; it matters if Tk understands them. The order is also important: key binding equality depends on it, so config-keys.def must use the same ordering. �darwinr*ZControlZOptionZCommandZAltZCtrlN)�sys�platformr0rs)rMr2r2r3rH�s  z(GetKeysDialog.set_modifiers_for_platformcCs�|j�d��d�rN|��|jjdd�|j��|j��|j� �d|_ n0|��|jjdd�|j ��|j ��d|_ dS) z'Toggle between basic and advanced keys.rZZAdvancedz<< Basic Key Binding Entry)rZTzAdvanced Key Binding Entry >>FN) r�Zcget� startswithr|r{r}Zliftrr~Z focus_setrKrprq)rMr2r2r3r��s     zGetKeysDialog.toggle_levelNcCs |��dS)z3Handler for clicking on key in basic settings list.N)rt)rM�eventr2r2r3ry�sz GetKeysDialog.final_key_selectedcCsN|��}}|j�d�}|r0t||�}|�|�|j�dd�|��d��dS)z2Create formatted string of modifiers plus the key.rdr&rr'N)� get_modifiersrur+r4rJrFrG�join)rM�keylistr0� final_keyr2r2r3rt�s     zGetKeysDialog.build_key_stringcCsdd�|jD�}dd�|D�S)z9Return ordered list of modifiers that have been selected.cSsg|] }|���qSr2)r+)�.0rOr2r2r3� �sz/GetKeysDialog.get_modifiers..cSsg|] }|r|�qSr2r2)r��modr2r2r3r��s)rI)rMZmod_listr2r2r3r��szGetKeysDialog.get_modifierscCsF|j�dd�|j�dd�x|jD]}|�d�q$W|j�d�dS)z#Clear modifiers and keys selection.rrlZmovetoz0.0r<N)ruZ select_clearrzrIrGrF)rMrOr2r2r3r|�s  zGetKeysDialog.clear_key_seqcCs\|j����}|s(|j|j|dd�dS|js8|�|�rH|�|�rH||_|� �|� �dS)NzNo key specified.)r@rB�message) rFr+�striprP�keyerror_titlerK�keys_ok�bind_okrE� grab_release�destroy)rMr��keysr2r2r3ros zGetKeysDialog.okcCsd|_|��|��dS)Nr<)rEr�r�)rMr�r2r2r3rA szGetKeysDialog.cancelcCs�|j�d�}|��}|j}dd�|jD�}|�d�sF|j||dd�nt|sh|ttkrh|j||dd�nR|d gkr�|ttd kr�d }|j|||d�n"||kr�d }|j|||d�nd SdS)z�Validity check on user's 'basic' keybinding selection. Doesn't check the string produced by the advanced dialog because 'modifiers' isn't set. rdcSsg|]}|D]}|�q qSr2r2)r�r�r/r2r2r3r�sz)GetKeysDialog.keys_ok..r'zMissing the final Key)rBr�zNo modifier key(s) specified.)r@rBr�r*)r rzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.TF) rur+r�r�rD�endswithrP� FUNCTION_KEYS� MOVE_KEYS)rMr�r�r0r@Z key_sequences�msgr2r2r3r�s*      zGetKeysDialog.keys_okc Csdy|�|dd��}Wn:tk rN}z|j|j|d|��d�dSd}~XYnX|�||�dSdS)z:Return True if Tcl accepts the new keys else show message.cSsdS)Nr2r2r2r2r3�4�z'GetKeysDialog.bind_ok..z2The entered key sequence is not accepted. Error: )r@rBr�FNT)rxrrPr�Zunbind)rMr�Zbinding�errr2r2r3r�1s zGetKeysDialog.bind_ok)N)N)N)�__name__� __module__� __qualname__r�r?rPrLrHr�ryrtr�r|rorAr�r�r2r2r2r3r5+s/f   r5�__main__)�mainz!idlelib.idle_test.test_config_keyr=F)� verbosity�exit)�run)!�__doc__ZtkinterrrrrZ tkinter.ttkrrrr r r r r,r�r��tupler-ZdigitsZ ALPHANUM_KEYSZPUNCTUATION_KEYSZWHITESPACE_KEYSZ EDIT_KEYSr�rwr4r5r�Zunittestr�Zidlelib.idle_test.htestr�r2r2r2r3�s*