ó
|Nc           @   s)  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z d Z d Z d Z	 d Z
 d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z dT Z dU Z dV Z  dW Z! dX Z" dY Z# e j$ ƒ  r'dZ d[ d\ d] f Z% e e e" e# f Z& n$ d^ d_ d` da f Z% e e  e e! f Z& e' g  e( e) e% ƒ ƒ D]# Z* e% e* D] Z+ e+ e* f ^ qoqaƒ Z, d" db d# „  ƒ  YZ- e( d e) e% ƒ >ƒ Z. g  e. D]% Z/ d$ j0 d% „  e1 e% ƒ Dƒ ƒ ^ q½Z2 d& „  Z3 e3 e. ƒ Z4 g  Z5 x] e. D]U Z/ d Z6 x9 e( e) e% ƒ ƒ D]% Z7 d e7 >e/ @r)e6 e& e7 OZ6 q)q)We5 j8 e6 ƒ q
Wd' dc d( „  ƒ  YZ9 dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz f Z: e9 f d e- f e) e: ƒ d Z; e' g  e( e) e: ƒ ƒ D]# Z* e: e* D] Z+ e+ e* f ^ qqùƒ Z< e j= dB ƒ Z> e j= dC ƒ Z? dD „  Z@ dE „  ZA i  ZB dF „  ZC eD dG k r%e jE ƒ  ZF eC e jG ƒ eF ƒ ZH eH jI ƒ  d g dH „ ZJ eJ dI ƒ eJ dJ ƒ eJ dK ƒ eJ dL ƒ eJ dM ƒ eJ dN ƒ eJ dO ƒ eJ dP ƒ eJ dQ ƒ eJ dR ƒ eJ dS ƒ eF jK ƒ  n  d S({   s˜  
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.
iÿÿÿÿN(   t   macosxSupporti    i   i   i   i   i   i   i   i   i	   i
   i   i   i   i   i   i   i   i   i   i   i   i   t   Shiftt   Controlt   Optiont   Commandt   Altt   Metat   Mt   _SimpleBinderc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sJ   | |  _  d t | d d |  _ | |  _ | |  _ g  |  _ d  |  _ d  S(   Nt   <i    t   >(   t   typet   _typest   sequencet   widgett
   widgetinstt   bindedfuncst   Nonet	   handlerid(   t   selfR   R   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   __init__F   s    				c         C   sV   |  j  sB |  j |  j d „ } |  j j |  j |  j | ƒ |  _  n  |  j j | ƒ d  S(   Nc         S   ss   | |  _  i  } x] t t | ƒ d d d ƒ D]? } | | } | | k r, t | | <| |  ƒ } | rk | Sq, q, Wd  S(   Ni   iÿÿÿÿ(   t   mc_typet   ranget   lent   True(   t   eventt   lR   t	   wascalledt   it   funct   r(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   handlerP   s    	#

(   R   R   R   R   t   bindR   R   t   append(   R   t   tripletR   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR    N   s
    	
c         C   sH   |  j  j | ƒ |  j  sD |  j j |  j |  j |  j ƒ d  |  _ n  d  S(   N(   R   t   removeR   t   unbindR   R   R   R   (   R   R"   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR$   ^   s    	c         C   s/   |  j  r+ |  j j |  j |  j |  j  ƒ n  d  S(   N(   R   R   R$   R   R   (   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   __del__d   s    	(   t   __name__t
   __module__R   R    R$   R%   (    (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR   E   s   			t    c         c   s1   |  ]' \ } } d  | >t  @r | d d Vq d S(   i   i    t   -N(   t   s(   t   .0R   t   m(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pys	   <genexpr>n   s   	c            si   d „  } g  } xS |  D]K ‰  t  t ‡  f d †  |  Dƒ ƒ ƒ } | j d | d t ƒ | j | ƒ q W| S(   s•   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.
    c         S   s6   d } x) |  r1 t  |  d ƒ \ }  } | | 7} q	 W| S(   s   number of bits set in n base 2i    i   (   t   divmod(   t   nt   nbt   rem(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   nbitsw   s
    	c         3   s   |  ] } ˆ  | @Vq d  S(   N(    (   R+   t   x(   t   state(    s&   C:\RCS\Python\lib\idlelib\MultiCall.pys	   <genexpr>€   s    t   keyt   reverse(   t   listt   sett   sortR   R!   (   t   statesR1   t	   statelistt	   substates(    (   R3   s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   expand_substatess   s    	"t   _ComplexBinderc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s"   | | | |  j  |  j d „ } | S(   Nc         S   sÖ   t  g | (| |  _ | |  _ i  } d  } x| | D]t } xa t t | ƒ d d d ƒ D]C }	 | |	 }
 |
 | k rR t  | |
 <| |	 |  ƒ } | r• Pq• qR qR W| r/ Pq/ q/ Wg  | (x | rÇ | j ƒ  ƒ  q± W| rÒ | Sd  S(   Ni   iÿÿÿÿ(   R   R   t   mc_stateR   R   R   t   pop(   R   t   listsR   R>   t   ishandlerrunningt   doafterhandlerR   R   R   R   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR   ™   s(    
		#

	(   RA   RB   (   R   R@   R   R>   R   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   __create_handler˜   s
    c   	      C   s  | |  _  t | d |  _ | |  _ | |  _ i g  t D] } g  ^ q6 d  6|  _ g  |  _ g  |  _	 g  |  _
 x“ t D]‹ } g  t | D] } |  j d  | ^ q‚ } |  j | | t | ƒ } d t | |  j d } |  j j | |  j j |  j | | ƒ f ƒ qq Wd  S(   Ni    R	   R
   (   R   R   t   typenameR   R   t   _statesR   R   t
   handleridsRA   RB   t   _state_subsetst   _ComplexBinder__create_handlert   _state_codest   _state_namesR!   R    (	   R   R   R   R   R*   R   R@   R   t   seq(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR   ´   s    			#			(c   
         s+  ˆ  d ˆ j  k rï g  t D] } g  ^ q ˆ j  ˆ  d <xµ t D]ª } g  ˆ  d d  f D]( } t | D] } ˆ j  | | ^ qc qU } ˆ j | ˆ j t | ƒ } d t | ˆ j ˆ  d f } ˆ j	 j
 | ˆ j j ˆ j | | ƒ f ƒ q> Wn  ‡ ‡  ‡ f d †  }	 ˆ j s|	 ƒ  n ˆ j j
 |	 ƒ d  S(   Ni   s	   <%s%s-%s>c              s    ˆ  j  ˆ d ˆ d j ˆ ƒ S(   Ni   i    (   R   R!   (    (   R   R"   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   <lambda>×   s    (   R   RE   R   RG   RH   R   RI   RJ   RD   RF   R!   R   R    R   RA   RB   (
   R   R"   R   R*   t   detailR   R@   R   RK   t   doit(    (   R"   R   R   s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR    Ë   s    $(	
c            s<   ‡  ‡ ‡ f d †  } ˆ  j  s( | ƒ  n ˆ  j j | ƒ d  S(   Nc              s    ˆ  j  ˆ d ˆ d j ˆ ƒ S(   Ni   i    (   R   R#   (    (   R   R"   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyRL   Þ   s    (   RA   RB   R!   (   R   R"   R   RN   (    (   R   R"   R   s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR$   Ý   s    	
c         C   s7   x0 |  j  D]% \ } } |  j j |  j | | ƒ q
 Wd  S(   N(   RF   R   R$   R   (   R   RK   t   id(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR%   ä   s    (   R&   R'   RH   R   R    R$   R%   (    (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR=      s
   				t   KeyPresst   Keyt
   KeyReleaset   ButtonPresst   Buttont   ButtonReleaset   Activatet	   Circulatet   Colormapt	   Configuret
   Deactivatet   Destroyt   Entert   Exposet   FocusInt   FocusOutt   Gravityt   Leavet   Mapt   Motiont
   MouseWheelt   Propertyt   Reparentt   Unmapt
   Visibilitys   ^\w+$s   ^[1-5]$c      	   C   sc  |  s' |  d d k s' |  d d k r+ d	 St j |  d d !d ƒ } d } x7 | rƒ | d t k rƒ | d t | d >O} | d =qM W| r² | d t k r² t | d } | d =n d	 St | t k rß | sÒ | rÖ d	 Sd	 } nw | g  d
 D] } t | ^ qé k rt } n t } | s d	 } n6 t	 | ƒ d k rR| j
 | d ƒ rR| d } n d	 S| | | f S(   s-  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.
    i    R	   iÿÿÿÿR
   i   R)   RP   RR   N(   RP   RR   (   R   t   stringt   splitt   _modifier_namest   _type_namest   _binder_classesR   t
   _keysym_ret
   _button_reR   t   match(   R   t   wordst	   modifiersR   RM   R*   t   type_re(    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   _parse_sequenceý   s0    '
	#		%c         C   sb   |  d r: d t  |  d t |  d d d |  d d Sd t  |  d t |  d d d Sd  S(   Ni   R	   i    i   R)   R
   (   RJ   R   (   R"   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   _triplet_to_sequence'  s    
0c            s>   ˆ  t  k r t  ˆ  Sd ˆ  f ‡  f d †  ƒ  Y} | t  ˆ  <| S(   s©   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.
    t	   MultiCallc              s’   e  Z e ˆ  e j ƒ s t ‚ ‡  f d  †  Z d d d ‡  f d † Z d ‡  f d † Z	 ‡  f d †  Z
 ‡  f d †  Z d ‡  f d † Z d „  Z RS(   c            sX   ˆ  j  |  | | Ž i  |  _ g  t t t ƒ ƒ D] } t | | ˆ  |  ƒ ^ q/ |  _ d  S(   N(   R   t   _MultiCall__eventinfoR   R   R   Rm   t   _MultiCall__binders(   R   t   argst   kwargsR   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR   :  s    	c            s#  t  | ƒ t k rt | ƒ d k r| d  d k r| d d k r| |  j k r÷ |  j | } | d d  k	 r§ x4 | d D]% } |  j | d j | | d ƒ q{ Wn  | | d <| d d  k	 r
x0 | d D]! } |  j | d j | | ƒ qÌ Wq
q| g  g |  j | <n  ˆ  j |  | | | ƒ S(   Ni   s   <<iþÿÿÿs   >>i    i   (   R   t   strR   Rw   R   Rx   R$   R    (   R   R   R   t   addt   eiR"   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR    C  s    $ &
%c            sÈ   t  | ƒ t k rµ t | ƒ d k rµ | d  d k rµ | d d k rµ | |  j k rµ |  j | \ } } | d  k	 rµ x) | D]! } |  j | d j | | ƒ qy Wd  |  j | d <qµ n  ˆ  j |  | | ƒ S(   Ni   s   <<iþÿÿÿs   >>i   i    (   R   R{   R   Rw   R   Rx   R$   (   R   R   t   funcidR   t   tripletsR"   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR$   T  s    $ c            s²   | |  j  k r% d  g  g |  j  | <n  |  j  | \ } } xs | D]k } t | ƒ } | d  k rs ˆ  j |  | | ƒ q? | d  k	 r |  j | d j | | ƒ n  | j | ƒ q? Wd  S(   Ni   (   Rw   R   Rt   t	   event_addRx   R    R!   (   R   t   virtualt	   sequencesR   R   RK   R"   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR€   _  s    c            s    | |  j  k r d  S|  j  | \ } } xs | D]k } t | ƒ } | d  k ra ˆ  j |  | | ƒ q- | d  k	 r‹ |  j | d j | | ƒ n  | j | ƒ q- Wd  S(   Ni   (   Rw   Rt   R   t   event_deleteRx   R$   R#   (   R   R   R‚   R   R   RK   R"   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyRƒ   o  s    c            s]   | d  k s | |  j k r+ ˆ  j |  | ƒ St t t |  j | d ƒ ƒ ˆ  j |  | ƒ Sd  S(   Ni   (   R   Rw   t
   event_infot   tuplet   mapRu   (   R   R   (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR„   }  s
    	c         S   s`   xY |  j  D]N } |  j  | \ } } | r
 x, | D]! } |  j | d j | | ƒ q0 Wq
 q
 Wd  S(   Ni   (   Rw   Rx   R$   (   R   R   R   R   R"   (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR%   …  s
    N(   R&   R'   t
   issubclasst   Tkintert   Misct   AssertionErrorR   R   R    R$   R€   Rƒ   R„   R%   (    (   R   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyRv   7  s   	(   t   _multicall_dict(   R   Rv   (    (   R   s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   MultiCallCreator/  s
    V
t   __main__c            sS   ‡  f d †  } t  j d | d | ƒ t  j d | d ˆ  ƒ | d c d 7<d  S(   Nc            s	   ˆ  GHd  S(   N(    (   R   (   RK   (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyR   –  s    s   <<handler%d>>i    i   (   t   textR    R€   (   RK   R.   R   (    (   RK   s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   bindseq•  s    s   <Key>s   <Control-Key>s   <Alt-Key-a>s   <Control-Key-a>s   <Alt-Control-Key-a>s   <Key-b>s   <Control-Button-1>s   <Alt-Button-1>s
   <FocusOut>s   <Enter>s   <Leave>i   i   i   i    i@   i€   (   R   (   R   (   R   (   R   (   R   (   R   (   R   (   R   R   (    (    (   s   KeyPressRQ   (   s
   KeyRelease(   RS   s   Button(   RU   (   RV   (   RW   (   RX   (   RY   (   RZ   (   R[   (   R\   (   R]   (   R^   (   R_   (   R`   (   Ra   (   Rb   (   Rc   (   Rd   (   Re   (   Rf   (   Rg   (   Rh   (L   t   __doc__t   sysRi   t   reRˆ   t   idlelibR    t   MC_KEYPRESSt   MC_KEYRELEASEt   MC_BUTTONPRESSt   MC_BUTTONRELEASEt   MC_ACTIVATEt   MC_CIRCULATEt   MC_COLORMAPt   MC_CONFIGUREt   MC_DEACTIVATEt
   MC_DESTROYt   MC_ENTERt	   MC_EXPOSEt
   MC_FOCUSINt   MC_FOCUSOUTt
   MC_GRAVITYt   MC_LEAVEt   MC_MAPt	   MC_MOTIONt   MC_MOUSEWHEELt   MC_PROPERTYt   MC_REPARENTt   MC_UNMAPt   MC_VISIBILITYt   MC_SHIFTt
   MC_CONTROLt   MC_ALTt   MC_METAt	   MC_OPTIONt
   MC_COMMANDt   runningAsOSXAppt
   _modifierst   _modifier_maskst   dictR   R   t   numbert   nameRk   R   RE   R*   t   joint	   enumerateRJ   R<   RG   RI   R   R   R!   R=   R   Rm   Rl   t   compileRn   Ro   Rt   Ru   R‹   RŒ   R&   t   Tkt   roott   TextRŽ   t   packR   t   mainloop(    (    (    s&   C:\RCS\Python\lib\idlelib\MultiCall.pyt   <module>   s²                         &
(/	[		"&	*		a











