[Idle-dev] IDLE "shell" (was: IDLE interpreter window)

Guido van Rossum guido@python.org
Tue, 07 Mar 2000 13:57:30 -0500


OK, here's a patch.  It was remarkably simple.

The following patch prevents all editing from having any effect before
the "I/O mark" -- an invisible marker in the text that delineates the
beginning of the command editing area, typically placed just after the
last prompt.  You can still steer the cursor anywhere in the window
(unlike with a typical bash-in-an-xterm setup) but you can't type (or
delete or cut or paste) when you're not in the command area.

Please try this out, and let me know how it "feels"!

Note that there's still a way to confuse yourself: if you use undo
immediately after a fresh prompt, it will erase the prompt, and if you
hit undo repeatedly, it will erase more and more of the session -- but
not its effects on your workspace.  I haven't decided yet if I want to
call that a feature.

Index: PyShell.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Tools/idle/PyShell.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -c -r1.27 -r1.28
*** PyShell.py	2000/03/07 17:55:32	1.27
--- PyShell.py	2000/03/07 18:51:49	1.28
***************
*** 15,20 ****
--- 15,21 ----
  from EditorWindow import EditorWindow, fixwordbreaks
  from FileList import FileList
  from ColorDelegator import ColorDelegator
+ from UndoDelegator import UndoDelegator
  from OutputWindow import OutputWindow
  from IdleConf import idleconf
  import idlever
***************
*** 127,132 ****
--- 128,155 ----
      })
  
  
+ class ModifiedUndoDelegator(UndoDelegator):
+ 
+     # Forbid insert/delete before the I/O mark
+ 
+     def insert(self, index, chars, tags=None):
+         try:
+             if self.delegate.compare(index, "<", "iomark"):
+                 self.delegate.bell()
+                 return
+         except TclError:
+             pass
+         UndoDelegator.insert(self, index, chars, tags)
+ 
+     def delete(self, index1, index2=None):
+         try:
+             if self.delegate.compare(index1, "<", "iomark"):
+                 self.delegate.bell()
+                 return
+         except TclError:
+             pass
+         UndoDelegator.delete(self, index1, index2)
+ 
  class ModifiedInterpreter(InteractiveInterpreter):
  
      def __init__(self, tkconsole):
***************
*** 264,269 ****
--- 287,293 ----
  
      # Override classes
      ColorDelegator = ModifiedColorDelegator
+     UndoDelegator = ModifiedUndoDelegator
  
      # Override menu bar specs
      menu_specs = PyShellEditorWindow.menu_specs[:]

--Guido van Rossum (home page: http://www.python.org/~guido/)