class_docstr: 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.
class_docstr_tok: ["Support","for","redirecting","arbitrary","widget","subcommands",".","Some","Tk","operations","do","n'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","."]
docstr: 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 colorizer.py.
docstr_tok: ["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","colorizer.py","."]
code: def dispatch(self, operation, *args):
      """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 colorizer.py.
  
      """
      m = self._operations.get(operation)
      try:
          if m:
              return m(*args)
          else:
              return self.tk.call((self.orig, operation) + args)
      except TclError:
          return ""
  
file_path: cpython/Lib/idlelib/redirector.py
imports: from tkinter import TclError
label_desc: Use image node_id 6 for calling the WidgetRedirector obj's underlying member method code with example usage: obj.dispatch(operation) and returns: m, self, str