a  ze8@sdZddlmZmZmZmZddlmZmZm Z m Z m Z m Z ddlm Z ddlmZddlZddlZdZeejejZedZd Zd Zd ZeeeeeeZd d ZGdddeZedkrddlm Z e ddddddl!m"Z"e"edS)z6 Dialog for building Tkinter accelerator key bindings )ToplevelListbox StringVarTclError)FrameButton CheckbuttonEntryLabel Scrollbar) messagebox) _setup_dialogN) 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%|vrr|tjvrr|}d&|S)'z3Translate from keycap symbol to the Tkinter keysym.spaceZ asciitildeZexclamZatZ numbersignpercentZ asciicircumZ ampersandZasteriskZ parenleftZ parenrightZ underscoreZminusZplusZequalZ braceleftZ bracerightZ bracketleftZ bracketrightZbarZ semicoloncolonZcommaZperiodZlessZgreaterZslashZquestionZPriorZNextZLeftZRightZUpZDownr)#r~!@#%^&*()_-+={}[]|;:,.<>/?rrrrrrrShiftzKey-)getstringascii_lowercaseupper)key modifiersmappingr<F/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/config_key.py translate_keys" r>c@seZdZdZdddddZddZdd Zd d Zd d ZdddZ ddZ ddZ ddZ d ddZ d!ddZddZddZdS)" GetKeysDialogzKey Sequence ErrorF)_htest_utestc CsJt||||jdd|jddd||||t||| d|j ||_ ||_ ||_ d|_t||_|jd|g|_|jD]"}t|}|d|j|qd|_|||d||d|d||s$|d|dnd f|sF| |!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 transientr Zgrab_setprotocolcancelparentactioncurrent_key_sequencesresultr key_stringsetset_modifiers_for_platform modifier_varsr:appendadvancedcreate_widgetsZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) selfrMrJrNrOr@rAmodifiervariabler<r<r=rI1sN        zGetKeysDialog.__init__cOstj|i|dSN)r showerror)rXargskwargsr<r<r=r\bszGetKeysDialog.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}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+|_|jjd,gtR|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)BNrGZsunken)rCrelieftopTZboth)sideexpandfillZbottomx)rarcZOK)textrEcommandrrB)rowcolumnpadxpadyZCancelZ keyseq_basic)nameZnsew)rhristickyrjrkzNew keys for 'z' :rfw)anchorleftZgroove)justify textvariabler_rC)ZipadxZipadyrc)rhrirnrjrF)rgrfrZZonvalueZoffvalue)rhrirjrnzSelect 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.))rsrf)rhri columnspanrjrn Zsingle)rErDZ selectmodeendzns)rhriZrowspanrnZvertical)Zorientrg)Zyscrollcommandz Clear Keys)rfrg)rhrirvZkeyseq_advancedzEnter new binding(s) for 'z' : z2(These bindings will not be checked for validity!))rt)rcaKey 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., .)rhrirn<< Basic Key Binding Entry)rgrfZew)rhriZstickrjrk)(rframepackrokZ button_okZgridrLZ button_cancelframe_keyseq_basicr rNrQframe_controls_basicZmodifier_checkbuttonszipr:rTmodifier_labelr5rbuild_key_stringrlist_keys_finalinsertAVAILABLE_KEYSbindfinal_key_selectedr yviewconfigrR clear_key_seqZ button_clearframe_keyseq_advancedr advanced_keysframe_help_advanced toggle_level button_level)rXr|Z frame_buttonsZ basic_titleZ basic_keysrirYrZZlabelcheckZ help_basicZscroll_keys_finalZadvanced_titleZ help_advancedr<r<r=rWfs           zGetKeysDialog.create_widgetscCs.tjdkrgd|_n gd|_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. darwin)r4ControlZOptionZCommand)rZAltr4rZCtrlN)sysplatformr:rrXr<r<r=rSs   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.rfZAdvancedr{roTzAdvanced Key Binding Entry >>FN) rZcget startswithrrrZliftrrZ focus_setrVrrrr<r<r=rs     zGetKeysDialog.toggle_levelNcCs |dS)z3Handler for clicking on key in basic settings list.N)rrXeventr<r<r=rsz GetKeysDialog.final_key_selectedcCsN|}}|jd}|r0t||}|||jdd|ddS)z2Create formatted string of modifiers plus the key.rqr0r$r1N) get_modifiersrr5r>rUrQrRjoin)rXkeylistr: final_keyr<r<r=rs     zGetKeysDialog.build_key_stringcCsdd|jD}dd|DS)z9Return ordered list of modifiers that have been selected.cSsg|] }|qSr<)r5).0rZr<r<r= z/GetKeysDialog.get_modifiers..cSsg|] }|r|qSr<r<)rmodr<r<r=rr)rT)rXZmod_listr<r<r=rszGetKeysDialog.get_modifierscCsB|jdd|jdd|jD]}|dq"|jddS)z#Clear modifiers and keys selection.rryZmovetoz0.0rFN)rZ select_clearrrTrRrQ)rXrZr<r<r=rs   zGetKeysDialog.clear_key_seqcCs\|j}|s(|j|j|dddS|js8||rH||rH||_| | dS)NzNo key specified.rJrMmessage) rQr5stripr\keyerror_titlerVkeys_okbind_okrP grab_releasedestroy)rXrkeysr<r<r=r~s zGetKeysDialog.okcCsd|_||dS)NrF)rPrrrr<r<r=rLszGetKeysDialog.cancelcCs|jd}|}|j}dd|jD}|dsF|j||ddnt|sh|ttvrh|j||ddnR|d gkr|ttd vrd }|j|||dn"||vrd }|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. rqcSsg|]}|D]}|q qSr<r<)rrr9r<r<r=rsz)GetKeysDialog.keys_ok..r1zMissing the final Key)rMrzNo modifier key(s) specified.rr4)rrzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.TF) rr5rrrOendswithr\ FUNCTION_KEYS MOVE_KEYS)rXrrr:rJZ key_sequencesmsgr<r<r=rs4     zGetKeysDialog.keys_okc Cshz||dd}Wn>tyR}z&|j|j|d|dWYd}~dSd}~00|||dSdS)z:Return True if Tcl accepts the new keys else show message.cSsdSr[r<r<r<r<r=6rz'GetKeysDialog.bind_ok..z2The entered key sequence is not accepted. Error: rNFT)rrr\rZunbind)rXrZbindingerrr<r<r=r3s zGetKeysDialog.bind_ok)N)N)N)__name__ __module__ __qualname__rrIr\rWrSrrrrrr~rLrrr<r<r<r=r?,s 1f   r?__main__)mainz!idlelib.idle_test.test_config_keyrGF) verbosityexit)run)#__doc__tkinterrrrrZ tkinter.ttkrrrr r r r Ztkinter.simpledialogr r6rrtupler7digitsZ ALPHANUM_KEYSZPUNCTUATION_KEYSZWHITESPACE_KEYSZ EDIT_KEYSrrr>r?rZunittestrZidlelib.idle_test.htestrr<r<r<r=s8