Python 3.x 如何使此Python扩展在windows上工作(清除空闲)?

Python 3.x 如何使此Python扩展在windows上工作(清除空闲)?,python-3.x,extension-methods,Python 3.x,Extension Methods,我知道类似的问题已经被问了一千次,这对我来说意味着这个问题可能与设计师的解决有关 我搜索了又搜索,终于找到了一个看起来可行的解决方案(见上面的链接),但我是Python的完全初学者,需要帮助了解如何让它工作。我尝试将注释部分中的代码添加到config-extensions.def文件中,并从空闲状态运行该文件,但任何菜单上都没有“清除屏幕”选项,也没有ctrl+l键盘快捷键。顺便说一句,我在windows上使用的是python 3.4 事实上,我非常惊讶,甚至感到震惊的是,由于这个原因,这个功能

我知道类似的问题已经被问了一千次,这对我来说意味着这个问题可能与设计师的解决有关

我搜索了又搜索,终于找到了一个看起来可行的解决方案(见上面的链接),但我是Python的完全初学者,需要帮助了解如何让它工作。我尝试将注释部分中的代码添加到config-extensions.def文件中,并从空闲状态运行该文件,但任何菜单上都没有“清除屏幕”选项,也没有ctrl+l键盘快捷键。顺便说一句,我在windows上使用的是python 3.4

事实上,我非常惊讶,甚至感到震惊的是,由于这个原因,这个功能没有被列为标准:Python经常被推荐为初学者的语言,而初学者(包括我和我打算在学完这门语言后教给他们的学生)会被屏幕上大量无法理解的文本淹没(语法错误等)我们需要的可能是最重要的功能之一是某种“紧急按钮”为了收拾残局,让我们白纸黑字地再试一次。关闭应用程序并重新打开它是严重的过火行为,因此我无法理解为什么没有考虑到这一点。如果有人知道要联系谁来改变它,我认为非常值得强调这一问题的重要性,因为它可能真的会成为选择新应用程序的破坏者用于教育目的的语言


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

好的,我找到了答案(两个相当懂电脑的人花了一段时间才解决):

将以下代码从ClearWindow.py的comments部分放入config-extensions.def(C:\Python34\Lib\idlelib…)

[ClearWindow]
启用=1
启用\u编辑器=0
启用\u shell=1
[ClearWindow\u cfgBindings]
清除窗口=
接下来,在同一文件夹(C:\Python34\Lib\idlelib)中,将整个ClearWindow.py文件.Ta Da!文件粘贴到下面以方便使用:

"""

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)
“”“
清除窗口扩展
版本:0.2
作者:Roger D.Serwy
罗杰。serwy@gmail.com
日期:2009-06-14
它在“选项”下提供“清除外壳窗口”
具有撤销的能力。
将这些行添加到config-extensions.def
[透明窗口]
启用=1
启用\u编辑器=0
启用\u shell=1
[ClearWindow\u cfgBindings]
清除窗口=
"""
类ClearWindow:
菜单项=[
(‘选项’,[None,
(‘透明壳窗’,“”),
]),]
定义初始化(self,editwin):
self.editwin=editwin
self.text=self.editwin.text
self.text.bind(“,self.clear\u window2)
self.text.bind(“,self.undo_事件)#add=“+”不起作用
def undo_事件(自身、事件):
text=self.text
文本标记集(“iomark2”、“iomark”)
文本标记集(“插入2”、“插入”)
self.editwin.undo.undo_事件(事件)
#固定标记并插入
文本标记集(“iomark”、“iomark2”)
文本。标记集(“插入”、“插入2”)
文本。标记未设置(“iomark2”)
text.mark_unset(“insert2”)
def清除窗口2(自身、事件):#替代方法
#围绕修改后的DundoDelegator工作
text=self.text
text.undo_block_start()
文本标记集(“iomark2”、“iomark”)
文本标记集(“iomark”,1.0)
文本。删除(1.0,“iomark2行开始”)
文本标记集(“iomark”、“iomark2”)
文本。标记未设置(“iomark2”)
text.undo_block_stop()
如果self.text.compare('insert','
"""

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)