[Idle-dev] CVS: idle CallTips.py,1.6,1.7 PyShell.py,1.28,1.29 rpc.py,1.7,1.8 run.py,1.7,1.8

Kurt B. Kaiser kbk@users.sourceforge.net
Thu, 10 Oct 2002 01:25:26 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv19190

Modified Files:
	CallTips.py PyShell.py rpc.py run.py 
Log Message:
M CallTips.py      Add support for getting calltip from subprocess,
                   refactor a bit and clean up.

M PyShell.py       Cosmetic changes, delete blank lines, add # on some
                   blank lines.

M rpc.py           Add more debugging capability

M run.py           Add support for getting calltip from subprocess
                   Move import statements



Index: CallTips.py
===================================================================
RCS file: /cvsroot/idlefork/idle/CallTips.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** CallTips.py	15 Sep 2002 22:02:58 -0000	1.6
--- CallTips.py	10 Oct 2002 08:25:24 -0000	1.7
***************
*** 1,8 ****
! # CallTips.py - An IDLE extension that provides "Call Tips" - ie, a floating window that
! # displays parameter information as you open parens.
  
  import string
  import types
  
  class CallTips:
  
--- 1,18 ----
! """CallTips.py - An IDLE Extension to Jog Your Memory
  
+ Call Tips are floating windows which display function/method parameter
+ information as you open the parameter parenthesis, and which disappear when you
+ type the closing parenthesis.  Future plans include extending the functionality
+ to include class attributes.
+ 
+ """
+ import sys
  import string
  import types
  
+ import CallTipWindow
+ 
+ import __main__
+ 
  class CallTips:
  
***************
*** 10,29 ****
      ]
  
!     def __init__(self, editwin):
          self.editwin = editwin
          self.text = editwin.text
          self.calltip = None
!         if hasattr(self.text, "make_calltip_window"):
!             self._make_calltip_window = self.text.make_calltip_window
!         else:
!             self._make_calltip_window = self._make_tk_calltip_window
  
      def close(self):
          self._make_calltip_window = None
  
-     # Makes a Tk based calltip window.  Used by IDLE, but not Pythonwin.
-     # See __init__ above for how this is used.
      def _make_tk_calltip_window(self):
!         import CallTipWindow
          return CallTipWindow.CallTip(self.text)
  
--- 20,37 ----
      ]
  
!     def __init__(self, editwin=None):
!         if editwin == None:  # subprocess and test
!             self.editwin = None
!             return
          self.editwin = editwin
          self.text = editwin.text
          self.calltip = None
!         self._make_calltip_window = self._make_tk_calltip_window
  
      def close(self):
          self._make_calltip_window = None
  
      def _make_tk_calltip_window(self):
!         # See __init__ for usage
          return CallTipWindow.CallTip(self.text)
  
***************
*** 35,39 ****
      def paren_open_event(self, event):
          self._remove_calltip_window()
!         arg_text = get_arg_text(self.get_object_at_cursor())
          if arg_text:
              self.calltip_start = self.text.index("insert")
--- 43,48 ----
      def paren_open_event(self, event):
          self._remove_calltip_window()
!         name = self.get_name_at_cursor()
!         arg_text = self.fetch_tip(name)
          if arg_text:
              self.calltip_start = self.text.index("insert")
***************
*** 54,58 ****
              # (Later need to be smarter about multi-line, etc)
              if self.text.compare("insert", "<=", self.calltip_start) or \
!                self.text.compare("insert", ">", self.calltip_start + " lineend"):
                  self._remove_calltip_window()
          return "" #so the event is handled normally.
--- 63,68 ----
              # (Later need to be smarter about multi-line, etc)
              if self.text.compare("insert", "<=", self.calltip_start) or \
!                self.text.compare("insert", ">", self.calltip_start
!                                  + " lineend"):
                  self._remove_calltip_window()
          return "" #so the event is handled normally.
***************
*** 62,88 ****
          return "" #so the event is handled normally.
  
!     def get_object_at_cursor(self,
!                 wordchars="._" + string.ascii_letters + string.digits):
!         # Usage of ascii_letters is necessary to avoid UnicodeErrors
!         # if chars contains non-ASCII.
! 
!         # XXX - This needs to be moved to a better place
!         # so the "." attribute lookup code can also use it.
!         text = self.text
!         chars = text.get("insert linestart", "insert")
!         i = len(chars)
!         while i and chars[i-1] in wordchars:
!             i = i-1
!         word = chars[i:]
!         if word:
!             # How is this for a hack!
!             import sys, __main__
              namespace = sys.modules.copy()
              namespace.update(__main__.__dict__)
              try:
!                 return eval(word, namespace)
              except:
