1"""Define the menu contents, hotkeys, and event bindings.
2
3There is additional configuration information in the EditorWindow class (and
4subclasses): the menus are created there based on the menu_specs (class)
5variable, and menus not created are silently skipped in the code here.  This
6makes it possible, for example, to define a Debug menu which is only present in
7the PythonShell window, and a Format menu which is only present in the Editor
8windows.
9
10"""
11from importlib.util import find_spec
12
13from idlelib.config import idleConf
14
15#   Warning: menudefs is altered in macosx.overrideRootMenu()
16#   after it is determined that an OS X Aqua Tk is in use,
17#   which cannot be done until after Tk() is first called.
18#   Do not alter the 'file', 'options', or 'help' cascades here
19#   without altering overrideRootMenu() as well.
20#       TODO: Make this more robust
21
22menudefs = [
23 # underscore prefixes character to underscore
24 ('file', [
25   ('_New File', '<<open-new-window>>'),
26   ('_Open...', '<<open-window-from-file>>'),
27   ('Open _Module...', '<<open-module>>'),
28   ('Module _Browser', '<<open-class-browser>>'),
29   ('_Path Browser', '<<open-path-browser>>'),
30   None,
31   ('_Save', '<<save-window>>'),
32   ('Save _As...', '<<save-window-as-file>>'),
33   ('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
34   None,
35   ('Prin_t Window', '<<print-window>>'),
36   None,
37   ('_Close', '<<close-window>>'),
38   ('E_xit', '<<close-all-windows>>'),
39   ]),
40
41 ('edit', [
42   ('_Undo', '<<undo>>'),
43   ('_Redo', '<<redo>>'),
44   None,
45   ('Cu_t', '<<cut>>'),
46   ('_Copy', '<<copy>>'),
47   ('_Paste', '<<paste>>'),
48   ('Select _All', '<<select-all>>'),
49   None,
50   ('_Find...', '<<find>>'),
51   ('Find A_gain', '<<find-again>>'),
52   ('Find _Selection', '<<find-selection>>'),
53   ('Find in Files...', '<<find-in-files>>'),
54   ('R_eplace...', '<<replace>>'),
55   ('Go to _Line', '<<goto-line>>'),
56   ('S_how Completions', '<<force-open-completions>>'),
57   ('E_xpand Word', '<<expand-word>>'),
58   ('Show C_all Tip', '<<force-open-calltip>>'),
59   ('Show Surrounding P_arens', '<<flash-paren>>'),
60   ]),
61
62 ('format', [
63   ('F_ormat Paragraph', '<<format-paragraph>>'),
64   ('_Indent Region', '<<indent-region>>'),
65   ('_Dedent Region', '<<dedent-region>>'),
66   ('Comment _Out Region', '<<comment-region>>'),
67   ('U_ncomment Region', '<<uncomment-region>>'),
68   ('Tabify Region', '<<tabify-region>>'),
69   ('Untabify Region', '<<untabify-region>>'),
70   ('Toggle Tabs', '<<toggle-tabs>>'),
71   ('New Indent Width', '<<change-indentwidth>>'),
72   ('S_trip Trailing Whitespace', '<<do-rstrip>>'),
73   ]),
74
75 ('run', [
76   ('R_un Module', '<<run-module>>'),
77   ('Run... _Customized', '<<run-custom>>'),
78   ('C_heck Module', '<<check-module>>'),
79   ('Python Shell', '<<open-python-shell>>'),
80   ]),
81
82 ('shell', [
83   ('_View Last Restart', '<<view-restart>>'),
84   ('_Restart Shell', '<<restart-shell>>'),
85   None,
86   ('_Previous History', '<<history-previous>>'),
87   ('_Next History', '<<history-next>>'),
88   None,
89   ('_Interrupt Execution', '<<interrupt-execution>>'),
90   ]),
91
92 ('debug', [
93   ('_Go to File/Line', '<<goto-file-line>>'),
94   ('!_Debugger', '<<toggle-debugger>>'),
95   ('_Stack Viewer', '<<open-stack-viewer>>'),
96   ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
97   ]),
98
99 ('options', [
100   ('Configure _IDLE', '<<open-config-dialog>>'),
101   None,
102   ('Show _Code Context', '<<toggle-code-context>>'),
103   ('Show _Line Numbers', '<<toggle-line-numbers>>'),
104   ('_Zoom Height', '<<zoom-height>>'),
105   ]),
106
107 ('window', [
108   ]),
109
110 ('help', [
111   ('_About IDLE', '<<about-idle>>'),
112   None,
113   ('_IDLE Help', '<<help>>'),
114   ('Python _Docs', '<<python-docs>>'),
115   ]),
116]
117
118if find_spec('turtledemo'):
119    menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
120
121default_keydefs = idleConf.GetCurrentKeySet()
122
123if __name__ == '__main__':
124    from unittest import main
125    main('idlelib.idle_test.test_mainmenu', verbosity=2)
126