diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index 75b6fa3861b23d..0f94579f759bdd 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -252,6 +252,9 @@ View Last Restart Restart Shell Restart the shell to clean the environment. +Clear and Restart + Restart the shell and clear the contents of the shell window. + Previous History Cycle through earlier commands in history which match the current entry. diff --git a/Lib/idlelib/README.txt b/Lib/idlelib/README.txt index bc3d978f43f1ad..22224de031cd5a 100644 --- a/Lib/idlelib/README.txt +++ b/Lib/idlelib/README.txt @@ -162,6 +162,7 @@ Edit Shell # pyshell View Last Restart # pyshell.PyShell.view_restart_mark Restart Shell # pyshell.PyShell.restart_shell + Clear and Restart # pyshell.PyShell.clear_and_restart_shell Interrupt Execution # pyshell.PyShell.cancel_callback Debug (Shell only) diff --git a/Lib/idlelib/config-keys.def b/Lib/idlelib/config-keys.def index f71269b5b49f46..3b6cc77326d48b 100644 --- a/Lib/idlelib/config-keys.def +++ b/Lib/idlelib/config-keys.def @@ -24,6 +24,7 @@ history-previous= interrupt-execution= view-restart= restart-shell= +clear-restart-shell= open-class-browser= open-module= open-new-window= @@ -82,6 +83,7 @@ history-previous= interrupt-execution= view-restart= restart-shell= +clear-restart-shell= open-class-browser= open-module= open-new-window= @@ -142,6 +144,7 @@ history-previous = interrupt-execution = view-restart = restart-shell = +clear-restart-shell = open-class-browser = open-module = open-new-window = @@ -204,6 +207,7 @@ history-previous= interrupt-execution= view-restart= restart-shell= +clear-restart-shell= open-class-browser= open-module= open-new-window= @@ -263,6 +267,7 @@ comment-region = redo = close-window = restart-shell = +clear-restart-shell = save-window-as-file = close-all-windows = view-restart = diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py index 04444a3bf20b30..6e66c018fc5798 100644 --- a/Lib/idlelib/config.py +++ b/Lib/idlelib/config.py @@ -614,6 +614,7 @@ def GetCoreKeys(self, keySetName=None): '<>': [''], '<>': [''], '<>': [''], + '<>': [''], '<>': [''], '<>': [''], '<>': [''], diff --git a/Lib/idlelib/help.html b/Lib/idlelib/help.html index 81ce5100bb8ad5..05110b4bf3cb0d 100644 --- a/Lib/idlelib/help.html +++ b/Lib/idlelib/help.html @@ -285,6 +285,8 @@

Shell menu (Shell window only)>", self.view_restart_mark) text.bind("<>", self.restart_shell) + text.bind("<>", self.clear_and_restart_shell) squeezer = self.Squeezer(self) text.bind("<>", squeezer.squeeze_current_text_event) @@ -1041,24 +1049,27 @@ def short_title(self): COPYRIGHT = \ 'Type "help", "copyright", "credits" or "license()" for more information.' + def write_header(self): + self.write(f"Python {sys.version} on {sys.platform}\n" + f"{self.COPYRIGHT}\n") + if not use_subprocess: + self.write("==== No Subprocess ====\n\n" + "WARNING: Running IDLE without a Subprocess is\n" + "deprecated and will be removed in a later version.\n" + "See Help/IDLE Help for details.\n\n") + def begin(self): self.text.mark_set("iomark", "insert") self.resetoutput() if use_subprocess: - nosub = '' client = self.interp.start_subprocess() if not client: self.close() return False else: - nosub = ("==== No Subprocess ====\n\n" + - "WARNING: Running IDLE without a Subprocess is deprecated\n" + - "and will be removed in a later version. See Help/IDLE Help\n" + - "for details.\n\n") sys.displayhook = rpc.displayhook - self.write("Python %s on %s\n%s\n%s" % - (sys.version, sys.platform, self.COPYRIGHT, nosub)) + self.write_header() self.text.focus_force() self.showprompt() import tkinter @@ -1268,6 +1279,9 @@ def restart_shell(self, event=None): "Callback for Run/Restart Shell Cntl-F6" self.interp.restart_subprocess(with_cwd=True) + def clear_and_restart_shell(self, event=None): + self.interp.restart_subprocess(with_cwd=True, clear=True) + def showprompt(self): self.resetoutput() self.console.write(self.prompt) diff --git a/Misc/NEWS.d/next/IDLE/2020-07-29-22-06-13.bpo-6143.d8pzkH.rst b/Misc/NEWS.d/next/IDLE/2020-07-29-22-06-13.bpo-6143.d8pzkH.rst new file mode 100644 index 00000000000000..5f994c3669a9ed --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2020-07-29-22-06-13.bpo-6143.d8pzkH.rst @@ -0,0 +1,2 @@ +Add a "Clear and Restart" item to IDLE's "Shell" menu. This can be used to +clear the contents of the shell window.