mainmenu.py 3.8 KB

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