blob: 795d837d77a860e2fbb178b7db1427f1b3a30c6c [file] [log] [blame]
Guido van Rossumd8d676c1998-10-12 20:57:09 +00001# The first three items of each tupel pertain to the menu bar. All
2# three are None if the item is not to appeat in a menu. Otherwise,
3# the first item is the menu name (in lowercase), the second item is
4# the menu item label; the third item is the keyboard shortcut to be
5# listed in the menu, if any. Menu items are added in the order of
6# their occurrence in this table. An item of the form
7# ("menu", None, None) can be used to insert a separator in the menu.
8#
9# The fourth item, if present is the virtual event; each of the
10# remaining items is an actual key binding for the event. (Thus,
11# items[3:] conveniently forms an argument list for event_add().)
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000012
13win_bindings = [
Guido van Rossumd8d676c1998-10-12 20:57:09 +000014 (None, None, None, "<<beginning-of-line>>", "<Control-a>", "<Home>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000015
Guido van Rossumd8d676c1998-10-12 20:57:09 +000016 (None, None, None, "<<expand-word>>", "<Meta-slash>", "<Alt-slash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000017
Guido van Rossumd8d676c1998-10-12 20:57:09 +000018 (None, None, None, "<<newline-and-indent>>", "<Key-Return>", "<KP_Enter>"),
19 (None, None, None, "<<plain-newline-and-indent>>", "<Control-j>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000020
Guido van Rossumd8d676c1998-10-12 20:57:09 +000021 (None, None, None, "<<interrupt-execution>>", "<Control-c>"),
22 (None, None, None, "<<end-of-file>>", "<Control-d>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000023
Guido van Rossumd8d676c1998-10-12 20:57:09 +000024 (None, None, None, "<<dedent-region>>", "<Control-bracketleft>"),
25 (None, None, None, "<<indent-region>>", "<Control-bracketright>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000026
Guido van Rossumd8d676c1998-10-12 20:57:09 +000027 (None, None, None, "<<comment-region>>", "<Meta-Key-3>", "<Alt-Key-3>"),
28 (None, None, None, "<<uncomment-region>>", "<Meta-Key-4>", "<Alt-Key-4>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000029
Guido van Rossumd8d676c1998-10-12 20:57:09 +000030 (None, None, None, "<<history-previous>>", "<Meta-p>", "<Alt-p>"),
31 (None, None, None, "<<history-next>>", "<Meta-n>", "<Alt-n>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000032
Guido van Rossumd8d676c1998-10-12 20:57:09 +000033 (None, None, None, "<<toggle-auto-coloring>>", "<Control-slash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000034
Guido van Rossumd8d676c1998-10-12 20:57:09 +000035 (None, None, None, "<<close-all-windows>>", "<Control-q>"),
36 (None, None, None, "<<open-new-window>>", "<Control-n>"),
37 (None, None, None, "<<open-window-from-file>>", "<Control-o>"),
38 (None, None, None, "<<save-window>>", "<Control-s>"),
39 (None, None, None, "<<save-window-as-file>>", "<Control-w>"),
40 (None, None, None, "<<save-copy-of-window-as-file>>", "<Meta-w>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000041
Guido van Rossumd8d676c1998-10-12 20:57:09 +000042 (None, None, None, "<<find>>", "<Control-f>"),
43 (None, None, None, "<<find-next>>", "<F3>"),
44 (None, None, None, "<<find-same>>", "<Control-F3>"),
45 (None, None, None, "<<goto-line>>", "<Alt-g>", "<Meta-g>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000046
Guido van Rossumd8d676c1998-10-12 20:57:09 +000047 (None, None, None, "<<undo>>", "<Control-z>"),
48 (None, None, None, "<<redo>>", "<Control-y>"),
49 (None, None, None, "<<dump-undo-state>>", "<Control-backslash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000050]
51
52emacs_bindings = [
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000053
Guido van Rossumd8d676c1998-10-12 20:57:09 +000054 # File menu
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000055
Guido van Rossumd8d676c1998-10-12 20:57:09 +000056 ("file", "New window", "C-x C-n",
57 "<<open-new-window>>", "<Control-x><Control-n>"),
58 ("file", "Open...", "C-x C-f",
59 "<<open-window-from-file>>", "<Control-x><Control-f>"),
Guido van Rossumb3418881998-10-13 03:45:15 +000060 ("file", "Open module...", "C-x C-m",
61 "<<open-module>>", "<Control-x><Control-m>"),
Guido van Rossumd8d676c1998-10-12 20:57:09 +000062 ("file", None, None),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000063
Guido van Rossumd8d676c1998-10-12 20:57:09 +000064 ("file", "Save", "C-x C-s",
65 "<<save-window>>", "<Control-x><Control-s>"),
66 ("file", "Save As...", "C-x C-w",
67 "<<save-window-as-file>>", "<Control-x><Control-w>"),
68 ("file", "Save Copy As...", "C-x w",
69 "<<save-copy-of-window-as-file>>", "<Control-x><w>"),
70 ("file", None, None),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000071
Guido van Rossumd8d676c1998-10-12 20:57:09 +000072 ("file", "Close", "C-x C-0",
73 "<<close-window>>", "<Control-x><Control-0>"),
74 ("file", "Exit", "C-x C-c",
75 "<<close-all-windows>>", "<Control-x><Control-c>"),
76
77 # Edit menu
78
79 ("edit", "Undo", "C-z", "<<undo>>", "<Control-z>"),
80 ("edit", "Redo", "Alt-z", "<<redo>>", "<Alt-z>", "<Meta-z>"),
81 ("edit", None, None),
82
83 ("edit", "Cut", None, "<<Cut>>"),
84 ("edit", "Copy", None, "<<Copy>>"),
85 ("edit", "Paste", None, "<<Paste>>"),
86 ("edit", None, None),
87
88 ("edit", "Find...", "C-s",
89 "<<find>>", "<Control-u><Control-u><Control-s>"),
90 ("edit", "Find next", "C-u C-s",
91 "<<find-next>>", "<Control-u><Control-s>"),
92 ("edit", "Find same", "C-s", "<<find-same>>", "<Control-s>"),
93 ("edit", "Go to line", "Alt-g", "<<goto-line>>", "<Alt-g>", "<Meta-g>"),
94 ("edit", None, None),
95
96 ("edit", "Dedent region", "Ctrl-[", "<<dedent-region>>",
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000097 "<Meta-bracketleft>", "<Alt-bracketleft>", "<Control-bracketleft>"),
Guido van Rossumd8d676c1998-10-12 20:57:09 +000098 ("edit", "Indent region", "Ctrl-]", "<<indent-region>>",
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000099 "<Meta-bracketright>", "<Alt-bracketright>", "<Control-bracketright>"),
100
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000101 ("edit", "Comment out region", "Alt-3",
102 "<<comment-region>>", "<Meta-Key-3>", "<Alt-Key-3>"),
103 ("edit", "Uncomment region", "Alt-4",
104 "<<uncomment-region>>", "<Meta-Key-4>", "<Alt-Key-4>"),
Guido van Rossum219ffde1998-10-12 23:55:10 +0000105
106 # Debug menu
107
108 ("debug", "Go to line from traceback", None, "<<goto-traceback-line>>"),
109 ("debug", "Open stack viewer", None, "<<open-stack-viewer>>"),
110
111 # Help menu
112
113 ("help", "Help...", None, "<<help>>"),
114 ("help", None, None),
115 ("help", "About IDLE...", None, "<<about-idle>>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000116
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000117 # Not in any menu
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000118
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000119 (None, None, None, "<<beginning-of-line>>", "<Control-a>", "<Home>"),
120 (None, None, None, "<<center-insert>>", "<Control-l>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000121
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000122 (None, None, None, "<<expand-word>>", "<Meta-slash>", "<Alt-slash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000123
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000124 (None, None, None, "<<newline-and-indent>>", "<Key-Return>", "<KP_Enter>"),
125 (None, None, None, "<<plain-newline-and-indent>>", "<Control-j>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000126
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000127 (None, None, None, "<<interrupt-execution>>", "<Control-c>"),
128 (None, None, None, "<<end-of-file>>", "<Control-d>"),
129
130 (None, None, None, "<<history-previous>>", "<Meta-p>", "<Alt-p>"),
131 (None, None, None, "<<history-next>>", "<Meta-n>", "<Alt-n>"),
132
133 (None, None, None, "<<toggle-auto-coloring>>", "<Control-slash>"),
134
135 (None, None, None, "<<dump-undo-state>>", "<Control-backslash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000136]
137
138default_bindings = emacs_bindings
139
140def apply_bindings(text, bindings=default_bindings):
141 event_add = text.event_add
142 for args in bindings:
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000143 args = args[3:]
144 if args[1:]:
145 apply(event_add, args)
146
147def fill_menus(text, dict, bindings=default_bindings):
148 # Fill the menus for the given text widget. The dict argument is
149 # a dictionary containing the menus, keyed by their lowercased name.
Guido van Rossum219ffde1998-10-12 23:55:10 +0000150 # Menus that are absent or None are ignored.
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000151 for args in bindings:
152 menu, label, accelerator = args[:3]
153 if not menu:
154 continue
Guido van Rossum219ffde1998-10-12 23:55:10 +0000155 menu = dict.get(menu)
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000156 if not menu:
157 continue
158 if accelerator is None:
159 accelerator = ""
160 args = args[3:]
161 if args:
162 def command(text=text, event=args[0]):
163 text.event_generate(event)
164 menu.add_command(label=label, accelerator=accelerator,
165 command=command)
166 elif label or accelerator:
167 menu.add_command(label=label, accelerator=accelerator)
168 else:
169 menu.add_separator()