如何让这个 Python 扩展在 windows 上工作(清除 IDLE)?

How do I make this Python extension work on windows (clear IDLE)?

http://bugs.python.org/issue6143

我知道类似的问题已被问过一千次,对我来说这表明该问题可以由设计师解决。

我搜索了又搜索,最终找到了一个看起来可行的解决方案(参见上文 link),但我是 Python 的完全初学者,需要有关如何使其工作的帮助。我尝试将注释部分中的代码添加到 config-extensions.def 文件,以及 运行 来自 IDLE 的文件,但是没有 "clear screen" 选项出现在任何菜单上,也没有 ctrl+ l 快捷键。顺便说一句,我在 windows.

上使用 python 3.4

我真的很惊讶甚至震惊,因为这个原因,这个功能没有作为标准包括:Python 经常被推荐为初学者的语言和初学者(包括我和我打算的学生一旦我学会了就教这门语言)被屏幕上很多不理解的文本所淹没(语法错误等)我们需要的可能是最重要的功能之一是某种 "panic button"清理混乱,让我们从头开始再试一次。关闭应用程序并重新打开它是严重的矫枉过正,所以我不明白为什么没有考虑到这一点。如果有人知道要联系谁来更改此内容,我认为非常值得强调这个问题的重要性,因为在选择用于教育目的的语言时它可能真的是一个交易破坏者。

不过,我主要关心的是获得一些帮助来完成这项工作,这样我才能继续进行有趣的编程!非常感谢任何帮助。

好的,我找到了这个问题的答案(两个相当精通计算机的人花了一段时间才算出来):

将ClearWindow.py评论区的以下代码放入config-extensions.def (C:\Python34\Lib\idlelib...)

[ClearWindow]
enable=1
enable_editor=0
enable_shell=1
[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>

接下来,在同一文件夹 (C:\Python34\Lib\idlelib) 中放入整个 ClearWindow.py 文件。哒哒!为方便起见粘贴在下面的文件:

"""

Clear Window Extension
Version: 0.2

Author: Roger D. Serwy
        roger.serwy@gmail.com

Date: 2009-06-14

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)