ó {fc@s¡ddlmZddlmZddd„ƒYZddd„ƒYZd„Zedkrdd lZej d d d d e ƒddl m Z e eƒnd S(iÿÿÿÿ(tprint_function(tTclErrortWidgetRedirectorcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(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 could be made via tkinter, what we really want to do is to hook the Tk 'insert' operation itself. For one thing, we want a text.insert call in idle code to have the same effect as a key press. 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. We will also intercept method calls on the Tkinter class instance that represents the tk widget. In IDLE, WidgetRedirector is used in Percolator to intercept Text commands. 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. cCsei|_||_|j|_}|j}|d|_|jd||jƒ|j||jƒdS(sÀInitialize attributes and setup redirection. _operations: dict mapping operation name to new function. widget: the widget whose tcl command is to be intercepted. tk: widget.tk, a convenience attribute, probably not needed. orig: new name of the original tcl command. Since renaming to orig fails with TclError when orig already exists, only one WidgetDirector can exist for a given widget. t_origtrenameN(t _operationstwidgetttkt_wtorigtcallt createcommandtdispatch(tselfRRtw((s0/usr/lib64/python2.7/idlelib/WidgetRedirector.pyt__init__s    cCsd|jjj|jjfS(NsWidgetRedirector(%s<%s>)(Rt __class__t__name__R(R ((s0/usr/lib64/python2.7/idlelib/WidgetRedirector.pyt__repr__2scCsux$t|jƒD]}|j|ƒqW|j}|j}|j}|j|ƒ|jd|j|ƒ|`|`dS(sBUnregister operations and revert redirection created by .__init__.RN( tlistRt unregisterRRRt deletecommandR R (R t operationRRR((s0/usr/lib64/python2.7/idlelib/WidgetRedirector.pytclose6s    cCs-||j|st