New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDLE - clear and restart the shell window #50393
Comments
I noticed that the feature to clear the shell window has been a The source code provides two methods to do this. The |
First of all I think that the Squeezer (issue bpo-1529353) extension is IMO the second method you offer - temporarily moving "iomark" - is One reason is that it will allow using the undo feature to undo deleting I propose going with the clear_window2 method, wrapping it with |
I just tried Squeezer. It's pretty neat and it solves a different The undo operation doesn't restore iomark properly, nor does it restore Binding to the "<<undo>>" virtual event with add="+" didn't work as Should I move this extension to the Cheese Shop and close out this issue? |
The ClearWindow.py extension as included in the IdleX package contains a more recent version that allows undo with full color tag restoration. |
In bpo-17632, Raymond suggests adding a "Restart and Clear" menu item under the Shell menu. |
Removing text before "iomark" can be done by using the underlying Text widget directly. See how the Squeezer extension does this in bpo-1529353. 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? |
I agree that the underlying .delete can be called directly, bypassing
There is no compelling reason. I agree that it should be moved to .do()
That's an artifact from earlier code for IPython compatibility. The Using text.dump() and the restore routine in undo() now restore the tags
IDLE itself does support multi-line prompts. The debugger is a whole
It should work on regular IDLE. IdleX wraps the existing CPython IDLE. |
Roger, thanks for the quick response! I'll try to get to working on this in the coming days. |
Terry, if I wrote an appropriate patch, would it have a chance of being accepted? |
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. |
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:
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. |
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. |
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. |
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. |
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. |
Regarding the last patch, see bpo-1529353 which proposes adding the Squeezer IDLE extension (including patches). |
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. |
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:
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. |
OK, I will. |
This issue is lower priority to me than many others, but there does seem to be at least some demand shown on Stackoverflow. So I have not dismissed it completely. |
Python 3.6 just got a patch to squeeze duplicate traceback lines, as with recursion-depth errors. |
Comments on taleinat.20140219.IDLE_ClearWindow_extension.patch. In 3.6, module names are lowercase, not too long. Also, I am trying to consolidate small files, not multiply them. I am trying to convert existing built-in extensions to built-in features, not add new extension files. The options menu seems like a strange place for the menu item. Since this patch is for Shell, I would put it on the Shell menu. Select All == Control A (Edit menu) + Backspace or Delete clears editor and output windows. (I could add this to the doc.) The issue with Shell, as Roger noted in his original post, is the current mechanism to prevent deletion. This suggests an alternate solution: only protect the current prompt (which I would like to move to a sidebar anyway). There could be an option to making Shell history editable or not? Why should people have to save-load or copy-paste to edit a shell session? (Currently, the Rt click context menu displays an apparently active 'Cut' that does not work.) The main issue is that people might edit past input, hit return, and expect the code to run. This could be made to work. What to delete? Everything prior to last prompt is plausible when IDLE is paused waiting for code input. It is wrong if one is trying to stop output since the last prompt. These are two different use cases (Raymond mentioned both in duplicate bpo-27771).
Undo-able? Cntl-A + delete is already undo-able. Clear and Restart would be, as Restart clears the undo stack. I think emergency deletion should not be. |
The ClearWindow.py extension works well with the specified shortcut, How can i invoke it in my source code to clear the window ? Thanks in advance. |
Alwx, please do not change the headers. IDLE menu commands cannot be invoked from a program. |
The way to clear an editor window at least on Windows is ^A (select all) and delete, which can be any of BS (backspace) or DEL or ^X (Cut). The latter 'moves to the clipboard. In Shell, select all selects everything, but ^X enters '^x', the other 2 do their normal thing. All three unselect without deleting. My first inclination is to have any or all of these work by ignoring IDLE's protection mechanism, which is different from tk's no-write mode. After deleting, the prompts needs to be re-written. I understand that Cut would need to expand squeezed blocks to the clipboard. |
An SO question today got me to look more at SO questions and discussion, and this appears to be the most requested feature. https://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window - 2009, 129 upvotes, 32 answers (not all read yet) ... (15 other hits for [python-idle] clear screen) https://stackoverflow.com/questions/54083355/how-to-clear-the-screen-in-idle-on-imac - 2019 today So I want to revisit this after we do a bit more on squeezer. I want to add 'Clear and Restart' to the Shell menu, as Raymond suggested, so I am inclined to 'clear and restart' this discussion by closing this issue and reopening bpo-17632 as a followup. |
bpo-17632 was instead closed as a duplicate of this issue. The (editor) Run menu now has a custom run item. 'Clear shell before restart' could be added as an alternative to 'no restart'. But this would be a separate issue. |
I would really like to be able to clear IDLE when using it. I do not understand how hard it can be just to clear a window. |
I have created PR 21682 to add a "Clear and Restart" item to the "Shell" menu. |
@PokerStar: First we have to agree on several things.
Overall, I prefer to use the deletion mechanism we have, rather than add a new one. |
https://stackoverflow.com/questions/71290382/how-do-i-adjust-python-idle-shell-settings-so-that-the-next-line-of-code-i-type |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: