B � f�H�@s&dZddlZddlZddlZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZd ZdZdZdZ ej!dkr�dZ"eeee fZ#ndZ"eeeefZ#e$dd �e%e&e"��D��Z'd!Z(Gd"d#�d#�Z)e%de&e"�>�Z*d$d �e*D�Z+d%d&�Z,e,e*�Z-gZ.xNe*D]FZ/dZ0x0e%e&e"��D] Z1de1>e/@�r6e0e#e1OZ0�q6We.�2e0��q WGd'd(�d(�Z3d)Z4e3fde)fe&e4�dZ5e$d*d �e%e&e4��D��Z6e�7d+�Z8e�7d,�Z9d-d.�Z:d/d0�Z;iZe?d5k�r"dd6l@mAZAeAd7dd8d9�dd: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))�Shift)�Control)ZOption)ZCommand))r)ZAlt)r)ZMeta�McCs"g|]}t|D] }||f�qqS�)� _modifiers)�.0�number�namerr�6/opt/alt/python37/lib64/python3.7/idlelib/multicall.py� 7sr%zapplication has been destroyedc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) � _SimpleBindercCs8||_dt|dd|_||_||_g|_d|_dS)N�)�type�_types�sequence�widget� widgetinst� bindedfuncs� handlerid)�selfr)r,r-rrr$�__init__Js z_SimpleBinder.__init__cCs>|js.|j|jfdd�}|j�|j|j|�|_|j�|�dS)NcSsT||_i}xDtt|�ddd�D],}||}||kr d||<||�}|r |Sq WdS)Nr�����T)�mc_type�range�len)�event�lr3� wascalled�i�func�rrrr$�handlerTsz#_SimpleBinder.bind..handler)r/r.r)r,�bindr-r+�append)r0�tripletr:r<rrr$r=Rs   z_SimpleBinder.bindcCs2|j�|�|js.|j�|j|j|j�d|_dS)N)r.�remover,�unbindr-r+r/)r0r?r:rrr$rAbs z_SimpleBinder.unbindc CsZ|jrVy|j�|j|j|j�Wn4tjk rT}zt|jdkrD�Wdd}~XYnXdS)Nr) r/r,rAr-r+�tkinter�TclError�APPLICATION_GONE�args)r0�errr$�__del__hs z_SimpleBinder.__del__N)�__name__� __module__� __qualname__r1r=rArGrrrr$r&Isr&cs(g|] �d��fdd�tt�D���qS)�c3s*|]"\}}d|>�@r|ddVqdS)rr�-Nr)r!r9�m)�srr$� wsz.)�join� enumerater )r!r)rNr$r%wscsPdd�}g}x>|D]6�tt�fdd�|D���}|j|dd�|�|�qW|S)z�For 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}x|r"t|d�\}}||7}qW|S)znumber of bits set in n base 2rr)�divmod)�nZnbZremrrr$�nbits�s  zexpand_substates..nbitsc3s|]}�|@VqdS)Nr)r!�x)�staterr$rO�sz#expand_substates..T)�key�reverse)�list�set�sortr>)ZstatesrTZ statelistZ substatesr)rVr$�expand_substates|s r\c@s4eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd S) �_ComplexBindercCs||||j|jfdd�}|S)Nc Ss�dg|dd�<||_||_i}d}xZ|D]R}xFtt|�ddd�D].} || } | |krBd|| <|| |�}|rBPqBW|r(Pq(Wg|dd�<x|D] } | �q�Wg|dd�<|r�|SdS)NTrr2)r3�mc_stater4r5) r6�listsr3r^�ishandlerrunning�doafterhandlerr8r;r7r9r:�frrr$r<�s*      z0_ComplexBinder.__create_handler..handler)r`ra)r0r_r3r^r<rrr$Z__create_handler�s z_ComplexBinder.__create_handlerc s�|�_t|d�_|�_|�_ddd�tD�i�_g�_g�_g�_ xhtD]`}�fdd�t |D�}�� ||t |�}dt |�jd}�j�|�j��j||�f�qLWdS)NrcSsg|]}g�qSrr)r!rNrrr$r%�sz+_ComplexBinder.__init__..csg|]}�jd|�qS)N)r.)r!r9)r0rr$r%�sr'r()r)r*�typenamer,r-�_statesr.� handleridsr`ra�_state_subsets�_ComplexBinder__create_handler� _state_codes� _state_namesr>r=)r0r)r,r-rNr_r<�seqr)r0r$r1�s z_ComplexBinder.__init__c s��d�jkr�dd�tD��j�d<xrtD]j���fdd��ddfD�}��|�jt��}dt��j�df}�j�|�j � �j ||�f�q,W���fdd�}�j s�|�n �j �|�dS)NrcSsg|]}g�qSrr)r!rNrrr$r%�sz'_ComplexBinder.bind..cs(g|] }t�D]}�j||�qqSr)rfr.)r!�detailr9)rNr0rr$r%�sz <%s%s-%s>cs�j�d�d���S)Nrr)r.r>r)r:r0r?rr$���z%_ComplexBinder.bind..)r.rdrgr)rhrircrer>r,r=r-r`ra)r0r?r:r_r<rj�doitr)r:rNr0r?r$r=�s    z_ComplexBinder.bindcs.���fdd�}�js|�n �j�|�dS)Ncs�j�d�d���S)Nrr)r.r@r)r:r0r?rr$rl�rmz'_ComplexBinder.unbind..)r`rar>)r0r?r:rnr)r:r0r?r$rA�sz_ComplexBinder.unbindc Csdx^|jD]T\}}y|j�|j||�Wqtjk rZ}zt|jdkrJ�Wdd}~XYqXqWdS)Nr)rer,rAr-rBrCrDrE)r0rj�idrFrrr$rG�s z_ComplexBinder.__del__N)rHrIrJrgr1r=rArGrrrr$r]�s r]))�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] }||f�qqSr)r*)r!r"r#rrr$r%sz^\w+$z^[1-5]$cCs|r|ddks|ddkr dS|dd��d�}d}x.|rd|dtkrd|dt|d>O}|d=q8W|r�|dtkr�t|d}|d=ndSt|tkr�|s�|r�dSd}nN|dd �d D�kr�t}nt}|s�d}n(t|�dkr�|�|d�r�|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(NrrLcSsg|] }t|�qSr)� _type_names)r!rNrrr$r%$sz#_parse_sequence..)rprq) �split�_modifier_namesrr�_binder_classesr&� _keysym_re� _button_rer5�match)r+ZwordsZ modifiersr)rkZtype_rerrr$�_parse_sequence s0    rycCs`|dr8dt|dt|ddd|ddSdt|dt|dddSdS)Nrr'rrrLr()rir*)r?rrr$�_triplet_to_sequence2s0rzcs0�tkrt�SG�fdd�d��}|t�<|S)z�Return a MultiCall class which inherits its methods from the given widget class (for example, Tkinter.Text). This is used instead of a templating mechanism. csbeZdZ�fdd�Zd�fdd� Zd�fdd� Z�fdd �Z�fd d �Zd�fd d � Zdd�Z dS)z#MultiCallCreator..MultiCallcs:�j�f|�|�i�_��fdd�ttt��D��_dS)Ncsg|]}t||����qSr)ru)r!r9)r0r,rr$r%Ksz@MultiCallCreator..MultiCall.__init__..)r1�_MultiCall__eventinfor4r5r*�_MultiCall__binders)r0rE�kwargs)r,)r0r$r1Es z,MultiCallCreator..MultiCall.__init__Ncs�t|�tkr�t|�dkr�|dd�dkr�|dd�dkr�||jkr�|j|}|ddk r�x*|dD]}|j|d�||d�qbW||d<|ddk r�x6|dD]}|j|d�||�q�Wn|gg|j|<��||||�S)Nrz<<�����z>>rr)r)�strr5r{r|rAr=)r0r+r:�addZeir?)r,rr$r=Ns     z(MultiCallCreator..MultiCall.bindcs�t|�tkr�t|�dkr�|dd�dkr�|dd�dkr�||jkr�|j|\}}|dk r�x"|D]}|j|d�||�q^Wd|j|d<��|||�S)Nrz<>rr)r)rr5r{r|rA)r0r+Zfuncidr:�tripletsr?)r,rr$rA`s   z*MultiCallCreator..MultiCall.unbindcs�||jkrdgg|j|<|j|\}}xT|D]L}t|�}|dkrP��|||�q,|dk rn|j|d�||�|�|�q,WdS)Nr)r{ry� event_addr|r=r>)r0�virtual� sequencesr:r�rjr?)r,rr$r�ks  z-MultiCallCreator..MultiCall.event_addcsv||jkrdS|j|\}}xT|D]L}t|�}|dkrF��|||�q"|dk rd|j|d�||�|�|�q"WdS)Nr)r{ry� event_deleter|rAr@)r0r�r�r:r�rjr?)r,rr$r�|s  z0MultiCallCreator..MultiCall.event_deletecsF|dks||jkr��||�Sttt|j|d����||�SdS)Nr)r{� event_info�tuple�maprz)r0r�)r,rr$r��s  z.MultiCallCreator..MultiCall.event_infoc Ss�x~|jD]t}|j|\}}|rx\|D]T}y|j|d�||�Wq$tjk rv}zt|jdkrf�Wdd}~XYq$Xq$WqWdS)Nrr)r{r|rArBrCrDrE)r0r�r:r�r?rFrrr$rG�s  z+MultiCallCreator..MultiCall.__del__)NNN)N)N) rHrIrJr1r=rAr�r�r�rGr)r,rr$� MultiCallBs   r�)�_multicall_dict)r,r�r)r,r$�MultiCallCreator:s [r�cs�t�|�}|�d�tt|���d�dd��\}}|�d||df�ttj�|���� �dgf�fdd� }|d �|d �|d �|d �|d �|d�|d�|d�|d�|d�|d�|d�dS)NzTest MultiCall�+rz+%d+%d�rcsH�fdd�}��d|d|���d|d��|dd7<dS)Ncs t��dS)N)�print)r6)rjrr$r<�sz-_multi_call..bindseq..handlerz <>rr)r=r�)rjrSr<)�text)rjr$�bindseq�s z_multi_call..bindseqzz z zzzzz zz zz) rBZToplevel�titler��intZgeometryrsr�ZTextZpack)�parent�toprU�yr�r)r�r$� _multi_call�s&   r��__main__)�mainzidlelib.idle_test.test_mainmenuF)� verbosity�exit)�run)D�__doc__�re�sysrBZ 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_COMMAND�platformr Z_modifier_masks�dictr4r5rtrDr&rdrir\rfrhrNr;r9r>r]r*rurr�compilervrwryrzr�r�r�rHZunittestr�Zidlelib.idle_test.htestr�rrrr$�s�   - `   'g