# 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", "Open module...", "C-x C-m", "<>", ""), ("file", "Class browser...", "C-x C-b", "<>", ""), ("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", "<>", "", ""), # Debug menu ("debug", "Go to line from traceback", None, "<>"), ("debug", "Open stack viewer", None, "<>"), # Help menu ("help", "Help...", None, "<>"), ("help", None, None), ("help", "About IDLE...", None, "<>"), # 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 def apply_bindings(text, bindings=default_bindings): event_add = text.event_add for args in bindings: 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. # Menus that are absent or None are ignored. for args in bindings: menu, label, accelerator = args[:3] if not menu: continue menu = dict.get(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()