Hacked By AnonymousFox

Current Path : /opt/alt/python27/lib64/python2.7/idlelib/
Upload File :
Current File : //opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyo

�
^
bc@s�ddlmZddlmZddd��YZddd��YZd�Zedkr�dd	lZej	d
ddd
e
�ddlm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 <Key> 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((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyt__init__s			
cCsd|jjj|jjfS(NsWidgetRedirector(%s<%s>)(Rt	__class__t__name__R(R
((s=/opt/alt/python27/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((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pytclose6s			
cCs-||j|<t|j||�t||�S(s�Return OriginalCommand(operation) after registering function.

        Registration adds an operation: function pair to ._operations.
        It also adds a widget function attribute that masks the Tkinter
        class instance method.  Method masking operates independently
        from command dispatch.

        If a second function is registered for the same operation, the
        first function is replaced in both places.
        (RtsetattrRtOriginalCommand(R
Rtfunction((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pytregisterCs
cCsZ||jkrR|j|}|j|=yt|j|�Wntk
rMnX|SdSdS(s~Return the function for the operation, or None.

        Deleting the instance attribute unmasks the class attribute.
        N(RtdelattrRtAttributeErrortNone(R
RR((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyRRs


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
R	R(R
Rtargstm((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyRbs
!
(	Rt
__module__t__doc__RRRRRR(((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyRs			
		RcBs)eZdZd�Zd�Zd�ZRS(s7Callable for original tk command that has been redirected.

    Returned by .register; can be used in the function registered.
    redir = WidgetRedirector(text)
    def my_insert(*args):
        print("insert", args)
        original_insert(*args)
    original_insert = redir.register("insert", my_insert)
    cCsO||_||_|j|_|j|_|jj|_|j|f|_dS(s�Create .tk_call and .orig_and_operation for .__call__ method.

        .redir and .operation store the input args for __repr__.
        .tk and .orig copy attributes of .redir (probably not needed).
        N(tredirRRR	R
ttk_calltorig_and_operation(R
R%R((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyR�s		cCsd|j|jfS(NsOriginalCommand(%r, %r)(R%R(R
((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyR�scGs|j|j|�S(N(R&R'(R
R!((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyt__call__�s(RR#R$RRR((((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyRxs			cs�ddlm}m}ddl}|�}|jd�ttt|jd|j	����\}}}}|j	d||df�||�}	|	j
�|	j�t|	�}
�fd�}|
j
d|��|j�dS(	Ni����(tTktTextsTest WidgetRedirectors[x+]s+%d+%di�cstd|��|�dS(Ntinsert(tprint(R!(toriginal_insert(s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyt	my_insert�s
R+(tTkinterR)R*trettitleRtmaptinttsplittgeometrytpackt	focus_setRRtmainloop(tparentR)R*R0troottwidththeighttxtyttextR%R.((R-s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyt_widget_redirector�s	
3

t__main__Ns"idlelib.idle_test.test_widgetredirt	verbosityitexit(trun(((
t
__future__RR/RRRR@RtunittesttmaintFalsetidlelib.idle_test.htestRD(((s=/opt/alt/python27/lib64/python2.7/idlelib/WidgetRedirector.pyt<module>st 	


Hacked By AnonymousFox1.0, Coded By AnonymousFox