Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/library/idle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions Lib/idlelib/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Lib/idlelib/config-keys.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ history-previous=<Alt-Key-p> <Meta-Key-p> <Alt-Key-P> <Meta-Key-P>
interrupt-execution=<Control-Key-c> <Control-Key-C>
view-restart=<Key-F6>
restart-shell=<Control-Key-F6>
clear-restart-shell=<Control-Key-F7>
open-class-browser=<Alt-Key-c> <Meta-Key-c> <Alt-Key-C> <Meta-Key-C>
open-module=<Alt-Key-m> <Meta-Key-m> <Alt-Key-M> <Meta-Key-M>
open-new-window=<Control-Key-n> <Control-Key-N>
Expand Down Expand Up @@ -82,6 +83,7 @@ history-previous=<Alt-Key-p> <Meta-Key-p>
interrupt-execution=<Control-Key-c>
view-restart=<Key-F6>
restart-shell=<Control-Key-F6>
clear-restart-shell=<Control-Key-F7>
open-class-browser=<Control-Key-x><Control-Key-b>
open-module=<Control-Key-x><Control-Key-m>
open-new-window=<Control-Key-x><Control-Key-n>
Expand Down Expand Up @@ -142,6 +144,7 @@ history-previous = <Alt-Key-p> <Meta-Key-p>
interrupt-execution = <Control-Key-c>
view-restart = <Key-F6>
restart-shell = <Control-Key-F6>
clear-restart-shell = <Control-Key-F7>
open-class-browser = <Control-Key-b>
open-module = <Control-Key-m>
open-new-window = <Control-Key-n>
Expand Down Expand Up @@ -204,6 +207,7 @@ history-previous=<Control-Key-p>
interrupt-execution=<Control-Key-c>
view-restart=<Key-F6>
restart-shell=<Control-Key-F6>
clear-restart-shell=<Control-Key-F7>
open-class-browser=<Command-Key-b>
open-module=<Command-Key-m>
open-new-window=<Command-Key-n>
Expand Down Expand Up @@ -263,6 +267,7 @@ comment-region = <Control-Key-3>
redo = <Shift-Command-Key-Z>
close-window = <Command-Key-w>
restart-shell = <Control-Key-F6>
clear-restart-shell = <Control-Key-F7>
save-window-as-file = <Shift-Command-Key-S>
close-all-windows = <Command-Key-q>
view-restart = <Key-F6>
Expand Down
1 change: 1 addition & 0 deletions Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def GetCoreKeys(self, keySetName=None):
'<<interrupt-execution>>': ['<Control-c>'],
'<<view-restart>>': ['<F6>'],
'<<restart-shell>>': ['<Control-F6>'],
'<<clear-restart-shell>>': ['<Control-F7>'],
'<<open-class-browser>>': ['<Alt-c>'],
'<<open-module>>': ['<Alt-m>'],
'<<open-new-window>>': ['<Control-n>'],
Expand Down
2 changes: 2 additions & 0 deletions Lib/idlelib/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ <h3>Shell menu (Shell window only)<a class="headerlink" href="#shell-menu-shell-
</dd>
<dt>Restart Shell</dt><dd><p>Restart the shell to clean the environment.</p>
</dd>
<dt>Clear and Restart</dt><dd><p>Restart the shell and clear the contents of the shell window.</p>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is generated from the IDLE doc: Doc/librarary/idle.rst. Edit latter instead.

</dd>
<dt>Previous History</dt><dd><p>Cycle through earlier commands in history which match the current entry.</p>
</dd>
<dt>Next History</dt><dd><p>Cycle through later commands in history which match the current entry.</p>
Expand Down
1 change: 1 addition & 0 deletions Lib/idlelib/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
('shell', [
('_View Last Restart', '<<view-restart>>'),
('_Restart Shell', '<<restart-shell>>'),
('_Clear and Restart', '<<clear-restart-shell>>'),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Clear shell might be sufficient.

None,
('_Previous History', '<<history-previous>>'),
('_Next History', '<<history-next>>'),
Expand Down
42 changes: 28 additions & 14 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def start_subprocess(self):
self.poll_subprocess()
return self.rpcclt

def restart_subprocess(self, with_cwd=False, filename=''):
def restart_subprocess(self, with_cwd=False, filename='', clear=False):
if self.restarting:
return self.rpcclt
self.restarting = True
Expand All @@ -503,12 +503,19 @@ def restart_subprocess(self, with_cwd=False, filename=''):
return None
self.transfer_path(with_cwd=with_cwd)
console.stop_readline()
# annotate restart in shell window and mark it
console.text.delete("iomark", "end-1c")
console.write('\n')
console.write(restart_line(console.width, filename))
console.text.mark_set("restart", "end-1c")
console.text.mark_gravity("restart", "left")
if clear:
# Temporarily remove the iomark to allow deleting all text.
console.text.mark_unset("iomark")
console.text.delete("0.0", "end")
console.resetoutput()
console.write_header()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need this. And the new function.

else:
# Annotate restart in shell window and mark it.
console.text.delete("iomark", "end-1c")
console.write('\n')
console.write(restart_line(console.width, filename))
console.text.mark_set("restart", "end-1c")
console.text.mark_gravity("restart", "left")
if not filename:
console.showprompt()
# restart subprocess debugger
Expand Down Expand Up @@ -893,6 +900,7 @@ def __init__(self, flist=None):
if use_subprocess:
text.bind("<<view-restart>>", self.view_restart_mark)
text.bind("<<restart-shell>>", self.restart_shell)
text.bind("<<clear-restart-shell>>", self.clear_and_restart_shell)
squeezer = self.Squeezer(self)
text.bind("<<squeeze-current-text>>",
squeezer.squeeze_current_text_event)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Misc/NEWS.d/next/IDLE/2020-07-29-22-06-13.bpo-6143.d8pzkH.rst
Original file line number Diff line number Diff line change
@@ -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.