;
رق"Ic               @   sO   d  d l  TGd   d  Z Gd   d  Z d   Z e d k o e   n d S(	   i    (   u   *c             B   sJ   |  Ee  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   uل  Support for redirecting arbitrary widget subcommands.

    Some Tk operations don't normally pass through Tkinter.  For example, if a
    character is inserted into a Text widget by pressing a key, a default Tk
    binding to the widget's 'insert' operation is activated, and the Tk library
    processes the insert without calling back into Tkinter.

    Although a binding to <Key> could be made via Tkinter, what we really want
    to do is to hook the Tk 'insert' operation itself.

    When a widget is instantiated, a Tcl command is created whose name is the
    same as the pathname widget._w.  This command is used to invoke the various
    widget operations, e.g. insert (for a Text widget). We are going to hook
    this command and provide a facility ('register') to intercept the widget
    operation.

    In IDLE, the function being registered provides access to the top of a
    Percolator chain.  At the bottom of the chain is a call to the original
    Tk widget operation.

    c             C   se   i  |  _  | |  _ | j |  _ } | j } | d |  _ | j d | |  j  | j | |  j  d  S(   Nu   _origu   rename(   u   _operationsu   widgetu   tku   _wu   origu   callu   createcommandu   dispatch(   u   selfu   widgetu   tku   w(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   __init__   s    			c             C   s   d |  j  j j |  j  j f S(   Nu   WidgetRedirector(%s<%s>)(   u   widgetu	   __class__u   __name__u   _w(   u   self(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   __repr__&   s    c             C   s{   x$ t  |  j  D] } |  j |  q W|  j } |  ` |  j } |  ` | j } | j } | j |  | j d | |  d  S(   Nu   rename(	   u   listu   _operationsu
   unregisteru   widgetu   origu   tku   _wu   deletecommandu   call(   u   selfu	   operationu   widgetu   origu   tku   w(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   close*   s     	 	 		c             C   s-   | |  j  | <t |  j | |  t |  |  S(   N(   u   _operationsu   setattru   widgetu   OriginalCommand(   u   selfu	   operationu   function(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   register5   s    c             C   s[   | |  j  k oC |  j  | } |  j  | =t |  j |  o t |  j |  n | Sd  Sd  S(   N(   u   _operationsu   hasattru   widgetu   delattru   None(   u   selfu	   operationu   function(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu
   unregister:   s    
c          	   G   sd   |  j  j |  } y3 | o | |   S|  j j |  j | f |  SWn t k
 o d SYn Xd S(   u  Callback from Tcl which runs when the widget is referenced.

        If an operation has been registered in self._operations, apply the
        associated function to the args passed into Tcl. Otherwise, pass the
        operation through to Tk via the original Tcl function.

        Note that if a registered function is called, the operation is not
        passed through to Tk.  Apply the function returned by self.register()
        to *args to accomplish that.  For an example, see ColorDelegator.py.

        u    N(   u   _operationsu   getu   tku   callu   origu   TclError(   u   selfu	   operationu   argsu   m(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   dispatchD   s    !N(	   u   __name__u
   __module__u   __doc__u   __init__u   __repr__u   closeu   registeru
   unregisteru   dispatch(   u
   __locals__(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   WidgetRedirector   s   
					
u   WidgetRedirectorc             B   s)   |  Ee  Z d    Z d   Z d   Z d S(   c             C   sR   | |  _  | |  _ | j |  _ | j |  _ |  j j |  _ |  j |  j f |  _ d  S(   N(   u   rediru	   operationu   tku   origu   callu   tk_callu   orig_and_operation(   u   selfu   rediru	   operation(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   __init__\   s    		c             C   s   d |  j  |  j f S(   Nu   OriginalCommand(%r, %r)(   u   rediru	   operation(   u   self(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   __repr__d   s    c             G   s   |  j  |  j |  S(   N(   u   tk_callu   orig_and_operation(   u   selfu   args(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   __call__g   s    N(   u   __name__u
   __module__u   __init__u   __repr__u   __call__(   u
   __locals__(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   OriginalCommandZ   s   
		u   OriginalCommandc              C   s   t    }  |  j d |  j  t   } | j   | j   t |  } d   } | j d |  a |  j	   | j
 d  | j   |  j	   |  j   d  S(   Nu   WM_DELETE_WINDOWc              W   s   t  d |   t |    d  S(   Nu   insert(   u   printu   previous_tcl_fcn(   u   args(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu	   my_inserts   s    u   insert(   u   Tku   wm_protocolu   quitu   Textu   packu	   focus_setu   WidgetRedirectoru   registeru   previous_tcl_fcnu   mainloopu
   unregisteru   closeu   destroy(   u   rootu   textu   rediru	   my_insert(    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   maink   s    		

	


u   __main__N(   u   tkinteru   WidgetRedirectoru   OriginalCommandu   mainu   __name__(    (    (    u5   /mit/python/lib/python3.0/idlelib/WidgetRedirector.pyu   <module>   s
   
W	