From d8d676c289e76171480765eb2e60d1e981c21af2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 12 Oct 1998 20:57:09 +0000 Subject: Add menu configuration to the event configuration. --- Tools/idle/Bindings.py | 183 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 123 insertions(+), 60 deletions(-) diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py index 9e2e791..4f1ddac 100644 --- a/Tools/idle/Bindings.py +++ b/Tools/idle/Bindings.py @@ -1,87 +1,125 @@ -# The first item of each tuple is the virtual event; -# each of the remaining items is an actual key binding for the event. -# (This conveniently forms an argument list for event_add().) +# The first three items of each tupel pertain to the menu bar. All +# three are None if the item is not to appeat in a menu. Otherwise, +# the first item is the menu name (in lowercase), the second item is +# the menu item label; the third item is the keyboard shortcut to be +# listed in the menu, if any. Menu items are added in the order of +# their occurrence in this table. An item of the form +# ("menu", None, None) can be used to insert a separator in the menu. +# +# The fourth item, if present is the virtual event; each of the +# remaining items is an actual key binding for the event. (Thus, +# items[3:] conveniently forms an argument list for event_add().) win_bindings = [ - ("<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", "", ""), - ("<>", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), - ("<>", "", ""), - ("<>", "", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", "", ""), - ("<>", "", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", "", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", "", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), ] emacs_bindings = [ - ("<>", "", ""), - ("<>", ""), - ("<>", "", ""), + # File menu + + ("file", "New window", "C-x C-n", + "<>", ""), + ("file", "Open...", "C-x C-f", + "<>", ""), + ("file", None, None), + + ("file", "Save", "C-x C-s", + "<>", ""), + ("file", "Save As...", "C-x C-w", + "<>", ""), + ("file", "Save Copy As...", "C-x w", + "<>", ""), + ("file", None, None), + + ("file", "Close", "C-x C-0", + "<>", ""), + ("file", "Exit", "C-x C-c", + "<>", ""), + + # Edit menu + + ("edit", "Undo", "C-z", "<>", ""), + ("edit", "Redo", "Alt-z", "<>", "", ""), + ("edit", None, None), + + ("edit", "Cut", None, "<>"), + ("edit", "Copy", None, "<>"), + ("edit", "Paste", None, "<>"), + ("edit", None, None), + + ("edit", "Find...", "C-s", + "<>", ""), + ("edit", "Find next", "C-u C-s", + "<>", ""), + ("edit", "Find same", "C-s", "<>", ""), + ("edit", "Go to line", "Alt-g", "<>", "", ""), + ("edit", None, None), + + ("edit", "Dedent region", "Ctrl-[", "<>", + "", "", ""), + ("edit", "Indent region", "Ctrl-]", "<>", + "", "", ""), - ("<>", "", ""), - ("<>", ""), + ("edit", "Comment out region", "Alt-3", + "<>", "", ""), + ("edit", "Uncomment region", "Alt-4", + "<>", "", ""), - ("<>", ""), - ("<>", ""), + # Not in any menu - ("<>", - "", "", ""), - ("<>", - "", "", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", ""), - ("<>", "", ""), - ("<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", "", ""), - ("<>", "", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", ""), - ("<>", ""), + (None, None, None, "<>", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), + (None, None, None, "<>", "", ""), + (None, None, None, "<>", "", ""), - ("<>", ""), - ("<>", ""), - ("<>", ""), - ("<>", "", ""), + (None, None, None, "<>", ""), - ("<>", ""), - ("<>", "", ""), - ("<>", ""), + (None, None, None, "<>", ""), ] default_bindings = emacs_bindings @@ -89,4 +127,29 @@ default_bindings = emacs_bindings def apply_bindings(text, bindings=default_bindings): event_add = text.event_add for args in bindings: - apply(event_add, args) + args = args[3:] + if args[1:]: + apply(event_add, args) + +def fill_menus(text, dict, bindings=default_bindings): + # Fill the menus for the given text widget. The dict argument is + # a dictionary containing the menus, keyed by their lowercased name. + for args in bindings: + menu, label, accelerator = args[:3] + if not menu: + continue + menu = dict[menu] + if not menu: + continue + if accelerator is None: + accelerator = "" + args = args[3:] + if args: + def command(text=text, event=args[0]): + text.event_generate(event) + menu.add_command(label=label, accelerator=accelerator, + command=command) + elif label or accelerator: + menu.add_command(label=label, accelerator=accelerator) + else: + menu.add_separator() -- cgit v0.12