Home > other >  Questions about the CLS - just contact python, thank you!
Questions about the CLS - just contact python, thank you!

Time:09-19

OS. The system (" the clear "), is how to use the CLS, can remove the inside of the shell window text? I tried it on and didn't see the effect, thank you!

CodePudding user response:

In strict accordance with the following steps to operate:
 
The class ClearWindow:

Menudefs=[
(' options', [None,
(' the Clear Shell Window ', '& lt; '),
]),]

Def __init__ (self, editwin) :
Self. Editwin=editwin
The self. The text=self. Editwin. Text
Self. Text. Bind (" & lt; " , the self. Clear_window2)

Self. Text. Bind (" & lt; " , the 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) : # the Alternative method
# the work around the ModifiedUndoDelegator
Text=self. Text
Text. Undo_block_start ()
Text. Mark_set (" iomark2 ", "iomark")
Text. Mark_set (" iomark ", 1.0)
The text. The delete (1.0, "iomark2 linestart")
Text. Mark_set (" iomark ", "iomark2")
Text. Mark_unset (" iomark2 ")
Text. Undo_block_stop ()
If self.text.com pare said (' insert ', '& lt; ', 'iomark') :
Self. Text. Mark_set (' insert ', 'end - 1 - c')
Self. Editwin. Set_line_and_column ()

Def clear_window (self, event) :
# remove undo delegator
Undo=self. Editwin. Undo
Self. Editwin. Per removefilter (undo)

# the clear the window, but preserve the current command
The self. The text. The delete (1.0, "iomark linestart")
If self.text.com pare said (' insert ', '& lt; ', 'iomark') :
Self. Text. Mark_set (' insert ', 'end - 1 - c')
Self. Editwin. Set_line_and_column ()

# restore undo delegator
Self. Editwin. Per insertfilter (undo)

1). To save the above code segment for ClearWindow. Py files, and copy to the Python installation home directory \ Lib \ idlelib directory, and find the config in that directory - extensions. Def this file (idle configuration file extensions)

2.) in a text editing tools, such as notepad to open the config - extensions. Add the following at the end of the file after the def:
 
[ClearWindow]
The enable=1
Enable_editor=0
Enable_shell=1
[ClearWindow_cfgBindings]
The clear - window=& lt; Control - Key - l>


3). Then save the exit,

4). To open the python IDLE, have a look at the options is an option for the clear shell window CTRL + L or shortcuts are available (click)
  • Related