Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 1 | # 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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 12 | |
| 13 | win_bindings = [ |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 14 | (None, None, None, "<<beginning-of-line>>", "<Control-a>", "<Home>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 15 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 16 | (None, None, None, "<<expand-word>>", "<Meta-slash>", "<Alt-slash>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 17 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 18 | (None, None, None, "<<newline-and-indent>>", "<Key-Return>", "<KP_Enter>"), |
| 19 | (None, None, None, "<<plain-newline-and-indent>>", "<Control-j>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 20 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 21 | (None, None, None, "<<interrupt-execution>>", "<Control-c>"), |
| 22 | (None, None, None, "<<end-of-file>>", "<Control-d>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 23 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 24 | (None, None, None, "<<dedent-region>>", "<Control-bracketleft>"), |
| 25 | (None, None, None, "<<indent-region>>", "<Control-bracketright>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 27 | (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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 30 | (None, None, None, "<<history-previous>>", "<Meta-p>", "<Alt-p>"), |
| 31 | (None, None, None, "<<history-next>>", "<Meta-n>", "<Alt-n>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 33 | (None, None, None, "<<toggle-auto-coloring>>", "<Control-slash>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 35 | (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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 42 | (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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 47 | (None, None, None, "<<undo>>", "<Control-z>"), |
| 48 | (None, None, None, "<<redo>>", "<Control-y>"), |
| 49 | (None, None, None, "<<dump-undo-state>>", "<Control-backslash>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 50 | ] |
| 51 | |
| 52 | emacs_bindings = [ |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 53 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 54 | # File menu |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 55 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 56 | ("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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 61 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 62 | ("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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 69 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 70 | ("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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 95 | "<Meta-bracketleft>", "<Alt-bracketleft>", "<Control-bracketleft>"), |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 96 | ("edit", "Indent region", "Ctrl-]", "<<indent-region>>", |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 97 | "<Meta-bracketright>", "<Alt-bracketright>", "<Control-bracketright>"), |
| 98 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 99 | ("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 Rossum | 219ffde | 1998-10-12 23:55:10 +0000 | [diff] [blame^] | 103 | |
| 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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 114 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 115 | # Not in any menu |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 116 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 117 | (None, None, None, "<<beginning-of-line>>", "<Control-a>", "<Home>"), |
| 118 | (None, None, None, "<<center-insert>>", "<Control-l>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 119 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 120 | (None, None, None, "<<expand-word>>", "<Meta-slash>", "<Alt-slash>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 121 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 122 | (None, None, None, "<<newline-and-indent>>", "<Key-Return>", "<KP_Enter>"), |
| 123 | (None, None, None, "<<plain-newline-and-indent>>", "<Control-j>"), |
Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 124 | |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 125 | (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 Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 134 | ] |
| 135 | |
| 136 | default_bindings = emacs_bindings |
| 137 | |
| 138 | def apply_bindings(text, bindings=default_bindings): |
| 139 | event_add = text.event_add |
| 140 | for args in bindings: |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 141 | args = args[3:] |
| 142 | if args[1:]: |
| 143 | apply(event_add, args) |
| 144 | |
| 145 | def 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 Rossum | 219ffde | 1998-10-12 23:55:10 +0000 | [diff] [blame^] | 148 | # Menus that are absent or None are ignored. |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 149 | for args in bindings: |
| 150 | menu, label, accelerator = args[:3] |
| 151 | if not menu: |
| 152 | continue |
Guido van Rossum | 219ffde | 1998-10-12 23:55:10 +0000 | [diff] [blame^] | 153 | menu = dict.get(menu) |
Guido van Rossum | d8d676c | 1998-10-12 20:57:09 +0000 | [diff] [blame] | 154 | 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() |