mainmenu.py 3.73 KB
Newer Older
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
1
"""Define the menu contents, hotkeys, and event bindings.
David Scherer's avatar
David Scherer committed
2

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
3 4 5 6 7 8 9 10
There is additional configuration information in the EditorWindow class (and
subclasses): the menus are created there based on the menu_specs (class)
variable, and menus not created are silently skipped in the code here.  This
makes it possible, for example, to define a Debug menu which is only present in
the PythonShell window, and a Format menu which is only present in the Editor
windows.

"""
11 12
from importlib.util import find_spec

13
from idlelib.config import idleConf
14

15
#   Warning: menudefs is altered in macosx.overrideRootMenu()
16 17 18 19 20
#   after it is determined that an OS X Aqua Tk is in use,
#   which cannot be done until after Tk() is first called.
#   Do not alter the 'file', 'options', or 'help' cascades here
#   without altering overrideRootMenu() as well.
#       TODO: Make this more robust
David Scherer's avatar
David Scherer committed
21 22 23 24

menudefs = [
 # underscore prefixes character to underscore
 ('file', [
25
   ('_New File', '<<open-new-window>>'),
David Scherer's avatar
David Scherer committed
26
   ('_Open...', '<<open-window-from-file>>'),
27
   ('Open _Module...', '<<open-module>>'),
28
   ('Module _Browser', '<<open-class-browser>>'),
29
   ('_Path Browser', '<<open-path-browser>>'),
David Scherer's avatar
David Scherer committed
30 31 32
   None,
   ('_Save', '<<save-window>>'),
   ('Save _As...', '<<save-window-as-file>>'),
33
   ('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
David Scherer's avatar
David Scherer committed
34
   None,
35
   ('Prin_t Window', '<<print-window>>'),
36
   None,
David Scherer's avatar
David Scherer committed
37 38
   ('_Close', '<<close-window>>'),
   ('E_xit', '<<close-all-windows>>'),
39 40
   ]),

David Scherer's avatar
David Scherer committed
41 42 43 44
 ('edit', [
   ('_Undo', '<<undo>>'),
   ('_Redo', '<<redo>>'),
   None,
45 46 47
   ('Cu_t', '<<cut>>'),
   ('_Copy', '<<copy>>'),
   ('_Paste', '<<paste>>'),
David Scherer's avatar
David Scherer committed
48
   ('Select _All', '<<select-all>>'),
49 50
   None,
   ('_Find...', '<<find>>'),
51 52
   ('Find A_gain', '<<find-again>>'),
   ('Find _Selection', '<<find-selection>>'),
53 54
   ('Find in Files...', '<<find-in-files>>'),
   ('R_eplace...', '<<replace>>'),
55
   ('Go to _Line', '<<goto-line>>'),
56 57 58 59
   ('S_how Completions', '<<force-open-completions>>'),
   ('E_xpand Word', '<<expand-word>>'),
   ('Show C_all Tip', '<<force-open-calltip>>'),
   ('Show Surrounding P_arens', '<<flash-paren>>'),
60
   ]),
61

62
 ('format', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
63 64 65 66 67 68 69 70
   ('_Indent Region', '<<indent-region>>'),
   ('_Dedent Region', '<<dedent-region>>'),
   ('Comment _Out Region', '<<comment-region>>'),
   ('U_ncomment Region', '<<uncomment-region>>'),
   ('Tabify Region', '<<tabify-region>>'),
   ('Untabify Region', '<<untabify-region>>'),
   ('Toggle Tabs', '<<toggle-tabs>>'),
   ('New Indent Width', '<<change-indentwidth>>'),
71 72
   ('F_ormat Paragraph', '<<format-paragraph>>'),
   ('S_trip Trailing Whitespace', '<<do-rstrip>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
73
   ]),
74

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
75
 ('run', [
76
   ('Python Shell', '<<open-python-shell>>'),
77 78
   ('C_heck Module', '<<check-module>>'),
   ('R_un Module', '<<run-module>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
79
   ]),
80

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
81 82 83
 ('shell', [
   ('_View Last Restart', '<<view-restart>>'),
   ('_Restart Shell', '<<restart-shell>>'),
84
   None,
85 86 87
   ('_Previous History', '<<history-previous>>'),
   ('_Next History', '<<history-next>>'),
   None,
88
   ('_Interrupt Execution', '<<interrupt-execution>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
89
   ]),
90

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
91
 ('debug', [
92
   ('_Go to File/Line', '<<goto-file-line>>'),
David Scherer's avatar
David Scherer committed
93
   ('!_Debugger', '<<toggle-debugger>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
94
   ('_Stack Viewer', '<<open-stack-viewer>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
95 96
   ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
   ]),
97

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
98
 ('options', [
99
   ('Configure _IDLE', '<<open-config-dialog>>'),
100 101 102
   None,
   ('Show _Code Context', '<<toggle-code-context>>'),
   ('Zoom Height', '<<zoom-height>>'),
103
   ]),
104

105
 ('window', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
106
   ]),
107

David Scherer's avatar
David Scherer committed
108
 ('help', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
109
   ('_About IDLE', '<<about-idle>>'),
David Scherer's avatar
David Scherer committed
110
   None,
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
111 112
   ('_IDLE Help', '<<help>>'),
   ('Python _Docs', '<<python-docs>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
113
   ]),
David Scherer's avatar
David Scherer committed
114 115
]

116 117 118
if find_spec('turtledemo'):
    menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))

119
default_keydefs = idleConf.GetCurrentKeySet()
120 121 122 123

if __name__ == '__main__':
    from unittest import main
    main('idlelib.idle_test.test_mainmenu', verbosity=2)