1. 程式人生 > >python的IDEL編輯器清屏文件配置

python的IDEL編輯器清屏文件配置

doesn 當前 分享 man ngs ins lte onf con

1.找到Python\PythonX\Lib\idlelib(x為你的版本號),在當前目錄下添加ClearWindow.py,復制提供的代碼,保存為*.py即可。

技術分享圖片
 1 class ClearWindow:
 2 
 3     menudefs = [
 4         (options, [None,
 5                (Clear Shell Window, <<clear-window>>),
 6        ]),]
 7 
 8     def __init__(self, editwin):
 9         self.editwin = editwin
10 self.text = self.editwin.text 11 self.text.bind("<<clear-window>>", self.clear_window2) 12 13 self.text.bind("<<undo>>", self.undo_event) # add="+" doesn‘t work 14 15 def undo_event(self, event): 16 text = self.text 17 18 text.mark_set("
iomark2", "iomark") 19 text.mark_set("insert2", "insert") 20 self.editwin.undo.undo_event(event) 21 22 # fix iomark and insert 23 text.mark_set("iomark", "iomark2") 24 text.mark_set("insert", "insert2") 25 text.mark_unset("iomark2") 26 text.mark_unset("
insert2") 27 28 29 def clear_window2(self, event): # Alternative method 30 # work around the ModifiedUndoDelegator 31 text = self.text 32 text.undo_block_start() 33 text.mark_set("iomark2", "iomark") 34 text.mark_set("iomark", 1.0) 35 text.delete(1.0, "iomark2 linestart") 36 text.mark_set("iomark", "iomark2") 37 text.mark_unset("iomark2") 38 text.undo_block_stop() 39 if self.text.compare(insert, <, iomark): 40 self.text.mark_set(insert, end-1c) 41 self.editwin.set_line_and_column() 42 43 def clear_window(self, event): 44 # remove undo delegator 45 undo = self.editwin.undo 46 self.editwin.per.removefilter(undo) 47 48 # clear the window, but preserve current command 49 self.text.delete(1.0, "iomark linestart") 50 if self.text.compare(insert, <, iomark): 51 self.text.mark_set(insert, end-1c) 52 self.editwin.set_line_and_column() 53 54 # restore undo delegator 55 self.editwin.per.insertfilter(undo)
ClearWindow.py

2.在當前目錄下找到config-extensions.def 並修改,在末尾添加如下代碼:

技術分享圖片
[ClearWindow]
enable=True
enable_editor=False
enable_shell=True
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>
配置內容

3. 重新打開IDEL即可,如果快捷鍵無效的話,註意查看ClearWindow.py的大小寫以及配置文件內容的大小寫狀態

python的IDEL編輯器清屏文件配置