python idle清屏快捷键_Python3.5 IDLE配置清屏快捷键

这个博客介绍了ClearShellWindow扩展的实现,它为编辑器提供了清除窗口并具备撤销功能。用户可以在'Options'菜单下找到'ClearShellWindow'选项。代码展示了如何绑定事件来清除文本,以及如何处理撤销操作,确保iomark和insert标记正确设置。
摘要由CSDN通过智能技术生成

copycode.gif

1 """

2

3 Clear Window Extension

4 Version: 0.2

5

6 Author: Roger D. Serwy

7 roger.serwy@gmail.com

8

9 Date: 2009-06-14

10

11 It provides "Clear Shell Window" under "Options"

12 with ability to undo.

13

14 Add these lines to config-extensions.def

15

16 [ClearWindow]

17 enable=1

18 enable_editor=0

19 enable_shell=1

20 [ClearWindow_cfgBindings]

21 clear-window=

22

23

24 """

25

26 class ClearWindow:

27

28 menudefs = [

29 ('options', [None,

30 ('Clear Shell Window', '<>'),

31 ]),]

32

33 def __init__(self, editwin):

34 self.editwin = editwin

35 self.text = self.editwin.text

36 self.text.bind("<>", self.clear_window2)

37

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

39

40 def undo_event(self, event):

41 text = self.text

42

43 text.mark_set("iomark2", "iomark")

44 text.mark_set("insert2", "insert")

45 self.editwin.undo.undo_event(event)

46

47 # fix iomark and insert

48 text.mark_set("iomark", "iomark2")

49 text.mark_set("insert", "insert2")

50 text.mark_unset("iomark2")

51 text.mark_unset("insert2")

52

53

54 def clear_window2(self, event): # Alternative method

55 # work around the ModifiedUndoDelegator

56 text = self.text

57 text.undo_block_start()

58 text.mark_set("iomark2", "iomark")

59 text.mark_set("iomark", 1.0)

60 text.delete(1.0, "iomark2 linestart")

61 text.mark_set("iomark", "iomark2")

62 text.mark_unset("iomark2")

63 text.undo_block_stop()

64 if self.text.compare('insert', '<', 'iomark'):

65 self.text.mark_set('insert', 'end-1c')

66 self.editwin.set_line_and_column()

67

68 def clear_window(self, event):

69 # remove undo delegator

70 undo = self.editwin.undo

71 self.editwin.per.removefilter(undo)

72

73 # clear the window, but preserve current command

74 self.text.delete(1.0, "iomark linestart")

75 if self.text.compare('insert', '<', 'iomark'):

76 self.text.mark_set('insert', 'end-1c')

77 self.editwin.set_line_and_column()

78

79 # restore undo delegator

80 self.editwin.per.insertfilter(undo)

81

copycode.gif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值