Python empties the contents of idle __python

Source: Internet
Author: User
Python code: clearwindow.py
"""


Clear Window Extension
version:0.2


It provides "clear Shell window" under "Options"
With ability to undo.


Add these lines to Config-extensions.def


[ClearWindow]
Enable=1
Enable_editor=0
Enable_shell=1
[Clearwindow_cfgbindings]
Clear-window=<control-key-l>




"""


Class ClearWindow:


Menudefs = [
(' Options ', [None,
(' Clear Shell Window ', ' <<clear-window>> '),
]),]


def __init__ (self, Editwin):
Self.editwin = Editwin
Self.text = Self.editwin.text
Self.text.bind ("<<clear-window>>", Self.clear_window2)


Self.text.bind ("<<undo>>", self.undo_event) # add= "+" doesn ' t work


def undo_event (self, event):
Text = Self.text


Text.mark_set ("Iomark2", "Iomark")
Text.mark_set ("Insert2", "Insert")
Self.editwin.undo.undo_event (Event)


# fix Iomark and insert
Text.mark_set ("Iomark", "IOMARK2")
Text.mark_set ("Insert", "Insert2")
Text.mark_unset ("Iomark2")
Text.mark_unset ("Insert2")




def clear_window2 (self, event): # Alternative method
# work around the Modifiedundodelegator
Text = Self.text
Text.undo_block_start ()
Text.mark_set ("Iomark2", "Iomark")
Text.mark_set ("Iomark", 1.0)
Text.delete (1.0, "Iomark2 Linestart")
Text.mark_set ("Iomark", "IOMARK2")
Text.mark_unset ("Iomark2")
Text.undo_block_stop ()
If Self.text.compare (' Insert ', ' < ', ' Iomark '):
Self.text.mark_set (' Insert ', ' end-1c ')
Self.editwin.set_line_and_column ()


def clear_window (self, event):
# Remove Undo Delegator
Undo = Self.editwin.undo
Self.editwin.per.removefilter (undo)


# Clear the window, but preserve current command
Self.text.delete (1.0, "Iomark Linestart")
If Self.text.compare (' Insert ', ' < ', ' Iomark '):
Self.text.mark_set (' Insert ', ' end-1c ')
Self.editwin.set_line_and_column ()


# Restore Undo Delegator
Self.editwin.per.insertfilter (undo)


Copy the clearwindow.py file and place it under the Python installation directory, Python xxx\lib\idlelib (XXX is your Python version, for example, 2.7).
Notepad opens the Config-extensions.def (Idle extended configuration file) under the Python xxx\lib\idlelib directory, and to prevent errors, you can copy a backup before opening it.
Modify the Config-extensions.def, add the following at the end, and then save the exit:
[ClearWindow]
Enable=1
Enable_editor=0
Enable_shell=1
[Clearwindow_cfgbindings]
Clear-window=<control-key-;>
Open the Python idle,options option to see the addition of Clear shell window Ctrl +;
Enter the code in the idle and press CTRL +; (refers to Ctrl and;) and find that the code you just entered can be cleared.
Shortcut keys CTRL +; can be modified to a different key to
Clear-window=<control-key-;>
Control and modify the other key.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.