Home | History | Annotate | Download | only in idlelib
      1 """Define the menu contents, hotkeys, and event bindings.
      2 
      3 There is additional configuration information in the EditorWindow class (and
      4 subclasses): the menus are created there based on the menu_specs (class)
      5 variable, and menus not created are silently skipped in the code here.  This
      6 makes it possible, for example, to define a Debug menu which is only present in
      7 the PythonShell window, and a Format menu which is only present in the Editor
      8 windows.
      9 
     10 """
     11 from importlib.util import find_spec
     12 
     13 from 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 
     22 menudefs = [
     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    ('_Indent Region', '<<indent-region>>'),
     64    ('_Dedent Region', '<<dedent-region>>'),
     65    ('Comment _Out Region', '<<comment-region>>'),
     66    ('U_ncomment Region', '<<uncomment-region>>'),
     67    ('Tabify Region', '<<tabify-region>>'),
     68    ('Untabify Region', '<<untabify-region>>'),
     69    ('Toggle Tabs', '<<toggle-tabs>>'),
     70    ('New Indent Width', '<<change-indentwidth>>'),
     71    ('F_ormat Paragraph', '<<format-paragraph>>'),
     72    ('S_trip Trailing Whitespace', '<<do-rstrip>>'),
     73    ]),
     74 
     75  ('run', [
     76    ('Python Shell', '<<open-python-shell>>'),
     77    ('C_heck Module', '<<check-module>>'),
     78    ('R_un Module', '<<run-module>>'),
     79    ]),
     80 
     81  ('shell', [
     82    ('_View Last Restart', '<<view-restart>>'),
     83    ('_Restart Shell', '<<restart-shell>>'),
     84    None,
     85    ('_Previous History', '<<history-previous>>'),
     86    ('_Next History', '<<history-next>>'),
     87    None,
     88    ('_Interrupt Execution', '<<interrupt-execution>>'),
     89    ]),
     90 
     91  ('debug', [
     92    ('_Go to File/Line', '<<goto-file-line>>'),
     93    ('!_Debugger', '<<toggle-debugger>>'),
     94    ('_Stack Viewer', '<<open-stack-viewer>>'),
     95    ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
     96    ]),
     97 
     98  ('options', [
     99    ('Configure _IDLE', '<<open-config-dialog>>'),
    100    None,
    101    ('Show _Code Context', '<<toggle-code-context>>'),
    102    ('Zoom Height', '<<zoom-height>>'),
    103    ]),
    104 
    105  ('window', [
    106    ]),
    107 
    108  ('help', [
    109    ('_About IDLE', '<<about-idle>>'),
    110    None,
    111    ('_IDLE Help', '<<help>>'),
    112    ('Python _Docs', '<<python-docs>>'),
    113    ]),
    114 ]
    115 
    116 if find_spec('turtledemo'):
    117     menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
    118 
    119 default_keydefs = idleConf.GetCurrentKeySet()
    120 
    121 if __name__ == '__main__':
    122     from unittest import main
    123     main('idlelib.idle_test.test_mainmenu', verbosity=2)
    124