classification
Title: IDLE - an extension to clear the shell window
Type: enhancement Stage:
Components: IDLE Versions: Python 3.4, Python 3.3, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: roger.serwy Nosy List: Todd.Rovito, rhettinger, roger.serwy, taleinat, terry.reedy, vadmium
Priority: normal Keywords: patch

Created on 2009-05-29 21:09 by roger.serwy, last changed 2014-02-24 00:41 by terry.reedy.

Files
File name Uploaded Description Edit
ClearWindow.py roger.serwy, 2009-05-29 21:09 ClearWindow extension
ClearWindow.py roger.serwy, 2009-06-15 05:13 Added Undo functionality
taleinat.20140219.IDLE_ClearWindow_extension.patch taleinat, 2014-02-19 18:47 Updated version of the ClearWindow extensions, with tests review
taleinat.20140219.IDLE_ClearWindow_Squeezer_integration.patch taleinat, 2014-02-19 18:49
Squeezer Screenshot.PNG taleinat, 2014-02-23 18:51
Messages (19)
msg88539 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2009-05-29 21:09
I noticed that the feature to clear the shell window has been a
discussion topic in the IDLE-dev archives for a few years. Here's an
extension that can clear the contents of the shell window. It provides
"Clear Shell Window" under "Options" and a <Ctrl-L> key binding.

