zoukankan      html  css  js  c++  java
  • Python IDLE配置清屏快捷键(Ctrl+L)

    1.在PythonLibidlelib下,新建一个ClearWindow.py文件(没有时就新建),内容如下:

     1 """
     2 
     3 Clear Window Extension
     4 Version: 0.2
     5 
     6 Author: Roger D. Serwy
     7         roger.serwy@gmail.com
     8 
     9 Date: 2009-06-14
    10 
    11 It provides "Clear Shell Window" under "Options"
    12 with ability to undo.
    13 
    14 Add these lines to config-extensions.def
    15 
    16 [ClearWindow]
    17 enable=1
    18 enable_editor=0
    19 enable_shell=1
    20 [ClearWindow_cfgBindings]
    21 clear-window=<Control-Key-l>
    22 
    23 
    24 """
    25 
    26 class ClearWindow:
    27 
    28     menudefs = [
    29         ('options', [None,
    30                ('Clear Shell Window', '<<clear-window>>'),
    31        ]),]
    32          
    33     def __init__(self, editwin):
    34         self.editwin = editwin
    35         self.text = self.editwin.text
    36         self.text.bind("<<clear-window>>", self.clear_window2)
    37 
    38         self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work
    39 
    40     def undo_event(self, event):
    41         text = self.text
    42         
    43         text.mark_set("iomark2", "iomark")
    44         text.mark_set("insert2", "insert")
    45         self.editwin.undo.undo_event(event)
    46 
    47         # fix iomark and insert
    48         text.mark_set("iomark", "iomark2")
    49         text.mark_set("insert", "insert2")
    50         text.mark_unset("iomark2")
    51         text.mark_unset("insert2")
    52         
    53 
    54     def clear_window2(self, event): # Alternative method
    55         # work around the ModifiedUndoDelegator
    56         text = self.text
    57         text.undo_block_start()
    58         text.mark_set("iomark2", "iomark")
    59         text.mark_set("iomark", 1.0)
    60         text.delete(1.0, "iomark2 linestart")
    61         text.mark_set("iomark", "iomark2")
    62         text.mark_unset("iomark2")
    63         text.undo_block_stop()
    64         if self.text.compare('insert', '<', 'iomark'):
    65             self.text.mark_set('insert', 'end-1c')
    66         self.editwin.set_line_and_column()
    67 
    68     def clear_window(self, event):
    69         # remove undo delegator
    70         undo = self.editwin.undo
    71         self.editwin.per.removefilter(undo)
    72 
    73         # clear the window, but preserve current command
    74         self.text.delete(1.0, "iomark linestart")
    75         if self.text.compare('insert', '<', 'iomark'):
    76             self.text.mark_set('insert', 'end-1c')
    77         self.editwin.set_line_and_column()
    78  
    79         # restore undo delegator
    80         self.editwin.per.insertfilter(undo)
    81  

    2.PythonLibidlelib下修改config-extensions.def ,在末尾添加如下内容:

    1[ClearWindow]
    2 enable=1
    3 enable_editor=0
    4 enable_shell=1
    5 [ClearWindow_cfgBindings]
    6 clear-window=<Control-Key-l>

    3.重新Python的IDLE,在options选项中就可以看到增加了Clear shell Window Ctrl+L,即清屏的快捷键为:Ctrl+L

  • 相关阅读:
    Android捕捉错误try catch 的简单使用
    ubuntu下安装lua和tolua++
    mosh安装与使用
    三,温习redis持久化解析与配置
    二,温习redis(工具命令使用)
    一,温习Redis (详解从安装到配置)
    报错!-> CPU100%-但是找不到使用cpu的进程
    linux安全---防火墙(iptables)理论解析
    Mysql8.0版二进制安装(my.cnf文件灵活编写)
    ansible实现template管理nginx
  • 原文地址:https://www.cnblogs.com/xiaomingzaixian/p/6793219.html
Copyright © 2011-2022 走看看