鱼C论坛

 找回密码
 立即注册
查看: 2113|回复: 8

[已解决]关于python中shell清屏快捷键的设置

[复制链接]
发表于 2020-5-13 23:06:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
求助,我的这个文件 (config-extensions.def) 和动图里面的那个不一样,然后按着他那个步骤来的,结果没反应

https://fishc.com.cn/thread-45441-1-1.html  

这个链接是我看的教程,

有会的大佬可以教我一下不


ps: 现在等级低,发不了图,为了刷点积分还被管理员搞了一波。

难受,下次不混水贴了
最佳答案
2020-5-15 11:07:01
python目录下的 lib\idlelib 的文件夹下 新建文件名为 ClearWindow.py 保存
  1. """

  2. Clear Window Extension
  3. Version: 0.2

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

  6. Date: 2009-06-14

  7. It provides "Clear Shell Window" under "Options"
  8. with ability to undo.

  9. Add these lines to config-extensions.def

  10. [ClearWindow]
  11. enable=1
  12. enable_editor=0
  13. enable_shell=1
  14. [ClearWindow_cfgBindings]
  15. clear-window=<Control-Key-l>


  16. """


  17. class ClearWindow:
  18.     menudefs = [
  19.         ('options', [None,
  20.                      ('Clear Shell Window', '<<clear-window>>'),
  21.                      ]), ]

  22.     def __init__(self, editwin):
  23.         self.editwin = editwin
  24.         self.text = self.editwin.text
  25.         self.text.bind("<<clear-window>>", self.clear_window2)

  26.         self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work

  27.     def undo_event(self, event):
  28.         text = self.text

  29.         text.mark_set("iomark2", "iomark")
  30.         text.mark_set("insert2", "insert")
  31.         self.editwin.undo.undo_event(event)

  32.         # fix iomark and insert
  33.         text.mark_set("iomark", "iomark2")
  34.         text.mark_set("insert", "insert2")
  35.         text.mark_unset("iomark2")
  36.         text.mark_unset("insert2")

  37.     def clear_window2(self, event):  # Alternative method
  38.         # work around the ModifiedUndoDelegator
  39.         text = self.text
  40.         text.undo_block_start()
  41.         text.mark_set("iomark2", "iomark")
  42.         text.mark_set("iomark", 1.0)
  43.         text.delete(1.0, "iomark2 linestart")
  44.         text.mark_set("iomark", "iomark2")
  45.         text.mark_unset("iomark2")
  46.         text.undo_block_stop()
  47.         if self.text.compare('insert', '<', 'iomark'):
  48.             self.text.mark_set('insert', 'end-1c')
  49.         self.editwin.set_line_and_column()

  50.     def clear_window(self, event):
  51.         # remove undo delegator
  52.         undo = self.editwin.undo
  53.         self.editwin.per.removefilter(undo)

  54.         # clear the window, but preserve current command
  55.         self.text.delete(1.0, "iomark linestart")
  56.         if self.text.compare('insert', '<', 'iomark'):
  57.             self.text.mark_set('insert', 'end-1c')
  58.         self.editwin.set_line_and_column()

  59.         # restore undo delegator
  60.         self.editwin.per.insertfilter(undo)
复制代码

python目录下的 lib\idlelib文件夹下,用记事本打开文件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>
复制代码


你是这样弄的嘛?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-14 07:56:57 | 显示全部楼层
可以将图片上传到 图床 再把链接发到论坛上。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2020-5-15 11:07:01 | 显示全部楼层    本楼为最佳答案   
python目录下的 lib\idlelib 的文件夹下 新建文件名为 ClearWindow.py 保存
  1. """

  2. Clear Window Extension
  3. Version: 0.2

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

  6. Date: 2009-06-14

  7. It provides "Clear Shell Window" under "Options"
  8. with ability to undo.

  9. Add these lines to config-extensions.def

  10. [ClearWindow]
  11. enable=1
  12. enable_editor=0
  13. enable_shell=1
  14. [ClearWindow_cfgBindings]
  15. clear-window=<Control-Key-l>


  16. """


  17. class ClearWindow:
  18.     menudefs = [
  19.         ('options', [None,
  20.                      ('Clear Shell Window', '<<clear-window>>'),
  21.                      ]), ]

  22.     def __init__(self, editwin):
  23.         self.editwin = editwin
  24.         self.text = self.editwin.text
  25.         self.text.bind("<<clear-window>>", self.clear_window2)

  26.         self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work

  27.     def undo_event(self, event):
  28.         text = self.text

  29.         text.mark_set("iomark2", "iomark")
  30.         text.mark_set("insert2", "insert")
  31.         self.editwin.undo.undo_event(event)

  32.         # fix iomark and insert
  33.         text.mark_set("iomark", "iomark2")
  34.         text.mark_set("insert", "insert2")
  35.         text.mark_unset("iomark2")
  36.         text.mark_unset("insert2")

  37.     def clear_window2(self, event):  # Alternative method
  38.         # work around the ModifiedUndoDelegator
  39.         text = self.text
  40.         text.undo_block_start()
  41.         text.mark_set("iomark2", "iomark")
  42.         text.mark_set("iomark", 1.0)
  43.         text.delete(1.0, "iomark2 linestart")
  44.         text.mark_set("iomark", "iomark2")
  45.         text.mark_unset("iomark2")
  46.         text.undo_block_stop()
  47.         if self.text.compare('insert', '<', 'iomark'):
  48.             self.text.mark_set('insert', 'end-1c')
  49.         self.editwin.set_line_and_column()

  50.     def clear_window(self, event):
  51.         # remove undo delegator
  52.         undo = self.editwin.undo
  53.         self.editwin.per.removefilter(undo)

  54.         # clear the window, but preserve current command
  55.         self.text.delete(1.0, "iomark linestart")
  56.         if self.text.compare('insert', '<', 'iomark'):
  57.             self.text.mark_set('insert', 'end-1c')
  58.         self.editwin.set_line_and_column()

  59.         # restore undo delegator
  60.         self.editwin.per.insertfilter(undo)
复制代码

python目录下的 lib\idlelib文件夹下,用记事本打开文件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>
复制代码


你是这样弄的嘛?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-5-15 14:20:39 | 显示全部楼层
谢了,已经解决了
ClearWindow.py这个文件没有弄,原来的那个帖子下面只是提到了这个文件,没给代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-5-15 14:25:57 | 显示全部楼层
雷梅黛丝 发表于 2020-5-15 14:20
谢了,已经解决了
ClearWindow.py这个文件没有弄,原来的那个帖子下面只是提到了这个文件,没给代码

噢噢 好的,以后建议去python交流区板块问,会有更多人解答的~~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-5-15 14:50:56 | 显示全部楼层
Twilight6 发表于 2020-5-15 14:25
噢噢 好的,以后建议去python交流区板块问,会有更多人解答的~~

我刚来,没权限
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-5-15 15:24:48 | 显示全部楼层


交流板块,不是课后作业的板块

https://fishc.com.cn/forum-173-1.html
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-5-16 06:27:43 | 显示全部楼层
Twilight6 发表于 2020-5-15 15:24
交流板块,不是课后作业的板块

https://fishc.com.cn/forum-173-1.html

好的,谢了啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-5-16 08:17:59 | 显示全部楼层

没事 嘿嘿~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 12:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表