3  f`4@s~dZddlTddlmZddlmZddlZddlZGdddeZe dkrzdd l m Z e d d d d ddl m Z e edS)z6 Dialog for building Tkinter accelerator key bindings )*) Scrollbar) messageboxNc@seZdZdZdddddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZd#ddZd$ddZdd Zd!d"ZdS)% GetKeysDialogzKey Sequence ErrorF)_htest_utestc CsNtj|||j|jdd|jttd|j||j||j|j d|j ||_ ||_ ||_ d|_t||_|jjd|jg|_x,|jD]"}t|}|jd|jj|qWd|_|j|j|j|jd|j|jd|jd|j|s(|jd|j dnd f|sJ|j!|j"d S) al action - string, the name of the virtual event these keys will be mapped to currentKeys - list, a list of all key sequence lists currently mapped to virtual events, for overlap checking _utest - bool, do not wait when running unittest _htest - bool, change box location when running htest ) borderwidth)heightwidthZWM_DELETE_WINDOWFz+%d+%dN)#Toplevel__init__ZwithdrawZ configureZ resizableZFALSEtitleZ transientZgrab_setZprotocolCancelparentactioncurrentKeySequencesresultZ StringVar keyStringsetSetModifiersForPlatform modifier_vars modifiersappendadvanced CreateWidgetsLoadFinalKeyListZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) selfrrrrrrmodifiervariabler#7/opt/alt/python36/lib64/python3.6/idlelib/config_key.pyrsB        *zGetKeysDialog.__init__cOstj||dS)N)r showerror)r argskwargsr#r#r$r%>szGetKeysDialog.showerrorc Cst|dtd}|jtttdt|}|jttdt|dd|j d|_ |j j ddd d d t|d d|j d|_ |j j dd d d d t||_t||_t||_t||_|jj ddtd d d |jj ddtd d d |jj|jj d dtd d|jj d dtd d|jjt||jdd|_|jj ddtd d dt|jd|jdd}|jtdt|jt|jtdd}|jd d tdi|_d}xft|j|j D]T\}}|j!j"||}t#|j|j$|||dd} | j d|dtd| |j|<|d 7}qWt|jtd?d!} | j d dd"dtd#t%|jd$d%t&d&|_'|j'j(d'|j)|j'j dd"d"t*d(t+|jt,|j'j-d)} |j'j.| j/d*| j dd d"t*d(t|jd+|j0d,|_1|j1j ddd"d-t|jtd.|jd/d0d!} | jtdt2|j|jd1|_3|j3jtd2t|jtdEd!} | j ddtd:dS)FNr )r relief)sideexpandfill)r)r+OK)textr commandrr)rowcolumnpadxpadyr)r0r1stickyr2r3)r0r1r5r2zAdvanced Key Binding Entry >>)r/r.)r0r1Zstickr2r3zNew keys for 'z' :)r.)Zanchor)justify textvariabler(r )ZipadxZipadyr+r )r/r.r"ZonvalueZoffvalue)r0r1r2r5z!Select the desired modifier keys z"above, and the final key from the zlist on the right. z"Use upper case Symbols when using z&the Shift modifier. (Letters will be zconverted automatically.))r6r.)r0r1 columnspanr2r5 )r r Z selectmodez)r0r1Zrowspanr5)Zorientr/)Zyscrollcommandz Clear Keys)r.r/)r0r1r9zEnter new binding(s) for 'z' : z2(These bindings will not be checked for validity!))r7)r+z4Key bindings are specified using Tkinter keysyms as zin these samples: , , , , , . Upper case is used when the Shift modifier is present! z8'Emacs style' multi-keystroke bindings are specified as z5follows: , where the first key z!is the 'do-nothing' keybinding. z4Multiple separate bindings for one action should be z,separated by a space, eg., .)r0r1r5zCSelect the desired modifier keys above, and the final key from the zWSelect the desired modifier keys above, and the final key from the list on the right. zySelect the desired modifier keys above, and the final key from the list on the right. Use upper case Symbols when using zSelect 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 zSelect 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.)zKey bindings are specified using Tkinter keysyms as in these samples: , , , , , . Upper case is used when the Shift modifier is present! a 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 a@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 aaKey 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. 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 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., .)4ZFrameZSUNKENZpackZTOPZTRUEZBOTHZBOTTOMXZButtonr,ZbuttonOKZgridrZ buttonCancelframeKeySeqBasicframeKeySeqAdvancedframeControlsBasicframeHelpAdvancedZNSEWlift ToggleLevel buttonLevelZEWZLabelrWZLEFTrZGROOVEZmodifier_checkbuttonsziprrmodifier_labelgetZ CheckbuttonBuildKeyStringZListboxZSINGLE listKeysFinalbindFinalKeySelectedZNSrZVERTICALyviewconfigr ClearKeySeqZ buttonClearZEntryentryKeysAdvanced)r Z frameMainZ frameButtonsZlabelTitleBasicZlabelKeysBasicr1r!r"ZlabelZcheckZ labelFnAdviceZscrollKeysFinalZlabelTitleAdvancedZlabelHelpAdvancedr#r#r$rBs                zGetKeysDialog.CreateWidgetscCs4tjdkrddddg|_n dddg|_ddi|_dS) aUDetermine 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. darwinShiftZControlZOptionZCommandZAltZCtrlN)sysplatformrrF)r r#r#r$rs  z%GetKeysDialog.SetModifiersForPlatformcCs|jjddddkrT|j|jjdd|jj|jj|jjd|_ n0|j|jjdd|j j|j jd|_ dS) Nr.r-ZAdvancedz<< Basic Key Binding Entry)r.TzAdvanced Key Binding Entry >>F) rCZcgetrNrMr>rAr@rOZ focus_setrr=r?)r r#r#r$rBs     zGetKeysDialog.ToggleLevelcCs |jdS)N)rH)r eventr#r#r$rKszGetKeysDialog.FinalKeySelectedcCsP|j}}|jjt}|r2|j||}|j||jjddj|ddS)N<->) GetModifiersrIrGANCHOR TranslateKeyrrrjoin)r ZkeyListrfinalKeyr#r#r$rHs     zGetKeysDialog.BuildKeyStringcCsdd|jD}dd|DS)NcSsg|] }|jqSr#)rG).0r"r#r#r$ sz.GetKeysDialog.GetModifiers..cSsg|] }|r|qSr#r#)r]modr#r#r$r^s)r)r ZmodListr#r#r$rXszGetKeysDialog.GetModifierscCsF|jjdt|jjtdx|jD]}|jdq$W|jjddS)Nrz0.0r )rIZ select_clearENDrLZMOVETOrrr)r r"r#r#r$rNs  zGetKeysDialog.ClearKeySeqc Csnd|_ttjtj|_td |_d|_d|_d|_ |j|j|j|j|j|j }|j j t f|dS) NF1F2F3F4F5F6F7F8F9F10F11F12z~!@#%^&*()_-+={}[]|;:,.<>/?TabSpaceReturn BackSpaceDeleteInsertHomeEndPage Up Page Down Left Arrow Right ArrowUp Arrow Down Arrow) rarbrcrdrerfrgrhrirjrkrl)rmrnro)rprqrr)rsrtrurvrwrxryrz) functionKeystuplestringascii_lowercaseZdigitsZ alphanumKeysZpunctuationKeysZwhitespaceKeysZeditKeysmoveKeysrIinsertr`)r keysr#r#r$rs $zGetKeysDialog.LoadFinalKeyListc$Csddddddddd d d d d ddddddddddddddddddd d!d"d#d$#}||kr\||}d%|krv|tjkrv|j}d&|}|S)'z2Translate from keycap symbol to the Tkinter keysymZspaceZ asciitildeZexclamZatZ numbersignZpercentZ asciicircumZ ampersandZasteriskZ parenleftZ parenrightZ underscoreZminusZplusZequalZ braceleftZ bracerightZ bracketleftZ bracketrightZbarZ semicolonZcolonZcommaZperiodZlessZgreaterZslashZquestionZPriorZNextZLeftZRightZUpZDownrm)#rn~!@#%^&r()_rV+={}[]|;:,.rUrW/?zPage Upz Page Downz Left Arrowz Right ArrowzUp Arrowz Down ArrowrmrQzKey-)r}r~upper)r keyrZ translateDictr#r#r$rZs   zGetKeysDialog.TranslateKeyNcCs\|jjj}|s(|j|j|dddS|js8|j|rH|j|rH||_|j |j dS)NzNo key specified.)rrmessage) rrGstripr%keyerror_titlerKeysOKbind_okr grab_releasedestroy)r rTrr#r#r$r,s zGetKeysDialog.OKcCsd|_|j|jdS)Nr )rrr)r rTr#r#r$rszGetKeysDialog.CancelcCs|jjt}|j}d}|j}dd|jD}|jdsJ|j||ddn~| rr||j|j krr|j||ddnV|d gkr||j|j dkrd }|j|||dn"||krd }|j|||dnd}|S)zValidity check on user's 'basic' keybinding selection. Doesn't check the string produced by the advanced dialog because 'modifiers' isn't set. FcSsg|]}|D]}|q qSr#r#)r]Zkeylistrr#r#r$r^sz(GetKeysDialog.KeysOK..rWzMissing the final Key)rrzNo modifier key(s) specified.)rrrrQrmrnzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.T)rmrn) rIrGrYrXrrendswithr%r{r)r rr\rZkeysOKrZ key_sequencesmsgr#r#r$rs,     zGetKeysDialog.KeysOKcCsby|j|dd}Wn8tk rL}z|j|j|d|ddSd}~XnX|j||dSdS)z:Return True if Tcl accepts the new keys else show message.cSsdS)Nr#r#r#r#r$sz'GetKeysDialog.bind_ok..z2The entered key sequence is not accepted. Error: )rrrFNT)rJZTclErrorr%rZunbind)r rZbindingerrr#r#r$rs zGetKeysDialog.bind_ok)N)N)__name__ __module__ __qualname__rrr%rrrBrKrHrXrNrrZr,rrrr#r#r#r$r s -O !r__main__)mainz!idlelib.idle_test.test_config_keyr F) verbosityexit)run)__doc__ZtkinterZ tkinter.ttkrrr}rRrrrZunittestrZidlelib.idle_test.htestrr#r#r#r$s