3 § f`4ã@s~dZddlTddlmZddlmZddlZddlZGdd„deƒZe dkrzdd l m Z e d d d d �ddl m Z e eƒdS)z6 Dialog for building Tkinter accelerator key bindings é)Ú*)Ú Scrollbar)Ú messageboxNc@s”eZdZdZdddœdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zd#dd„Zd$dd„Zdd „Zd!d"„ZdS)%Ú GetKeysDialogzKey Sequence ErrorF)Ú_htestÚ_utestc CsNtj||ƒ|jƒ|jdd�|jttd�|j|ƒ|j|ƒ|jƒ|j d|j ƒ||_ ||_ ||_ d|_t|ƒ|_|jjdƒ|jƒg|_x,|jD]"}t|ƒ}|jdƒ|jj|ƒqœWd|_|jƒ|jƒ|jƒ|jd|jƒ|jƒd|jƒd|jƒ|�s(|jƒd|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)ÚheightÚwidthZWM_DELETE_WINDOWÚFz+%d+%déé–N)#ÚToplevelÚ__init__ZwithdrawZ configureZ resizableZFALSEÚtitleZ transientZgrab_setZprotocolÚCancelÚparentÚactionÚcurrentKeySequencesÚresultZ StringVarÚ keyStringÚsetÚSetModifiersForPlatformÚ modifier_varsÚ modifiersÚappendÚadvancedÚ CreateWidgetsÚLoadFinalKeyListZupdate_idletasksZgeometryZ winfo_rootxZ winfo_widthZwinfo_reqwidthZ winfo_rootyZ winfo_heightZwinfo_reqheightZ deiconifyZ wait_window) ÚselfrrrrrrÚmodifierÚvariable©r#ú7/opt/alt/python36/lib64/python3.6/idlelib/config_key.pyrsB        *zGetKeysDialog.__init__cOstj||ŽdS)N)rÚ showerror)r ÚargsÚkwargsr#r#r$r%>szGetKeysDialog.showerrorc Cst|dtd�}|jtttd�t|ƒ}|jttd�t|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�|jjƒt||jdd�|_|jj ddtd d d�t|jd|jdd�}|jtd�t|jt|jtdd�}|jd d td�i|_d}xft|j|j ƒD]T\}}|j!j"||ƒ}t#|j|j$|||dd�} | j d|dtd�| |j|<|d 7}�q Wt|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!�} | jtd�t2|j|jd1�|_3|j3jtd2�t|jtdEd!�} | j ddtd:�dS)FNr )r Úrelief)ÚsideÚexpandÚfill)r)r+ÚOKé)Útextr Úcommandrr)ÚrowÚcolumnÚpadxÚpadyré)r0r1Ústickyr2r3)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 zŸin 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 zŸ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 z¸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.)zÓKey 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. 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 is the 'do-nothing' keybinding. Multiple separate bindings for one action should be 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 is the 'do-nothing' keybinding. Multiple separate bindings for one action should be separated by a space, eg., .)4ZFrameZSUNKENZpackZTOPZTRUEZBOTHZBOTTOMÚXZButtonr,ZbuttonOKZgridrZ buttonCancelÚframeKeySeqBasicÚframeKeySeqAdvancedÚframeControlsBasicÚframeHelpAdvancedZNSEWÚliftÚ ToggleLevelÚ buttonLevelZEWZLabelrÚWZLEFTrZGROOVEZmodifier_checkbuttonsÚziprrÚmodifier_labelÚgetZ CheckbuttonÚBuildKeyStringZListboxZSINGLEÚ listKeysFinalÚbindÚFinalKeySelectedZNSrZVERTICALÚyviewÚconfigrÚ ClearKeySeqZ buttonClearZEntryÚentryKeysAdvanced)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. ÚdarwinÚShiftZControlZOptionZCommandZAltZCtrlN)ÚsysÚplatformrrF)r r#r#r$r‘s  z%GetKeysDialog.SetModifiersForPlatformcCsˆ|jjdƒdd…dkrT|jƒ|jjdd�|jjƒ|jjƒ|jjƒd|_ n0|jƒ|jjdd�|j jƒ|j jƒd|_ dS) Nr.r-ZAdvancedz<< Basic Key Binding Entry)r.TzAdvanced Key Binding Entry >>F) rCZcgetrNrMr>rAr@rOZ focus_setrr=r?)r r#r#r$rBŸs     zGetKeysDialog.ToggleLevelcCs |jƒdS)N)rH)r Úeventr#r#r$rK®szGetKeysDialog.FinalKeySelectedcCsP|jƒ}}|jjtƒ}|r2|j||ƒ}|j|ƒ|jjddj|ƒdƒdS)Nú<ú-ú>) Ú GetModifiersrIrGÚANCHORÚ TranslateKeyrrrÚjoin)r ZkeyListrÚfinalKeyr#r#r$rH±s     zGetKeysDialog.BuildKeyStringcCsdd„|jDƒ}dd„|DƒS)NcSsg|] }|jƒ‘qSr#)rG)Ú.0r"r#r#r$ú ºsz.GetKeysDialog.GetModifiers..cSsg|] }|r|‘qSr#r#)r]Úmodr#r#r$r^»s)r)r ZmodListr#r#r$rX¹szGetKeysDialog.GetModifierscCsF|jjdtƒ|jjtdƒx|jD]}|jdƒq$W|jjdƒdS)Nrz0.0r )rIZ select_clearÚENDrLZMOVETOrrr)r r"r#r#r$rN½s  zGetKeysDialog.ClearKeySeqc Csnd|_ttjtjƒ|_td ƒ|_d|_d|_d|_ |j|j|j|j|j|j }|j j t f|žŽdS) NÚF1ÚF2ÚF3ÚF4ÚF5ÚF6ÚF7ÚF8ÚF9ÚF10ÚF11ÚF12z~!@#%^&*()_-+={}[]|;:,.<>/?ÚTabÚSpaceÚReturnÚ BackSpaceÚDeleteÚInsertÚHomeÚEndúPage Upú Page Downú Left Arrowú Right ArrowúUp Arrowú Down Arrow) rarbrcrdrerfrgrhrirjrkrl)rmrnro)rprqrr)rsrtrurvrwrxryrz) Ú functionKeysÚtupleÚstringÚascii_lowercaseZdigitsZ alphanumKeysZpunctuationKeysZwhitespaceKeysZeditKeysÚmoveKeysrIÚinsertr`)r Úkeysr#r#r$rÄs $zGetKeysDialog.LoadFinalKeyListc$Cs‚ddddddddd 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$rZÓs   zGetKeysDialog.TranslateKeyNcCs\|jjƒjƒ}|s(|j|j|dd�dS|js8|j|ƒrH|j|ƒrH||_|j ƒ|j ƒdS)NzNo key specified.)rrÚmessage) rrGÚstripr%Úkeyerror_titlerÚKeysOKÚbind_okrÚ grab_releaseÚdestroy)r rTr�r#r#r$r,æs zGetKeysDialog.OKcCsd|_|jƒ|jƒdS)Nr )rr r¡)r rTr#r#r$rñszGetKeysDialog.CancelcCsÌ|jjtƒ}|jƒ}d}|j}dd„|jDƒ}|jdƒsJ|j||dd�n~| rr||j|j krr|j||dd�nV|d gkr¦||j|j dkr¦d }|j|||d�n"||krÄd }|j|||d�nd}|S)z©Validity 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]Zkeylistršr#r#r$r^sz(GetKeysDialog.KeysOK..rWzMissing the final Key)rr›zNo modifier key(s) specified.)rrr›rQrmrnzBThe shift modifier by itself may not be used with this key symbol.z'This key combination is already in use.T)rmrn) rIrGrYrXr�rÚendswithr%r{r)r r�r\rZkeysOKrZ key_sequencesÚmsgr#r#r$ržös,     zGetKeysDialog.KeysOKcCsby|j|dd„ƒ}Wn8tk rL}z|j|j|d|›�d�dSd}~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: )rrr›FNT)rJZTclErrorr%r�Zunbind)r r�ZbindingÚerrr#r#r$rŸs zGetKeysDialog.bind_ok)N)N)Ú__name__Ú __module__Ú __qualname__r�rr%rrrBrKrHrXrNrrZr,rržrŸr#r#r#r$r s -O !rÚ__main__)Úmainz!idlelib.idle_test.test_config_keyr F)Ú verbosityÚexit)Úrun)Ú__doc__ZtkinterZ tkinter.ttkrrr}rRrrr¦ZunittestrªZidlelib.idle_test.htestr­r#r#r#r$Ús