diff options
author | Guido van Rossum <guido@python.org> | 2000-03-07 18:51:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-07 18:51:49 (GMT) |
commit | 9de988315a3ac8b87a9881d8d2ebf38d19671442 (patch) | |
tree | 4bc0e0a7bc05b42bc2b9719aa68f2d541b9584ac /Tools | |
parent | 6fbd1f85d91772bd8c173db09b092ef88d9823bf (diff) | |
download | cpython-9de988315a3ac8b87a9881d8d2ebf38d19671442.zip cpython-9de988315a3ac8b87a9881d8d2ebf38d19671442.tar.gz cpython-9de988315a3ac8b87a9881d8d2ebf38d19671442.tar.bz2 |
Override the Undo delegator to forbid any changes before the I/O mark.
It beeps if you try to insert or delete before the "iomark" mark.
This makes the shell less confusing for newbies.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/idle/PyShell.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Tools/idle/PyShell.py b/Tools/idle/PyShell.py index 6e26738..cbd7d66 100644 --- a/Tools/idle/PyShell.py +++ b/Tools/idle/PyShell.py @@ -15,6 +15,7 @@ import tkMessageBox 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,6 +128,28 @@ class ModifiedColorDelegator(ColorDelegator): }) +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,6 +287,7 @@ class PyShell(OutputWindow): # Override classes ColorDelegator = ModifiedColorDelegator + UndoDelegator = ModifiedUndoDelegator # Override menu bar specs menu_specs = PyShellEditorWindow.menu_specs[:] |