Ñò
—à"Ic           @   sU   d  d k  Td d	 d „  ƒ  YZ d d
 d „  ƒ  YZ d „  Z e d j o e ƒ  n d S(   iÿÿÿÿ(   t   *t   WidgetRedirectorc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sä  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   h  |  _  | |  _ | i |  _ } | i } | d |  _ | i d | |  i ƒ | i | |  i ƒ d  S(   Nt   _origt   rename(   t   _operationst   widgett   tkt   _wt   origt   callt   createcommandt   dispatch(   t   selfR   R   t   w(    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   __init__   s    			c         C   s   d |  i  i i |  i  i f S(   Ns   WidgetRedirector(%s<%s>)(   R   t	   __class__t   __name__R   (   R   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   __repr__&   s    c         C   s{   x$ t  |  i ƒ D] } |  i | ƒ q W|  i } |  ` |  i } |  ` | i } | i } | i | ƒ | i d | | ƒ d  S(   NR   (	   t   listR   t
   unregisterR   R   R   R   t   deletecommandR	   (   R   t	   operationR   R   R   R   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   close*   s     	 	 		c         C   s-   | |  i  | <t |  i | | ƒ t |  | ƒ S(   N(   R   t   setattrR   t   OriginalCommand(   R   R   t   function(    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   register5   s    c         C   s[   | |  i  j oC |  i  | } |  i  | =t |  i | ƒ o t |  i | ƒ n | Sd  Sd  S(   N(   R   t   hasattrR   t   delattrt   None(   R   R   R   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR   :   s    
c         G   s`   |  i  i | ƒ } y3 | o | | Œ  S|  i i |  i | f | ƒ SWn t j
 o d SXd S(   s  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.

        t    N(   R   t   getR   R	   R   t   TclError(   R   R   t   argst   m(    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR   D   s    !(	   R   t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR      s   					
R   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   sR   | |  _  | |  _ | i |  _ | i |  _ |  i i |  _ |  i |  i f |  _ d  S(   N(   t   redirR   R   R   R	   t   tk_callt   orig_and_operation(   R   R%   R   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR   \   s    		c         C   s   d |  i  |  i f S(   Ns   OriginalCommand(%r, %r)(   R%   R   (   R   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR   d   s    c         G   s   |  i  |  i | ƒ S(   N(   R&   R'   (   R   R!   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   __call__g   s    (   R   R#   R   R   R(   (    (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyR   Z   s   		c          C   s™   t  ƒ  }  |  i d |  i ƒ t ƒ  } | i ƒ  | i ƒ  t | ƒ } d „  } | i d | ƒ a |  i	 ƒ  | i
 d ƒ | i ƒ  |  i	 ƒ  |  i ƒ  d  S(   Nt   WM_DELETE_WINDOWc          W   s   d G|  GHt  |  Œ  d  S(   Nt   insert(   t   previous_tcl_fcn(   R!   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt	   my_inserts   s    	R*   (   t   Tkt   wm_protocolt   quitt   Textt   packt	   focus_setR   R   R+   t   mainloopR   R   t   destroy(   t   roott   textR%   R,   (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   maink   s    		

	


t   __main__N(    (    (   t   TkinterR   R   R7   R   (    (    (    s5   /mit/python/lib/python2.6/idlelib/WidgetRedirector.pyt   <module>   s
   
W	