!                 pass
!         return None # Can't find an object.
  
  def _find_constructor(class_ob):
--- 72,103 ----
          return "" #so the event is handled normally.
  
!     __IDCHARS = "._" + string.ascii_letters + string.digits
! 
!     def get_name_at_cursor(self):
!         idchars = self.__IDCHARS
!         str = self.text.get("insert linestart", "insert")
!         i = len(str)
!         while i and str[i-1] in idchars:
!             i -= 1
!         return str[i:]
!         
!     def fetch_tip(self, name):
!         interp = self.editwin and self.editwin.flist.pyshell.interp
!         rpcclt = interp and interp.rpcclt
!         if rpcclt:
!             return rpcclt.remotecall("exec", "get_the_calltip",
!                                      (name,), {})
!         else:
!             entity = self.get_entity(name)
!             return get_arg_text(entity)
! 
!     def get_entity(self, name):
!         if name:
              namespace = sys.modules.copy()
              namespace.update(__main__.__dict__)
              try:
!                 return eval(name, namespace)
              except:
!                 return None
  
  def _find_constructor(class_ob):
***************
*** 143,147 ****
                  argText += "\n"
              argText += doc[:pos]
- 
      return argText
  
--- 158,161 ----
***************
*** 169,184 ****
          def t6(self, a, b=None, *args, **kw): "(a, b=None, ..., ***)"
  
!     def test( tests ):
          failed=[]
          for t in tests:
              expected = t.__doc__ + "\n" + t.__doc__
!             if get_arg_text(t) != expected:
                  failed.append(t)
!                 print "%s - expected %s, but got %s" % (t, `expected`, `get_arg_text(t)`)
          print "%d of %d tests failed" % (len(failed), len(tests))
  
      tc = TC()
!     tests = t1, t2, t3, t4, t5, t6, \
!             TC, tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6
  
      test(tests)
--- 183,202 ----
          def t6(self, a, b=None, *args, **kw): "(a, b=None, ..., ***)"
  
!     def test(tests):
!         ct = CallTips()
          failed=[]
          for t in tests:
              expected = t.__doc__ + "\n" + t.__doc__
!             name = t.__name__
!             arg_text = ct.fetch_tip(name)
!             if arg_text != expected:
                  failed.append(t)
!                 print "%s - expected %s, but got %s" % (t, expected,
!                                                         get_arg_text(entity))
          print "%d of %d tests failed" % (len(failed), len(tests))
  
      tc = TC()
!     tests = (t1, t2, t3, t4, t5, t6, 
!              TC, tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6)
  
      test(tests)

Index: PyShell.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyShell.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -r1.28 -r1.29
*** PyShell.py	29 Sep 2002 00:34:10 -0000	1.28
--- PyShell.py	10 Oct 2002 08:25:24 -0000	1.29
***************
*** 415,419 ****
              display_executing_dialog()
              return
-         #
          self.checklinecache()
          if self.save_warnings_filters is not None:
--- 415,418 ----
***************
*** 426,430 ****
                                                      (code,), {})
              return
-         #
          try:
              self.tkconsole.beginexecuting()
--- 425,428 ----
***************
*** 445,449 ****
              except:
                  self.showtraceback()
-         #        
          finally:
              self.tkconsole.endexecuting()
--- 443,446 ----
***************
*** 481,492 ****
              root.withdraw()
              flist = PyShellFileList(root)
! 
          OutputWindow.__init__(self, flist, None, None)
! 
          import __builtin__
          __builtin__.quit = __builtin__.exit = "To exit, type Ctrl-D."
! 
          self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
! 
          text = self.text
          text.configure(wrap="char")
--- 478,489 ----
              root.withdraw()
              flist = PyShellFileList(root)
!         #
          OutputWindow.__init__(self, flist, None, None)
!         #
          import __builtin__
          __builtin__.quit = __builtin__.exit = "To exit, type Ctrl-D."
!         #
          self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
!         #
          text = self.text
          text.configure(wrap="char")
***************
*** 500,504 ****
          text.bind("<<open-python-shell>>", self.flist.open_shell)
          text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
! 
          self.save_stdout = sys.stdout
          self.save_stderr = sys.stderr
--- 497,501 ----
          text.bind("<<open-python-shell>>", self.flist.open_shell)
          text.bind("<<toggle-jit-stack-viewer>>", self.toggle_jit_stack_viewer)
!         #
          self.save_stdout = sys.stdout
          self.save_stderr = sys.stderr
***************
*** 511,517 ****
              sys.stderr = self.stderr
              sys.stdin = self
! 
          self.history = self.History(self.text)
! 
          if use_subprocess:
              self.interp.start_subprocess()
--- 508,514 ----
              sys.stderr = self.stderr
              sys.stdin = self
