�`^c@sfddlTdd
d��YZddd��YZd�ZedkrbddlmZee�nd S(i�(t*tWidgetRedirectorcBsDeZdZd�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 <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.
cCsei|_||_|j|_}|j}|d|_|jd||j�|j||j�dS(Nt_origtrename(t_operationstwidgetttkt_wtorigtcallt
createcommandtdispatch(tselfRRtw((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt__init__s
cCsd|jjj|jjfS(NsWidgetRedirector(%s<%s>)(Rt __class__t__name__R(R((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt__repr__&scCs{x$t|j�D]}|j|�qW|j}|`|j}|`|j}|j}|j|�|jd||�dS(NR( tlistRt
unregisterRRRRt
deletecommandR (Rt operationRRRR
((s./sys/lib/python2.7/idlelib/WidgetRedirector.pytclose*s
cCs-||j|<t|j||�t||�S(N(RtsetattrRtOriginalCommand(RRtfunction((s./sys/lib/python2.7/idlelib/WidgetRedirector.pytregister5s
cCsW||jkrO|j|}|j|=t|j|�rKt|j|�n|SdSdS(N(RthasattrRtdelattrtNone(RRR((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyR:s
cGs\|jj|�}y1|r%||�S|jj|j|f|�SWntk
rWdSXdS(sCallback 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.
tN(RtgetRR RtTclError(RRtargstm((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyRDs
!
( Rt
__module__t__doc__RRRRRR(((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyRs
RcBs#eZd�Zd�Zd�ZRS(cCsR||_||_|j|_|j|_|jj|_|j|jf|_dS(N(tredirRRRR ttk_calltorig_and_operation(RR%R((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyR\s cCsd|j|jfS(NsOriginalCommand(%r, %r)(R%R(R((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyRdscGs|j|j|�S(N(R&R'(RR!((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt__call__gs(RR#RRR((((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyRZs c Cs�t�}|jd�ttttjd|j����\}}}}|jd||df�t|�}|j �|j
�t|�}d�}|jd|�a
|j�dS(NsTest WidgetRedirectors[x+]s+%d+%di�cWsdG|GHt|�dS(Ntinsert(tprevious_tcl_fcn(R!((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt my_insertus R)(tTkttitleRtmaptinttretsplittgeometrytTexttpackt focus_setRRR*tmainloop( tparenttroottwidththeighttxtyttextR%R+((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt_widget_redirectorks
3
t__main__(trunN(((tTkinterRRR>Rtidlelib.idle_test.htestR@(((s./sys/lib/python2.7/idlelib/WidgetRedirector.pyt<module>s
W
|