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

时间:2015-06-19 09:46:46

标签: python-3.x extension-methods clear

http://bugs.python.org/issue6143

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

我已经搜索并搜索并最终找到了一个看起来可行的解决方案(参见上面的链接),但我是Python的初学者,需要有关如何使其工作的帮助。我已经尝试将评论部分中的代码添加到config-extensions.def文件中,并且还从IDLE运行该文件,但没有"清除屏幕"选项出现在任何菜单上,也不是ctrl + l键盘快捷键。顺便说一句,我在Windows上使用python 3.4。

我实际上非常惊讶甚至感到震惊的是,由于这个原因,此功能并未作为标准包含在内:Python经常被推荐为初学者'语言和初学者(包括我和我打算用这种语言教学的学生一旦我学会了它)被屏幕上的许多不理解的文本所覆盖(语法错误等)我们需要的可能是一个最重要的功能是某种"恐慌按钮"清除混乱,让我们再试一次空白的石板。关闭应用程序重新打开它是严重的过度杀伤,所以我无法理解为什么没有考虑到这一点。如果有人知道要联系谁来改变这一点,我认为值得强调这个问题的重要性,因为它可能真的是一个选择语言用于教育目的的交易破坏。

然而,我在这里主要关心的是获得一些帮助来完成这项工作,这样我就可以继续并有一些有趣的编程!任何帮助非常感谢。

1 个答案:

答案 0 :(得分:0)

好的,我找到了答案(并且需要两位相当有计算机知识的人才能解决这个问题):

将ClearWindow.py的comments部分中的以下代码放入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)
相关问题