blob: 4f833c67b3dbb7f6941728afcbbeac9a723c9a25 [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>"),
60 ("file", None, None),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000061
Guido van Rossumd8d676c1998-10-12 20:57:09 +000062 ("file", "Save", "C-x C-s",
63 "<<save-window>>", "<Control-x><Control-s>"),
64 ("file", "Save As...", "C-x C-w",
65 "<<save-window-as-file>>", "<Control-x><Control-w>"),
66 ("file", "Save Copy As...", "C-x w",
67 "<<save-copy-of-window-as-file>>", "<Control-x><w>"),
68 ("file", None, None),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000069
Guido van Rossumd8d676c1998-10-12 20:57:09 +000070 ("file", "Close", "C-x C-0",
71 "<<close-window>>", "<Control-x><Control-0>"),
72 ("file", "Exit", "C-x C-c",
73 "<<close-all-windows>>", "<Control-x><Control-c>"),
74
75 # Edit menu
76
77 ("edit", "Undo", "C-z", "<<undo>>", "<Control-z>"),
78 ("edit", "Redo", "Alt-z", "<<redo>>", "<Alt-z>", "<Meta-z>"),
79 ("edit", None, None),
80
81 ("edit", "Cut", None, "<<Cut>>"),
82 ("edit", "Copy", None, "<<Copy>>"),
83 ("edit", "Paste", None, "<<Paste>>"),
84 ("edit", None, None),
85
86 ("edit", "Find...", "C-s",
87 "<<find>>", "<Control-u><Control-u><Control-s>"),
88 ("edit", "Find next", "C-u C-s",
89 "<<find-next>>", "<Control-u><Control-s>"),
90 ("edit", "Find same", "C-s", "<<find-same>>", "<Control-s>"),
91 ("edit", "Go to line", "Alt-g", "<<goto-line>>", "<Alt-g>", "<Meta-g>"),
92 ("edit", None, None),
93
94 ("edit", "Dedent region", "Ctrl-[", "<<dedent-region>>",
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000095 "<Meta-bracketleft>", "<Alt-bracketleft>", "<Control-bracketleft>"),
Guido van Rossumd8d676c1998-10-12 20:57:09 +000096 ("edit", "Indent region", "Ctrl-]", "<<indent-region>>",
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +000097 "<Meta-bracketright>", "<Alt-bracketright>", "<Control-bracketright>"),
98
Guido van Rossumd8d676c1998-10-12 20:57:09 +000099 ("edit", "Comment out region", "Alt-3",
100 "<<comment-region>>", "<Meta-Key-3>", "<Alt-Key-3>"),
101 ("edit", "Uncomment region", "Alt-4",
102 "<<uncomment-region>>", "<Meta-Key-4>", "<Alt-Key-4>"),
Guido van Rossum219ffde1998-10-12 23:55:10 +0000103
104 # Debug menu
105
106 ("debug", "Go to line from traceback", None, "<<goto-traceback-line>>"),
107 ("debug", "Open stack viewer", None, "<<open-stack-viewer>>"),
108
109 # Help menu
110
111 ("help", "Help...", None, "<<help>>"),
112 ("help", None, None),
113 ("help", "About IDLE...", None, "<<about-idle>>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000114
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000115 # Not in any menu
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000116
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000117 (None, None, None, "<<beginning-of-line>>", "<Control-a>", "<Home>"),
118 (None, None, None, "<<center-insert>>", "<Control-l>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000119
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000120 (None, None, None, "<<expand-word>>", "<Meta-slash>", "<Alt-slash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000121
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000122 (None, None, None, "<<newline-and-indent>>", "<Key-Return>", "<KP_Enter>"),
123 (None, None, None, "<<plain-newline-and-indent>>", "<Control-j>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000124
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000125 (None, None, None, "<<interrupt-execution>>", "<Control-c>"),
126 (None, None, None, "<<end-of-file>>", "<Control-d>"),
127
128 (None, None, None, "<<history-previous>>", "<Meta-p>", "<Alt-p>"),
129 (None, None, None, "<<history-next>>", "<Meta-n>", "<Alt-n>"),
130
131 (None, None, None, "<<toggle-auto-coloring>>", "<Control-slash>"),
132
133 (None, None, None, "<<dump-undo-state>>", "<Control-backslash>"),
Guido van Rossum3b4ca0d1998-10-10 18:48:31 +0000134]
135
136default_bindings = emacs_bindings
137
138def apply_bindings(text, bindings=default_bindings):
139 event_add = text.event_add
140 for args in bindings:
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000141 args = args[3:]
142 if args[1:]:
143 apply(event_add, args)
144
145def fill_menus(text, dict, bindings=default_bindings):
146 # Fill the menus for the given text widget. The dict argument is
147 # a dictionary containing the menus, keyed by their lowercased name.
Guido van Rossum219ffde1998-10-12 23:55:10 +0000148 # Menus that are absent or None are ignored.
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000149 for args in bindings:
150 menu, label, accelerator = args[:3]
151 if not menu:
152 continue
Guido van Rossum219ffde1998-10-12 23:55:10 +0000153 menu = dict.get(menu)
Guido van Rossumd8d676c1998-10-12 20:57:09 +0000154 if not menu:
155 continue
156 if accelerator is None:
157 accelerator = ""
158 args = args[3:]
159 if args:
160 def command(text=text, event=args[0]):
161 text.event_generate(event)
162 menu.add_command(label=label, accelerator=accelerator,
163 command=command)
164 elif label or accelerator:
165 menu.add_command(label=label, accelerator=accelerator)
166 else:
167 menu.add_separator()