a XC?hH@sdZddlZddlZddlZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZd ZdZdZdZ ej!dkrdZ"eeee fZ#ndZ"eeeefZ#e$dd 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.e*D]BZ/dZ0e%e&e"D] Z1de1>e/@r2e0e#e1OZ0q2e.2e0qGd'd(d(Z3d)Z4e3fde)fe&e4dZ5e$d*d e%e&e4DZ6e7d+Z8e7d,Z9d-d.Z:d/d0Z;iZe?d5krdd6l@mAZAeAd7dd8d9dd:lBmCZCeCe>dS);a 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  @darwin)ZShiftZControl)ZOption)ZCommand)r)ZAltr)ZMetaMcCs"g|]}t|D] }||fqqS) _modifiers.0Znumbernamerr6/opt/alt/python39/lib64/python3.9/idlelib/multicall.py 7s r%zapplication has been destroyedc@s,eZdZddZddZddZddZd S) _SimpleBindercCs8||_dt|dd|_||_||_g|_d|_dS)N)type_typessequencewidget widgetinst bindedfuncs handlerid)selfr)r,r-rrr$__init__Js z_SimpleBinder.__init__cCs>|js.|j|jfdd}|j|j|j||_|j|dS)NcSsT||_i}tt|dddD]0}||}||vrd||<||}|r|SqdS)NrT)mc_typerangelen)eventlr3 wascalledifuncrrrr$handlerTsz#_SimpleBinder.bind..handler)r/r.r)r,bindr-r+append)r0tripletr:r<rrr$r=Rs  z_SimpleBinder.bindcCs2|j||js.|j|j|j|jd|_dSN)r.remover,unbindr-r+r/)r0r?r:rrr$rBbs z_SimpleBinder.unbindc Cs\|jrXz|j|j|j|jWn6tjyV}zt|jdvrBWYd}~n d}~00dSNr) r/r,rBr-r+tkinterTclErrorAPPLICATION_GONEargs)r0errr$__del__hsz_SimpleBinder.__del__N)__name__ __module__ __qualname__r1r=rBrIrrrr$r&Isr&cs(g|] dfddttDqS)c3s*|]"\}}d|>@r|ddVqdS)rr-Nr)r"r9msrr$ ws z.)join enumerater )r"rrPr$r%wscsLdd}g}|D]6ttfdd|D}|j|dd||q|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. cSs$d}|r t|d\}}||7}q|S)znumber of bits set in n base 2rr)divmod)nZnbZremrrr$nbitss  zexpand_substates..nbitsc3s|]}|@VqdSr@r)r"xstaterr$rRz#expand_substates..T)keyreverse)listsetsortr>)ZstatesrWZ statelistZ substatesrrYr$expand_substates|s rac@s4eZdZddZddZddZddZd d Zd S) _ComplexBindercCs||||j|jfdd}|S)Nc Ssdg|dd<||_||_i}d}|D]R}tt|dddD]0} || } | |vr>d|| <|| |}|r>qpq>|r&qzq&g|dd<|D] } | qg|dd<|r|SdS)NTrr2)r3mc_stater4r5) r6listsr3rcishandlerrunningdoafterhandlerr8r;r7r9r:frrr$r<s*   z0_ComplexBinder.__create_handler..handler)rerf)r0rdr3rcr<rrr$Z__create_handlers  z_ComplexBinder.__create_handlerc s|_t|d_|_|_dddtDi_g_g_g_ tD]`}fddt |D} ||t |}dt |jd}j|jj||fqJdS)NrcSsg|]}gqSrrr"rQrrr$r%r[z+_ComplexBinder.__init__..csg|]}jd|qSr@)r.r"r9r0rr$r%r[r'r()r)r*typenamer,r-_statesr. handleridsrerf_state_subsets_ComplexBinder__create_handler _state_codes _state_namesr>r=)r0r)r,r-rQrdr<seqrrjr$r1sz_ComplexBinder.__init__c sdjvrddtDjd<tD]jfddddfD}|jt}dtjdf}j|j j ||fq*fdd}j s|n j |dS)NrcSsg|]}gqSrrrhrrr$r%r[z'_ComplexBinder.bind..cs(g|] }tD]}j||qqSr)rnr.)r"detailr9)rQr0rr$r%s z <%s%s-%s>csjddSNrr)r.r>rr:r0r?rr$r[z%_ComplexBinder.bind..)r.rlror)rprqrkrmr>r,r=r-rerf)r0r?r:rdr<rrdoitr)r:rQr0r?r$r=s"    z_ComplexBinder.bindcs.fdd}js|n j|dS)NcsjddSrt)r.rArrurr$rvr[z'_ComplexBinder.unbind..)rerfr>)r0r?r:rwrrur$rBsz_ComplexBinder.unbindc Csb|jD]V\}}z|j|j||WqtjyZ}zt|jdvrFWYd}~qd}~00qdSrC)rmr,rBr-rDrErFrG)r0rridrHrrr$rIs z_ComplexBinder.__del__N)rJrKrLror1r=rBrIrrrr$rbs rb))KeyPressZKey) KeyRelease)Z ButtonPressZButton)Z ButtonRelease)ZActivate)Z Circulate)ZColormap)Z Configure)Z Deactivate)ZDestroy)ZEnter)ZExpose)ZFocusIn)ZFocusOut)ZGravity)ZLeave)ZMap)ZMotion)Z MouseWheel)ZProperty)ZReparent)ZUnmap)Z VisibilitycCs"g|]}t|D] }||fqqSr)r*r!rrr$r%s z^\w+$z^[1-5]$cCs|r|ddks|ddkr dS|ddd}d}|rb|dtvrb|dt|d>O}|d=q6|r|dtvrt|d}|d=ndSt|tur|s|rdSd}nN|dd d Dvrt}nt}|sd}n(t|dkr||dr|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'r2r(NrrNcSsg|] }t|qSr) _type_namesrhrrr$r%$r[z#_parse_sequence..)ryrz) split_modifier_namesr{_binder_classesr& _keysym_re _button_rer5match)r+ZwordsZ modifiersr)rsZtype_rerrr$_parse_sequence s0   rcCs`|dr8dt|dt|ddd|ddSdt|dt|dddSdS)Nrr'rrrNr()rqr*)r?rrr$_triplet_to_sequence2s"rcs0tvrtSGfddd}|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. csreZdZeejsJfddZdfdd Zdfdd Zfdd Z fd d Z dfd d Z ddZ dS)z#MultiCallCreator..MultiCallcs@jg|Ri|i_fddtttD_dS)Ncsg|]}t||qSr)r~ri)r0r,rr$r%Ksz@MultiCallCreator..MultiCall.__init__..)r1_MultiCall__eventinfor4r5r*_MultiCall__binders)r0rGkwargsr,rjr$r1Es   z,MultiCallCreator..MultiCall.__init__Ncst|turt|dkr|dddkr|dddkr||jvr|j|}|ddur|dD]}|j|d||dq`||d<|ddur|dD]}|j|d||qn|gg|j|<||||S)Nr<<>>rr)r)strr5rrrBr=)r0r+r:addZeir?rrr$r=Ns       z(MultiCallCreator..MultiCall.bindcst|turt|dkr|dddkr|dddkr||jvr|j|\}}|dur|D]}|j|d||q\d|j|d<|||S)Nrrrrrr)r)rr5rrrB)r0r+Zfuncidr:tripletsr?rrr$rB`sz*MultiCallCreator..MultiCall.unbindcs|||jvrdgg|j|<|j|\}}|D]L}t|}|durN|||q*|durl|j|d||||q*dSNr)rr event_addrr=r>r0virtual sequencesr:rrrr?rrr$rks z-MultiCallCreator..MultiCall.event_addcsr||jvrdS|j|\}}|D]L}t|}|durD|||q |durb|j|d||||q dSr)rr event_deleterrBrArrrr$r|s z0MultiCallCreator..MultiCall.event_deletecsF|dus||jvr||Sttt|j|d||SdSr)r event_infotuplemapr)r0rrrr$rs   z.MultiCallCreator..MultiCall.event_infoc Ss~|jD]r}|j|\}}|r|D]V}z|j|d||Wq tjyt}zt|jdvr`WYd}~q d}~00q qdS)Nrr)rrrBrDrErFrG)r0rr:rr?rHrrr$rIs z+MultiCallCreator..MultiCall.__del__)NNN)N)N) rJrKrL issubclassrDZMiscr1r=rBrrrrIrrrr$ MultiCallBs   r)_multicall_dict)r,rrrr$MultiCallCreator:s [rcst|}|dtt|ddd\}}|d||dfttj| dgffdd }|d |d |d |d |d |d|d|d|d|d|d|ddS)NzTest MultiCall+rz+%d+%drcsHfdd}d|d|d|d|dd7<dS)Ncs tdSr@)print)r6rrrr$r<sz-_multi_call..bindseq..handlerz <>rr)r=r)rrrVr<textrr$bindseqs z_multi_call..bindseqzz z zzzzz zz zz) rDZTopleveltitlerintZgeometryr|rTextZpack)parenttoprXyrrrr$ _multi_calls&   r__main__)mainzidlelib.idle_test.test_mainmenuF) verbosityexit)run)D__doc__resysrDZ 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_masksdictr4r5r}rFr&rlrqrarnrprQr;r9r>rbr*r~r{compilerrrrrrrrJZunittestrZidlelib.idle_test.htestrrrrr$sf    -_    'g