B 3[X@sdZddlmZmZmZmZddlmZmZm Z m Z m Z m Z ddlm Z ddlZddlZdZeejejZedZdZd Zd ZeeeeeeZd d ZGd ddeZedkrddlmZeddddddlm Z e edS)z6 Dialog for building Tkinter accelerator key bindings )ToplevelListbox StringVarTclError)FrameButton CheckbuttonEntryLabel Scrollbar) messageboxN) ZF1ZF2ZF3ZF4ZF5ZF6ZF7ZF8ZF9ZF10ZF11ZF12z~!@#%^&*()_-+={}[]|;:,.<>/?)TabSpaceZReturn)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-)getstringascii_lowercaseupper)key modifiersmappingr25/opt/alt/python37/lib/python3.7/idlelib/config_key.py translate_keys   r4c@seZdZdZdddddZddZdd Zd d Zd d ZdddZ ddZ ddZ ddZ d ddZ d!ddZddZddZdS)" GetKeysDialogzKey Sequence ErrorF)_htest_utestc CsFt||||jdd|jddd||||||d|j ||_ ||_ ||_ d|_ t||_|jd|g|_x,|jD]"}t|}|d|j|qWd|_|||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)heightwidthZWM_DELETE_WINDOWz+%d+%dN)!r__init__ZwithdrawZ configureZ resizabletitleZ transientZgrab_setZprotocolcancelparentactioncurrent_key_sequencesresultr key_stringsetset_modifiers_for_platform modifier_varsr0appendadvancedcreate_widgetsZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) selfrBr@rCrDr6r7modifiervariabler2r2r3r?0s@        *zGetKeysDialog.__init__cOstj||dS)N)r showerror)rMargskwargsr2r2r3rP`szGetKeysDialog.showerrorc Cs0t|ddd|_}|jddddt|}|jdd d t|d d |jd |_|jjdddddt|dd |jd |_|jjdddddt|dd|_ |j jddddddt |j d|j dd}|jddt |j d|j ddd}|jddd dt||_ |j jddddd i|_d}xft|j|jD]T\}}|j||}t|j |j|||d!d"} | jd|ddd#| |j|<|d7}q0Wt |j dd$d%} | jddd&ddd't|j d(d)d*d+|_|jjdBt|jd-|j|jjdd&d&d.d/t|j d0|jjd1} |jj| jd2| jddd&d.d/t|j d3|j d4|_!|j!jddd&d5t|d6d|_"|j"jddddddt |j"dd7|j d8d9d%} | jddt#|j"|j d:|_$|j$jd d;t||_%|j%jddddd t |j%ddd?|_'|j'jddd@dddA|&dS)CNr=Zsunken)r9relieftopTZboth)sideexpandfillZbottomx)rUrWZOK)textr;commandrr8)rowcolumnpadxpadyZCancelZ keyseq_basic)nameZnsew)r\r]stickyr^r_zNew keys for 'z' :)rZw)anchorleftZgroove)justify textvariablerSr9)ZipadxZipadyrW)r\r]rbr^r<)r[rZrOZonvalueZoffvalue)r\r]r^rbzSelect 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 selectmodeendzns)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)rWaKey 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)(rframeZpackrokZ button_okZgridrAZ button_cancelframe_keyseq_basicr rCrFframe_controls_basicZmodifier_checkbuttonszipr0rImodifier_labelr+rbuild_key_stringrlist_keys_finalinsertAVAILABLE_KEYSbindfinal_key_selectedr yviewconfigrG clear_key_seqZ button_clearframe_keyseq_advancedr advanced_keysframe_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)sysplatformr0rs)rMr2r2r3rHs  z(GetKeysDialog.set_modifiers_for_platformcCs|jddrN||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) rZcget startswithr|r{r}Zliftrr~Z focus_setrKrprq)rMr2r2r3rs     zGetKeysDialog.toggle_levelNcCs |dS)z3Handler for clicking on key in basic settings list.N)rt)rMeventr2r2r3rysz GetKeysDialog.final_key_selectedcCsN|}}|jd}|r0t||}|||jdd|ddS)z2Create formatted string of modifiers plus the key.rdr&rr'N) get_modifiersrur+r4rJrFrGjoin)rMkeylistr0 final_keyr2r2r3rts     zGetKeysDialog.build_key_stringcCsdd|jD}dd|DS)z9Return ordered list of modifiers that have been selected.cSsg|] }|qSr2)r+).0rOr2r2r3 sz/GetKeysDialog.get_modifiers..cSsg|] }|r|qSr2r2)rmodr2r2r3rs)rI)rMZmod_listr2r2r3rszGetKeysDialog.get_modifierscCsF|jdd|jddx|jD]}|dq$W|jddS)z#Clear modifiers and keys selection.rrlZmovetoz0.0r<N)ruZ select_clearrzrIrGrF)rMrOr2r2r3r|s  zGetKeysDialog.clear_key_seqcCs\|j}|s(|j|j|dddS|js8||rH||rH||_| | dS)NzNo key specified.)r@rBmessage) rFr+striprPkeyerror_titlerKkeys_okbind_okrE grab_releasedestroy)rMrkeysr2r2r3ros zGetKeysDialog.okcCsd|_||dS)Nr<)rErr)rMrr2r2r3rA szGetKeysDialog.cancelcCs|jd}|}|j}dd|jD}|dsF|j||ddnt|sh|ttkrh|j||ddnR|d gkr|ttd krd }|j|||dn"||krd }|j|||dnd SdS)zValidity 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)rrr/r2r2r3rsz)GetKeysDialog.keys_ok..r'zMissing the final Key)rBrzNo modifier key(s) specified.)r@rBrr*)r rzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.TF) rur+rrrDendswithrP FUNCTION_KEYS MOVE_KEYS)rMrrr0r@Z key_sequencesmsgr2r2r3rs*      zGetKeysDialog.keys_okc Csdy||dd}Wn:tk rN}z|j|j|d|ddSd}~XYnX|||dSdS)z:Return True if Tcl accepts the new keys else show message.cSsdS)Nr2r2r2r2r34z'GetKeysDialog.bind_ok..z2The entered key sequence is not accepted. Error: )r@rBrFNT)rxrrPrZunbind)rMrZbindingerrr2r2r3r1s zGetKeysDialog.bind_ok)N)N)N)__name__ __module__ __qualname__rr?rPrLrHrryrtrr|rorArrr2r2r2r3r5+s/f   r5__main__)mainz!idlelib.idle_test.test_config_keyr=F) verbosityexit)run)!__doc__ZtkinterrrrrZ tkinter.ttkrrrr r r r r,rrtupler-ZdigitsZ ALPHANUM_KEYSZPUNCTUATION_KEYSZWHITESPACE_KEYSZ EDIT_KEYSrrwr4r5rZunittestrZidlelib.idle_test.htestrr2r2r2r3s*