U :e8@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)ZHomeZEndPage Up Page Down Left Arrow Right ArrowUp Arrow 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 numbersignpercentZ asciicircumZ ampersandZasteriskZ parenleftZ parenrightZ underscoreZminusZplusZequalZ braceleftZ bracerightZ bracketleftZ bracketrightZbarZ semicolonZcolonZcommaZperiodZlessZgreaterZslashZquestionZPriorZNextZLeftZRightZUpZDownr )#r~!@#%^&*()_-+={}[]|;:,.<>/?rrrrrrr ShiftzKey-)getstringascii_lowercaseupper)key modifiersmappingr97/usr/local/python38/lib/python3.8/idlelib/config_key.py translate_keysP r;c@seZdZdZdddddZddZdd Zd d Zd d ZdddZ ddZ ddZ ddZ d ddZ d!ddZddZddZdS)" GetKeysDialogzKey Sequence ErrorF)_htest_utestc CsBt||||jdd|jddd||||||d|j ||_ ||_ ||_ d|_ t||_|jd|g|_|jD]"}t|}|d|j|qd|_|||d||d|d||s|d|dnd f|s>|| 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_setprotocolcancelparentactioncurrent_key_sequencesresultr key_stringsetset_modifiers_for_platform modifier_varsr7appendadvancedcreate_widgetsZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) selfrJrGrKrLr=r>modifiervariabler9r9r:rF0sL        zGetKeysDialog.__init__cOstj||dSN)r showerror)rUargskwargsr9r9r:rY`szGetKeysDialog.showerrorc Cs,t|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}t|j|jD]T\}}|j||}t|j |j|||d!d"} | jd|ddd#| |j|<|d7}q.t |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)CNrDZsunken)r@relieftopTZboth)sideexpandfillZbottomx)r^r`ZOK)textrBcommandrr?)rowcolumnpadxpadyZCancelZ keyseq_basic)nameZnsew)rerfstickyrgrhzNew keys for 'z' :rcw)anchorleftZgroove)justify textvariabler\r@)ZipadxZipadyr`)rerfrkrgrC)rdrcrWZonvalueZoffvalue)rerfrgrkzSelect 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.))rprc)rerf columnspanrgrk Zsingle)rBrAZ selectmodeendzns)rerfZrowspanrkZvertical)Zorientrd)Zyscrollcommandz Clear Keys)rcrd)rerfrsZkeyseq_advancedzEnter new binding(s) for 'z' : z2(These bindings will not be checked for validity!))rq)r`aKey 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., .)rerfrk<< Basic Key Binding Entry)rdrcZew)rerfZstickrgrh)rv)(rframepackrokZ button_okZgridrIZ button_cancelframe_keyseq_basicr rKrNframe_controls_basicZmodifier_checkbuttonszipr7rQmodifier_labelr2rbuild_key_stringrlist_keys_finalinsertAVAILABLE_KEYSbindfinal_key_selectedr yviewconfigrO clear_key_seqZ button_clearframe_keyseq_advancedr advanced_keysframe_help_advanced toggle_level button_level)rUryZ frame_buttonsZ basic_titleZ basic_keysrfrVrWZlabelcheckZ help_basicZscroll_keys_finalZadvanced_titleZ help_advancedr9r9r:rTds           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. darwinr1ZControlZOptionZCommandZAltZCtrlN)sysplatformr7rrUr9r9r:rPs  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.rcZAdvancedrxrlTzAdvanced Key Binding Entry >>FN) rZcget startswithrrrZliftrrZ focus_setrSr|r}rr9r9r:rs     zGetKeysDialog.toggle_levelNcCs |dS)z3Handler for clicking on key in basic settings list.N)rrUeventr9r9r:rsz GetKeysDialog.final_key_selectedcCsN|}}|jd}|r0t||}|||jdd|ddS)z2Create formatted string of modifiers plus the key.rnr-r!r.N) get_modifiersrr2r;rRrNrOjoin)rUkeylistr7 final_keyr9r9r:rs     zGetKeysDialog.build_key_stringcCsdd|jD}dd|DS)z9Return ordered list of modifiers that have been selected.cSsg|] }|qSr9)r2).0rWr9r9r: sz/GetKeysDialog.get_modifiers..cSsg|] }|r|qSr9r9)rmodr9r9r:rs)rQ)rUZmod_listr9r9r:rszGetKeysDialog.get_modifierscCsB|jdd|jdd|jD]}|dq"|jddS)z#Clear modifiers and keys selection.rrvZmovetoz0.0rCN)rZ select_clearrrQrOrN)rUrWr9r9r:rs   zGetKeysDialog.clear_key_seqcCs\|j}|s(|j|j|dddS|js8||rH||rH||_| | dS)NzNo key specified.rGrJmessage) rNr2striprYkeyerror_titlerSkeys_okbind_okrM grab_releasedestroy)rUrkeysr9r9r:r{s zGetKeysDialog.okcCsd|_||dS)NrC)rMrrrr9r9r:rI 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. rncSsg|]}|D]}|q qSr9r9)rrr6r9r9r:rsz)GetKeysDialog.keys_ok..r.zMissing the final Key)rJrzNo modifier key(s) specified.rr1)r rzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.TF) rr2rrrLendswithrY FUNCTION_KEYS MOVE_KEYS)rUrrr7rGZ key_sequencesmsgr9r9r:rs4     zGetKeysDialog.keys_okc Csjz||dd}Wn@tk rT}z"|j|j|d|dWYdSd}~XYnX|||dSdS)z:Return True if Tcl accepts the new keys else show message.cSsdSrXr9r9r9r9r:4z'GetKeysDialog.bind_ok..z2The entered key sequence is not accepted. Error: rFNT)rrrYrZunbind)rUrZbindingerrr9r9r:r1s zGetKeysDialog.bind_ok)N)N)N)__name__ __module__ __qualname__rrFrYrTrPrrrrrr{rIrrr9r9r9r:r<+s  0f   r<__main__)mainz!idlelib.idle_test.test_config_keyrDF) verbosityexit)run)!__doc__tkinterrrrrZ tkinter.ttkrrrr r r r r3rrtupler4digitsZ ALPHANUM_KEYSZPUNCTUATION_KEYSZWHITESPACE_KEYSZ EDIT_KEYSrrr;r<rZunittestrZidlelib.idle_test.htestrr9r9r9r:s6