The source code provides two methods to do this. The
ModifiedUndoDelegator prevents changing the contents of the text widget
before "iomark". One solution is to disable the filter, make the
changes, then re-enable it. Another solution is move "iomark" to the
beginning of the document. Any thoughts?
msg89319 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2009-06-13 10:26
First of all I think that the Squeezer (issue #1529353) extension is
more useful and solves most of the problems that this proposed feature
is set to solve, e.g. issue #1442493.


IMO the second method you offer - temporarily moving "iomark" - is
preferable.

One reason is that it will allow using the undo feature to undo deleting
the entire shell history. I think this is important since deleting the
history by accident without a way to retrieve it would be very annoying.

I propose going with the clear_window2 method, wrapping it with
undo_block_start() and undo_block_stop().
msg89387 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2009-06-15 05:13
I just tried Squeezer. It's pretty neat and it solves a different
problem. Clearing the contents of the shell window should be a simple
operation.

The undo operation doesn't restore iomark properly, nor does it restore
tags. I've uploaded a newer version of the extension to handle undo.

Binding to the "<<undo>>" virtual event with add="+" didn't work as
expected, so the new undo event handler explicitly calls the older one.
I admit that this code is not ideal.

Should I move this extension to the Cheese Shop and close out this issue?
msg185485 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2013-03-29 02:16
The ClearWindow.py extension as included in the IdleX package contains a more recent version that allows undo with full color tag restoration.
msg186033 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2013-04-04 13:46
In #17632, Raymond suggests adding a "Restart and Clear" menu item under the Shell menu.
msg211032 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-11 22:43
Removing text before "iomark" can be done by using the underlying Text widget directly. See how the Squeezer extension does this in issue1529353. This should simplify the implementation significantly.


I also took a look at the version of the extension in IdleX. I'm thinking of adapting this for CPython's IDLE. Some questions:

1. Is there a reason that text.dump() isn't called inside ClearWindowDeleteCommand.do()?
2. What is the purpose of strip_ansi()?
3. Does IDLE support multi-line prompts, or is that just IdleX? As a side note, it seems that in IDLE the debugger will override the prompt with '>>> ' whenever it is shut down (see PyShell.close_debugger); perhaps this is a bug?
4. I see ClearWindowDeleteCommand just calls text.delete() and text.insert to modify text before the iomark. Will this work on regular IDLE as well, or this is possible only in IdleX?
msg211044 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2014-02-11 23:48
>
> Removing text before "iomark" can be done by using the underlying Text widget directly. See how the Squeezer extension does this in issue1529353. This should simplify the implementation significantly.

I agree that the underlying .delete can be called directly, bypassing 
the ModifiedUndoDelegator in the percolator chain. I have mixed opinions 
about the Percolator, but that's another issue.

>
> 1. Is there a reason that text.dump() isn't called inside ClearWindowDeleteCommand.do()?

There is no compelling reason. I agree that it should be moved to .do()

> 2. What is the purpose of strip_ansi()?

That's an artifact from earlier code for IPython compatibility. The 
colored text prompts in IPython use ANSI escape codes, and the older 
undo code reinserted the text without restoring tags.

Using text.dump() and the restore routine in undo() now restore the tags 
and eliminates the need for strip_ansi(). I haven't removed that old 
code yet.

> 3. Does IDLE support multi-line prompts, or is that just IdleX? As a side note, it seems that in IDLE the debugger will override the prompt with '>>> ' whenever it is shut down (see PyShell.close_debugger); perhaps this is a bug?

IDLE itself does support multi-line prompts. The debugger is a whole 
other can of worms.

> 4. I see ClearWindowDeleteCommand just calls text.delete() and text.insert to modify text before the iomark. Will this work on regular IDLE as well, or this is possible only in IdleX?

It should work on regular IDLE. IdleX wraps the existing CPython IDLE.
msg211056 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-12 06:11
Roger, thanks for the quick response!

I'll try to get to working on this in the coming days.
msg211066 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-12 08:58
Terry, if I wrote an appropriate patch, would it have a chance of being accepted?
msg211067 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-02-12 09:40
Without having read the dialog to know what you mean by appropriate, and how a new patch would be different from Roger's 5 year old patch, or how this issue relates toSqueezer, yes. I have occasionally closed the shell and reopened (perhaps by running a file) to clear the shell. I would like to reduce the need for that by putting help output in a separate read-only output window. But there is still the occasional 2000 line traceback for hitting the recursion limit, and other mishaps.
msg211073 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-12 09:57
The relation to Squeezer is that both of these can be useful when you've had a large amount of output written in the IDLE shell. I prefer Squeezer as a solution for this issue, for two reasons:

1. Squeezer catches long outputs before they are ever written in the Text widget, so the performance degradation doesn't happen at all. This also means that for truly huge outputs, Squeezer will still work, while otherwise IDLE may become completely stuck before a user would have a chance to clear the shell history.

2. Squeezer gives the user access to "squeezed" text in several ways: copy to the clipboard, open in an external viewer or expand into the shell. Otherwise the user must choose between a shell with some useless output hiding the useful history, or erasing the entire history.

Still, I still think clearing the history could be a useful feature, though. This is a common feature in terminals and it has been requested relatively often.

Note that making ClearWindow and Squeezer play together nicely is non-trivial. I'm likely going to have ClearWindow include special support for Squeezer.
msg211074 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-12 09:58
Also, note that the new version of Squeezer allows squeezing tracebacks as well as normal output! It does not squeeze them automatically, though; the user must do so manually.
msg211310 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-16 09:28
FYI, with some help from Roger answering various questions, I've cooked up a version of ClearWindow supporting the current version of IDLE. This includes integration with the Squeezer extension.

I haven't tested it, however, nor written appropriate tests. I hope to do so in the coming days, and when I have I'll post a patch.
msg211641 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-19 18:47
Attaching a patch adding a ClearWindow extension for IDLE.

I took some ideas from Roger's version in IdleX, but I wrote this version from scratch and it is significantly different in many aspects.

This patch includes extensive tests with 98% coverage of ClearWindow.py.

This also includes a minor change to PyShell, adding a 'prompt' tag to every prompt in the shell's Text widget. This makes it straightforward for the ClearWindow extension to find the last prompt in the shell.
msg211642 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-19 18:49
Attached another patch which adds support for the Squeezer extension to ClearWindow. This is necessary in case the Squeezer extension is added to IDLE.

This patch allows ClearWindow to properly remove "squeezed text" buttons created by Squeezer, and also reinsert them if the 'clear' operation is undone.

This patch also updates the relevant ClearWindow tests as well as adding new tests to check the new functionality.
msg211644 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-19 18:51
Regarding the last patch, see issue1529353 which proposes adding the Squeezer IDLE extension (including patches).
msg211663 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-02-19 22:00
I have not looked Idle issues in the last few days because I am working on the unmaintained (since 2006 and 8), embarrassing (~5 bugs in 70 lines), disfunctional mess that tokenize.untokenize has been. It will take me a few more days to finish.

Clearing the shell window strikes me as an obvious beginner feature. From what I have read here, Squeezer strikes me as the sort of advanced feature that you and others have suggested should not be added. I might change my mind after trying it out. I must admit that switching from a half gigabyte 32-bit xp machine to a multi-gigabyte 64-bit win7 machine a couple of years ago seems to have eliminated large output slowdown. Or maybe tk has improved. Either way, not having the problem Squeezer solves probably colors my thinking.

So *at the moment* I would be inclined to apply a more or less Squeezer-ignorant patch like ClearWindow-extension and then revise Squeezer to replace methods as necessary when it is installed.
msg212020 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2014-02-23 18:51
Terry, please do give Squeezer a try before making a decision! Squeezer may be slightly more complex than ClearWindow in concept and in code, but IMO it is simpler and more appropriate for use by a novice user.

I'm attaching a screenshot to give a feeling of what working in the IDLE shell with Squeezer looks like. This screenshot was taken on Windows. Note that the second squeezed text is the very long "Max recursion depth" exception traceback, which I manually squeezed after it was printed.

Now I'll try to make the case for Squeezer one last time...


Nobody expects a Squeezer Inquisition! Amongst Squeezer's weaponry are such diverse elements as:

1. No fear! Squeezer automatically catches overly long outputs for users, so they need not fear crashing IDLE or losing their history just by printing something long accidentally.

2. No surprise! Squeezer requires no learning and is completely self-explanatory. It's an in-line button with a label of the form "Squeezed text (13412 lines)". Hovering over it with the mouse shows tooltip listing the various available interactions (expand, copy, preview). Don't want the text to be squeezed? Double-click and the button is replaced by the original text!

3. Ruthless efficiency! With Squeezer, IDLE will never slow down to a crawl again! (Well, unless you explicitly expand a very long output.)

4. Dashing red uniforms! Okay, not really, but it does look nice.

Also, beware *the comfy chair*! Squeezer conveniently allows one to manually squeeze exception tracebacks and other outputs to clean up the shell history. This is available via the right-click context menu.


Finally, I'll mention that ClearWindow forces a user to choose: delete your entire shell history, or keep it all. Squeezer allows a user to choose which parts to hide and which to keep, and nothing is ever lost since squeezed text can always be expanded again.

That's it. If this doesn't convince people of the utility of Squeezer, I truly believe nothing else will.
msg212051 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-02-24 00:41
OK, I will.
History
Date User Action Args
2014-02-24 00:41:40terry.reedysetmessages: + msg212051
2014-02-23 18:51:12taleinatsetfiles: + Squeezer Screenshot.PNG

messages: + msg212020
2014-02-19 22:00:23terry.reedysetmessages: + msg211663
2014-02-19 18:51:18taleinatsetmessages: + msg211644
2014-02-19 18:49:40taleinatsetfiles: + taleinat.20140219.IDLE_ClearWindow_Squeezer_integration.patch

messages: + msg211642
2014-02-19 18:47:02taleinatsetfiles: + taleinat.20140219.IDLE_ClearWindow_extension.patch
keywords: + patch
messages: + msg211641
2014-02-16 09:28:29taleinatsetmessages: + msg211310
2014-02-16 06:35:50Todd.Rovitosetnosy: + Todd.Rovito
2014-02-12 09:58:23taleinatsetmessages: + msg211074
2014-02-12 09:57:04taleinatsetmessages: + msg211073
2014-02-12 09:40:01terry.reedysetmessages: + msg211067
versions: - Python 3.2
2014-02-12 08:58:06taleinatsetmessages: + msg211066
2014-02-12 08:57:21taleinatsetnosy: + terry.reedy
2014-02-12 06:11:56taleinatsetmessages: + msg211056
2014-02-11 23:48:03roger.serwysetmessages: + msg211044
2014-02-11 22:43:11taleinatsetnosy: + taleinat
messages: + msg211032
2014-02-04 12:02:47taleinatsetnosy: - taleinat
2013-12-10 01:40:40vadmiumsetnosy: + vadmium
2013-04-04 13:46:38roger.serwysetnosy: + rhettinger
messages: + msg186033
2013-04-04 13:45:43roger.serwylinkissue17632 superseder
2013-03-29 02:16:13roger.serwysetassignee: roger.serwy
messages: + msg185485
versions: + Python 2.7, Python 3.3, Python 3.4
2010-08-03 21:11:45terry.reedysettype: behavior -> enhancement
versions: - Python 2.6, Python 2.5, Python 3.0, Python 3.1, Python 2.7
2009-06-15 05:13:28roger.serwysetfiles: + ClearWindow.py

messages: + msg89387
2009-06-13 10:26:18taleinatsetnosy: + taleinat
messages: + msg89319
2009-05-29 21:09:50roger.serwycreate