[H@sdZddlZddlZddlZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdQZdRZdSZdTZdUZdVZ ej!dkrd[Z"eeee fZ#nd`Z"eeeefZ#e$d!d"e%e&e"DZ'd#Z(Gd$d%d%Z)e%de&e">Z*d&d"e*DZ+d'd(Z,e,e*Z-gZ.x]e*D]UZ/dZ0x9e%e&e"D]%Z1de1>e/@re0e#e1OZ0qqWe.j2e0qWGd)d*d*Z3dxZ4e3fde)fe&e4dZ5e$dDd"e%e&e4DZ6ej7dEZ8ej7dFZ9dGdHZ:dIdJZ;iZ<dKdLZ=dMdNZ>e?dOkrddPl@mAZAeAe>ndS)ya MultiCall - a class which inherits its methods from a Tkinter widget (Text, for example), but enables multiple calls of functions per virtual event - all matching events will be called, not only the most specific one. This is done by wrapping the event functions - event_add, event_delete and event_info. MultiCall recognizes only a subset of legal event sequences. Sequences which are not recognized are treated by the original Tk handling mechanism. A more-specific event will be called before a less-specific event. The recognized sequences are complete one-event sequences (no emacs-style Ctrl-X Ctrl-C, no shortcuts like <3>), for all types of events. Key/Button Press/Release events can have modifiers. The recognized modifiers are Shift, Control, Option and Command for Mac, and Control, Alt, Shift, Meta/M for other platforms. For all events which were handled by MultiCall, a new member is added to the event instance passed to the binded functions - mc_type. This is one of the event type constants defined in this module (such as MC_KEYPRESS). For Key/Button events (which are handled by MultiCall and may receive modifiers), another member is added - mc_state. This member gives the state of the recognized modifiers, as a combination of the modifier constants also defined in this module (for example, MC_SHIFT). Using these members is absolutely portable. The order by which events are called is defined by these rules: 1. A more-specific event will be called before a less-specific event. 2. A recently-binded event will be called before a previously-binded event, unless this conflicts with the first rule. Each function will be called at most once for each event. N darwinShiftControlOptionCommandAltMetaMcCs-g|]#}t|D]}||fqqS) _modifiers).0numbernamer r '/usr/lib/python3.4/idlelib/MultiCall.py 7s r&zapplication has been destroyedc@s@eZdZddZddZddZddZd S) _SimpleBindercCsJ||_dt|dd|_||_||_g|_d|_dS)N)type_typessequencewidget widgetinst bindedfuncs handlerid)selfr*r-r.r r r%__init__Js     z_SimpleBinder.__init__cCsY|jsE|j|jdd}|jj|j|j||_n|jj|dS)NcSss||_i}x]tt|dddD]?}||}||kr,d||<||}|rk|Sq,q,WdS)NrTr3)mc_typerangelen)eventlr4 wascalledifuncrr r r%handlerTs #    z#_SimpleBinder.bind..handler)r0r/r*r-bindr.r,append)r1tripletr;r=r r r%r>Rs   z_SimpleBinder.bindcCsH|jj||jsD|jj|j|j|jd|_ndS)N)r/remover-unbindr.r,r0)r1r@r;r r r%rBbs z_SimpleBinder.unbindcCsw|jrsy#|jj|j|j|jWqstjk ro}zt|jdkr]nWYdd}~XqsXndS)Nr) r0r-rBr.r,tkinterTclErrorAPPLICATION_GONEargs)r1er r r%__del__hs z_SimpleBinder.__del__N)__name__ __module__ __qualname__r2r>rBrHr r r r%r'Is    r'cs8g|].djfddttDqS)c3s1|]'\}}d|>@r|ddVqdS)rr-Nr )r"r:m)sr r% ws z.)join enumerater!)r"r )rOr%r&ws csodd}g}xV|D]Nttfdd|D}|jd|dd|j|qW|S)zFor each item of states return a list containing all combinations of that item with individual bits reset, sorted by the number of set bits. cSs6d}x)|r1t|d\}}||7}q W|S)znumber of bits set in n base 2rr)divmod)nZnbZremr r r%nbitss  zexpand_substates..nbitsc3s|]}|@VqdS)Nr )r"x)stater r%rPsz#expand_substates..keyreverseT)listsetsortr?)ZstatesrUZ statelistZ substatesr )rWr%expand_substates|s  %r]c@sLeZdZddZddZddZddZd d Zd S) _ComplexBindercCs%||||j|jdd}|S)Nc Ssdg|dd<||_||_i}d}x||D]t}xatt|dddD]C} || } | |kr[d|| <|| |}|rPqq[q[W|r8Pq8q8Wg|dd.handler)rarb)r1r`r4r_r=r r r%Z__create_handlers z_ComplexBinder.__create_handlercs|_t|d_|_|_iddtDd6_g_g_g_ xtD]}fddt |D}j ||t |}dt |jd}jj|jjj||fqkWdS)NrcSsg|] }gqSr r )r"rOr r r%r&s z+_ComplexBinder.__init__..cs!g|]}jd|qS)N)r/)r"r:)r1r r%r&s r(r))r*r+typenamer-r._statesr/ handleridsrarb_state_subsets_ComplexBinder__create_handler _state_codes _state_namesr?r>)r1r*r-r.rOr`r=seqr )r1r%r2s       z_ComplexBinder.__init__csdjkrddtDjd.cs2g|](}tD]}j||qqSr )rgr/)r"detailr:)rOr1r r%r&s z <%s%s-%s>cs jddjS)Nrr)r/r?r )r;r1r@r r%sz%_ComplexBinder.bind..)r/rerhr*rirjrdrfr?r-r>r.rarb)r1r@r;r`r=rkdoitr )r;rOr1r@r%r>s    z_ComplexBinder.bindcs?fdd}js+|njj|dS)Ncs jddjS)Nrr)r/rAr )r;r1r@r r%rmsz'_ComplexBinder.unbind..)rarbr?)r1r@r;rnr )r;r1r@r%rBs  z_ComplexBinder.unbindcCsxx|jD]m\}}y|jj|j||Wq tjk rv}zt|jdkrdnWYdd}~Xq Xq WdS)Nr)rfr-rBr.rCrDrErF)r1rkidrGr r r%rHs z_ComplexBinder.__del__N)rIrJrKrhr2r>rBrHr r r r%r^s     r^KeyPressKey KeyRelease ButtonPressButton ButtonReleaseActivate CirculateColormap Configure DeactivateDestroyEnterExposeFocusInFocusOutGravityLeaveMapMotion MouseWheelPropertyReparentUnmap VisibilitycCs-g|]#}t|D]}||fqqSr )r+)r"r#r$r r r%r&s z^\w+$z^[1-5]$cCsY| s'|ddks'|d dkr+dS|dd jd}d}x7|r|dtkr|dt|d>O}|d=qMW|r|dtkrt|d}|d=ndSt|tkr|s|rdSd}nm|ddd Dkrt}nt}|sd}n6t|dkrH|j|drH|d}ndS|||fS)a-Get a string which should describe an event sequence. If it is successfully parsed as one, return a tuple containing the state (as an int), the event type (as an index of _types), and the detail - None if none, or a string if there is one. If the parsing is unsuccessful, return None. rr(rr)NrMcSsg|]}t|qSr ) _type_names)r"rOr r r%r&$s z#_parse_sequence..rprrr3r3)rprr) split_modifier_namesr_binder_classesr' _keysym_re _button_rer6match)r,ZwordsZ modifiersr*rlZtype_rer r r%_parse_sequence s0'      % rcCsb|dr:dt|dt|ddd|ddSdt|dt|dddSdS)Nrr(rrrMr))rjr+)r@r r r%_triplet_to_sequence2s 0rcs>tkrtSGfddd}|t<|S)zReturn a MultiCall class which inherits its methods from the given widget class (for example, Tkinter.Text). This is used instead of a templating mechanism. cseZdZeejs$tfddZdddfddZdfddZ fdd Z fd d Z dfd d Z ddZ dS)z#MultiCallCreator..MultiCallcsKj||i_fddtttD_dS)Ncs&g|]}t||qSr )r)r"r:)r1r-r r%r&Ks z@MultiCallCreator..MultiCall.__init__..)r2_MultiCall__eventinfor5r6r+_MultiCall__binders)r1rFkwargs)r-)r1r%r2Es z,MultiCallCreator..MultiCall.__init__Ncs/t|tkrt|dkr|dddkr|dddkr||jkr|j|}|ddk rx4|dD]%}|j|dj||dqWn||d<|ddk rx0|dD]!}|j|dj||qWqq|gg|j|>rr)r*strr6rrrBr>)r1r,r;addZeir@)r-r r%r>Ns$, & %z(MultiCallCreator..MultiCall.bindcst|tkrt|dkr|dddkr|dddkr||jkr|j|\}}|dk rx)|D]!}|j|dj||qWd|j|d>rrr)r*rr6rrrB)r1r,Zfuncidr;tripletsr@)r-r r%rB`s$,  z*MultiCallCreator..MultiCall.unbindcs||jkr%dgg|j|r?)r1virtual sequencesr;rrkr@)r-r r%rks    z-MultiCallCreator..MultiCall.event_addcs||jkrdS|j|\}}xs|D]k}t|}|dkraj|||q-|dk r|j|dj||n|j|q-WdS)Nr)rr event_deleterrBrA)r1rrr;rrkr@)r-r r%r|s    z0MultiCallCreator..MultiCall.event_deletecs]|dks||jkr+j||Sttt|j|dj||SdS)Nr)r event_infotuplemapr)r1r)r-r r%rs  z.MultiCallCreator..MultiCall.event_infocSsx|jD]}|j|\}}|r xt|D]i}y|j|dj||Wq0tjk r}zt|jdkrnWYdd}~Xq0Xq0Wq q WdS)Nrr)rrrBrCrDrErF)r1rr;rr@rGr r r%rHs z+MultiCallCreator..MultiCall.__del__)rIrJrK issubclassrCZMiscAssertionErrorr2r>rBrrrrHr )r-r r% MultiCallBs   r)_multicall_dict)r-rr )r-r%MultiCallCreator:s  [ rcs$tj}|jdttttjd|j\}}}}|jd||dft tj |j dgfdd}|d|d |d |d |d |d |d|d|d|d|d|d|j dS)NzTest MultiCallz[x+]z+%d+%drcsTfdd}jd|d|jd|d|dd7.bindseq..handlerz <>rr)r>r)rkrTr=)text)rkr%bindseqsz_multi_call..bindseqzz z zzzzz zz zz) rCZTktitlerZrintrerZgeometryrZTextZpackZmainloop)parentrootwidthZheightrVyrr )rr% _multi_calls(  3             r__main__)runrrr @rrrr)rrrrrrrrr)rrrrzKeyPressrqz KeyReleasersrtrurvrwrxryrzr{r|r}r~rrrrrrrrrr)rrrrrrrrrrrrrrrrrrrrrrr)B__doc__sysrrCZ MC_KEYPRESSZ MC_KEYRELEASEZMC_BUTTONPRESSZMC_BUTTONRELEASEZ MC_ACTIVATEZ MC_CIRCULATEZ MC_COLORMAPZ MC_CONFIGUREZ MC_DEACTIVATEZ MC_DESTROYZMC_ENTERZ MC_EXPOSEZ MC_FOCUSINZ MC_FOCUSOUTZ MC_GRAVITYZMC_LEAVEZMC_MAPZ MC_MOTIONZ MC_MOUSEWHEELZ MC_PROPERTYZ MC_REPARENTZMC_UNMAPZ MC_VISIBILITYZMC_SHIFTZ MC_CONTROLZMC_ALTZMC_METAZ MC_OPTIONZ MC_COMMANDplatformr!Z_modifier_masksdictr5r6rrEr'rerjr]rgrirOr<r:r?r^r+rrcompilerrrrrrrrIZidlelib.idle_test.htestrr r r r%s     -     `"  '  g