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

问题描述 投票:0回答:1

http:/bugs.python.orgissue6143

我知道类似的问题已经被问过上千次了,对我来说,这说明这个问题可以由设计者来解决。

我找了又找,终于找到了一个看起来可行的解决方案 (见上面的链接),但我是一个完全的Python初学者,需要帮助我如何让它工作。我试过将注释部分的代码添加到config-extensions.def文件中,也试过从IDLE运行该文件,但任何菜单上都没有出现 "清屏 "选项,ctrl+l键盘快捷键也没有。另外,我在windows上使用python 3.4。

其实我非常惊讶,甚至震惊,因为这个原因,这个功能没有作为标准配置。Python 通常被推荐为初学者的语言,而初学者 (包括我和我打算教的学生)会被屏幕上大量不理解的文本 (语法错误等) 所困扰,我们需要的可能是某种 "紧急按钮 "来清除这些混乱,让我们在一片空白的情况下再次尝试。关闭应用程序并重新打开它是严重的矫枉过正,所以我无法理解为什么没有考虑这个问题。如果有谁知道该联系谁来改变这个问题,我认为是非常值得强调这个问题的重要性,因为它可能真的是一个为教育目的选择语言的决定性因素。

然而,我在这里主要关注的是得到一些帮助,使这个工作,所以我可以得到和有一些有趣的编程!任何帮助非常感激。任何帮助,非常感激。

python-3.x extension-methods
1个回答
0
投票

好吧,我找到了答案(花了两个相当懂电脑的人的时间才弄明白)。

把以下代码从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文件。Ta Da! 为方便起见,文件粘贴在下面。

"""

Clear Window Extension
Version: 0.2

Author: Roger D. Serwy
        [email protected]

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)
© www.soinside.com 2019 - 2024. All rights reserved.