mainmenu.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ('Cu_t', '<<cut>>'),
  40. ('_Copy', '<<copy>>'),
  41. ('_Paste', '<<paste>>'),
  42. ('Select _All', '<<select-all>>'),
  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. ('Go to _Line', '<<goto-line>>'),
  50. ('S_how Completions', '<<force-open-completions>>'),
  51. ('E_xpand Word', '<<expand-word>>'),
  52. ('Show C_all Tip', '<<force-open-calltip>>'),
  53. ('Show Surrounding P_arens', '<<flash-paren>>'),
  54. ]),
  55. ('format', [
  56. ('F_ormat Paragraph', '<<format-paragraph>>'),
  57. ('_Indent Region', '<<indent-region>>'),
  58. ('_Dedent Region', '<<dedent-region>>'),
  59. ('Comment _Out Region', '<<comment-region>>'),
  60. ('U_ncomment Region', '<<uncomment-region>>'),
  61. ('Tabify Region', '<<tabify-region>>'),
  62. ('Untabify Region', '<<untabify-region>>'),
  63. ('Toggle Tabs', '<<toggle-tabs>>'),
  64. ('New Indent Width', '<<change-indentwidth>>'),
  65. ('S_trip Trailing Whitespace', '<<do-rstrip>>'),
  66. ]),
  67. ('run', [
  68. ('R_un Module', '<<run-module>>'),
  69. ('Run... _Customized', '<<run-custom>>'),
  70. ('C_heck Module', '<<check-module>>'),
  71. ('Python Shell', '<<open-python-shell>>'),
  72. ]),
  73. ('shell', [
  74. ('_View Last Restart', '<<view-restart>>'),
  75. ('_Restart Shell', '<<restart-shell>>'),
  76. None,
  77. ('_Previous History', '<<history-previous>>'),
  78. ('_Next History', '<<history-next>>'),
  79. None,
  80. ('_Interrupt Execution', '<<interrupt-execution>>'),
  81. ]),
  82. ('debug', [
  83. ('_Go to File/Line', '<<goto-file-line>>'),
  84. ('!_Debugger', '<<toggle-debugger>>'),
  85. ('_Stack Viewer', '<<open-stack-viewer>>'),
  86. ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
  87. ]),
  88. ('options', [
  89. ('Configure _IDLE', '<<open-config-dialog>>'),
  90. None,
  91. ('Show _Code Context', '<<toggle-code-context>>'),
  92. ('Show _Line Numbers', '<<toggle-line-numbers>>'),
  93. ('_Zoom Height', '<<zoom-height>>'),
  94. ]),
  95. ('window', [
  96. ]),
  97. ('help', [
  98. ('_About IDLE', '<<about-idle>>'),
  99. None,
  100. ('_IDLE Help', '<<help>>'),
  101. ('Python _Docs', '<<python-docs>>'),
  102. ]),
  103. ]
  104. if find_spec('turtledemo'):
  105. menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))
  106. default_keydefs = idleConf.GetCurrentKeySet()
  107. if __name__ == '__main__':
  108. from unittest import main
  109. main('idlelib.idle_test.test_mainmenu', verbosity=2)