/Lib/idlelib/Bindings.py

http://unladen-swallow.googlecode.com/ · Python · 111 lines · 84 code · 9 blank · 18 comment · 1 complexity · ddc75071f1c878191b77983ca0f40c78 MD5 · raw file

  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. import sys
  10. from configHandler import idleConf
  11. import macosxSupport
  12. menudefs = [
  13. # underscore prefixes character to underscore
  14. ('file', [
  15. ('_New Window', '<<open-new-window>>'),
  16. ('_Open...', '<<open-window-from-file>>'),
  17. ('Open _Module...', '<<open-module>>'),
  18. ('Class _Browser', '<<open-class-browser>>'),
  19. ('_Path Browser', '<<open-path-browser>>'),
  20. None,
  21. ('_Save', '<<save-window>>'),
  22. ('Save _As...', '<<save-window-as-file>>'),
  23. ('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
  24. None,
  25. ('Prin_t Window', '<<print-window>>'),
  26. None,
  27. ('_Close', '<<close-window>>'),
  28. ('E_xit', '<<close-all-windows>>'),
  29. ]),
  30. ('edit', [
  31. ('_Undo', '<<undo>>'),
  32. ('_Redo', '<<redo>>'),
  33. None,
  34. ('Cu_t', '<<cut>>'),
  35. ('_Copy', '<<copy>>'),
  36. ('_Paste', '<<paste>>'),
  37. ('Select _All', '<<select-all>>'),
  38. None,
  39. ('_Find...', '<<find>>'),
  40. ('Find A_gain', '<<find-again>>'),
  41. ('Find _Selection', '<<find-selection>>'),
  42. ('Find in Files...', '<<find-in-files>>'),
  43. ('R_eplace...', '<<replace>>'),
  44. ('Go to _Line', '<<goto-line>>'),
  45. ]),
  46. ('format', [
  47. ('_Indent Region', '<<indent-region>>'),
  48. ('_Dedent Region', '<<dedent-region>>'),
  49. ('Comment _Out Region', '<<comment-region>>'),
  50. ('U_ncomment Region', '<<uncomment-region>>'),
  51. ('Tabify Region', '<<tabify-region>>'),
  52. ('Untabify Region', '<<untabify-region>>'),
  53. ('Toggle Tabs', '<<toggle-tabs>>'),
  54. ('New Indent Width', '<<change-indentwidth>>'),
  55. ]),
  56. ('run', [
  57. ('Python Shell', '<<open-python-shell>>'),
  58. ]),
  59. ('shell', [
  60. ('_View Last Restart', '<<view-restart>>'),
  61. ('_Restart Shell', '<<restart-shell>>'),
  62. ]),
  63. ('debug', [
  64. ('_Go to File/Line', '<<goto-file-line>>'),
  65. ('!_Debugger', '<<toggle-debugger>>'),
  66. ('_Stack Viewer', '<<open-stack-viewer>>'),
  67. ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
  68. ]),
  69. ('options', [
  70. ('_Configure IDLE...', '<<open-config-dialog>>'),
  71. None,
  72. ]),
  73. ('help', [
  74. ('_About IDLE', '<<about-idle>>'),
  75. None,
  76. ('_IDLE Help', '<<help>>'),
  77. ('Python _Docs', '<<python-docs>>'),
  78. ]),
  79. ]
  80. if macosxSupport.runningAsOSXApp():
  81. # Running as a proper MacOS application bundle. This block restructures
  82. # the menus a little to make them conform better to the HIG.
  83. quitItem = menudefs[0][1][-1]
  84. closeItem = menudefs[0][1][-2]
  85. # Remove the last 3 items of the file menu: a separator, close window and
  86. # quit. Close window will be reinserted just above the save item, where
  87. # it should be according to the HIG. Quit is in the application menu.
  88. del menudefs[0][1][-3:]
  89. menudefs[0][1].insert(6, closeItem)
  90. # Remove the 'About' entry from the help menu, it is in the application
  91. # menu
  92. del menudefs[-1][1][0:2]
  93. menudefs.insert(0,
  94. ('application', [
  95. ('About IDLE', '<<about-idle>>'),
  96. None,
  97. ('_Preferences....', '<<open-config-dialog>>'),
  98. ]))
  99. default_keydefs = idleConf.GetCurrentKeySet()
  100. del sys