!         #
          self.history = self.History(self.text)
!         #
          if use_subprocess:
              self.interp.start_subprocess()

Index: rpc.py
===================================================================
RCS file: /cvsroot/idlefork/idle/rpc.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** rpc.py	25 Aug 2002 14:08:07 -0000	1.7
--- rpc.py	10 Oct 2002 08:25:24 -0000	1.8
***************
*** 178,184 ****
          self.debug("remotecall:", oid, methodname, args, kwargs) 
          seq = self.asynccall(oid, methodname, args, kwargs)
!         return self.asyncreturn(seq)
  
      def asynccall(self, oid, methodname, args, kwargs):
          request = ("call", (oid, methodname, args, kwargs))
          seq = self.putrequest(request)
--- 178,187 ----
          self.debug("remotecall:", oid, methodname, args, kwargs) 
          seq = self.asynccall(oid, methodname, args, kwargs)
!         ret = self.asyncreturn(seq)
!         self.debug("return:", ret)
!         return ret
  
      def asynccall(self, oid, methodname, args, kwargs):
+         self.debug("asyncall:", oid, methodname, args, kwargs)
          request = ("call", (oid, methodname, args, kwargs))
          seq = self.putrequest(request)

Index: run.py
===================================================================
RCS file: /cvsroot/idlefork/idle/run.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** run.py	25 Aug 2002 14:08:07 -0000	1.7
--- run.py	10 Oct 2002 08:25:24 -0000	1.8
***************
*** 2,22 ****
  import time
  import socket
  import rpc
  
  def main():
      """Start the Python execution server in a subprocess
  
!     In Idle, RPCServer is instantiated with handlerclass MyHandler, which
!     inherits register/unregister methods from RPCHandler via the mix-in class
!     SocketIO.
! 
!     When the RPCServer is instantiated, the TCPServer initialization creates an
!     instance of run.MyHandler and calls its handle() method.  handle()
!     instantiates a run.Executive, passing it a reference to the MyHandler
!     object.  That reference is saved as an attribute of the Executive instance.
!     The Executive methods have access to the reference and can pass it on to
!     entities that they command (e.g. RemoteDebugger.Debugger.start_debugger()).
!     The latter, in turn, can call MyHandler(SocketIO) register/unregister
!     methods via the reference to register and unregister themselves.
  
      """
--- 2,30 ----
  import time
  import socket
+ 
+ import CallTips
+ import RemoteDebugger
+ import RemoteObjectBrowser
+ import StackViewer
  import rpc
  
+ import __main__
+ 
  def main():
      """Start the Python execution server in a subprocess
  
!     In the Python subprocess, RPCServer is instantiated with handlerclass
!     MyHandler, which inherits register/unregister methods from RPCHandler via
!     the mix-in class SocketIO.
! 
!     When the RPCServer svr is instantiated, the TCPServer initialization
!     creates an instance of run.MyHandler and calls its handle() method.
!     handle() instantiates a run.Executive object, passing it a reference to the
!     MyHandler object.  That reference is saved as attribute rpchandler of the
!     Executive instance.  The Executive methods have access to the reference and
!     can pass it on to entities that they command
!     (e.g. RemoteDebugger.Debugger.start_debugger()).  The latter, in turn, can
!     call MyHandler(SocketIO) register/unregister methods via the reference to
!     register and unregister themselves.
  
      """
***************
*** 56,61 ****
      def __init__(self, rpchandler):
          self.rpchandler = rpchandler
-         import __main__
          self.locals = __main__.__dict__
  
      def runcode(self, code):
--- 64,69 ----
      def __init__(self, rpchandler):
          self.rpchandler = rpchandler
          self.locals = __main__.__dict__
+         self.calltip = CallTips.CallTips()
  
      def runcode(self, code):
***************
*** 63,67 ****
  
      def start_the_debugger(self, gui_adap_oid):
-         import RemoteDebugger
          return RemoteDebugger.start_debugger(self.rpchandler, gui_adap_oid)
  
--- 71,74 ----
***************
*** 70,73 ****
--- 77,83 ----
          self.rpchandler.unregister(idb_adap_oid)
  
+     def get_the_calltip(self, name):
+         return self.calltip.fetch_tip(name)
+ 
      def stackviewer(self, flist_oid=None):
          if not hasattr(sys, "last_traceback"):
***************
*** 76,81 ****
          if flist_oid is not None:
              flist = self.rpchandler.get_remote_proxy(flist_oid)
-         import RemoteObjectBrowser
-         import StackViewer
          tb = sys.last_traceback
          while tb and tb.tb_frame.f_globals["__name__"] in ["rpc", "run"]:
--- 86,89 ----