Bindings.py 3.35 KB
Newer Older
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
1
"""Define the menu contents, hotkeys, and event bindings.
David Scherer's avatar
David Scherer committed
2

Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
3 4 5 6 7 8 9 10
There is additional configuration information in the EditorWindow class (and
subclasses): the menus are created there based on the menu_specs (class)
variable, and menus not created are silently skipped in the code here.  This
makes it possible, for example, to define a Debug menu which is only present in
the PythonShell window, and a Format menu which is only present in the Editor
windows.

"""
David Scherer's avatar
David Scherer committed
11
import sys
12
from idlelib.configHandler import idleConf
13
from idlelib import macosxSupport
David Scherer's avatar
David Scherer committed
14 15 16 17

menudefs = [
 # underscore prefixes character to underscore
 ('file', [
18
   ('_New File', '<<open-new-window>>'),
David Scherer's avatar
David Scherer committed
19
   ('_Open...', '<<open-window-from-file>>'),
20 21 22
   ('Open _Module...', '<<open-module>>'),
   ('Class _Browser', '<<open-class-browser>>'),
   ('_Path Browser', '<<open-path-browser>>'),
David Scherer's avatar
David Scherer committed
23 24 25
   None,
   ('_Save', '<<save-window>>'),
   ('Save _As...', '<<save-window-as-file>>'),
26
   ('Save Cop_y As...', '<<save-copy-of-window-as-file>>'),
David Scherer's avatar
David Scherer committed
27
   None,
28
   ('Prin_t Window', '<<print-window>>'),
29
   None,
David Scherer's avatar
David Scherer committed
30 31 32 33 34 35 36
   ('_Close', '<<close-window>>'),
   ('E_xit', '<<close-all-windows>>'),
  ]),
 ('edit', [
   ('_Undo', '<<undo>>'),
   ('_Redo', '<<redo>>'),
   None,
37 38 39
   ('Cu_t', '<<cut>>'),
   ('_Copy', '<<copy>>'),
   ('_Paste', '<<paste>>'),
David Scherer's avatar
David Scherer committed
40
   ('Select _All', '<<select-all>>'),
41 42
   None,
   ('_Find...', '<<find>>'),
43 44
   ('Find A_gain', '<<find-again>>'),
   ('Find _Selection', '<<find-selection>>'),
45 46
   ('Find in Files...', '<<find-in-files>>'),
   ('R_eplace...', '<<replace>>'),
47
   ('Go to _Line', '<<goto-line>>'),
David Scherer's avatar
David Scherer committed
48
  ]),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
49
('format', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
50 51 52 53 54 55 56 57 58 59
   ('_Indent Region', '<<indent-region>>'),
   ('_Dedent Region', '<<dedent-region>>'),
   ('Comment _Out Region', '<<comment-region>>'),
   ('U_ncomment Region', '<<uncomment-region>>'),
   ('Tabify Region', '<<tabify-region>>'),
   ('Untabify Region', '<<untabify-region>>'),
   ('Toggle Tabs', '<<toggle-tabs>>'),
   ('New Indent Width', '<<change-indentwidth>>'),
   ]),
 ('run', [
60
   ('Python Shell', '<<open-python-shell>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
61
   ]),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
62 63 64
 ('shell', [
   ('_View Last Restart', '<<view-restart>>'),
   ('_Restart Shell', '<<restart-shell>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
65 66
   ]),
 ('debug', [
67
   ('_Go to File/Line', '<<goto-file-line>>'),
David Scherer's avatar
David Scherer committed
68
   ('!_Debugger', '<<toggle-debugger>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
69
   ('_Stack Viewer', '<<open-stack-viewer>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
70 71
   ('!_Auto-open Stack Viewer', '<<toggle-jit-stack-viewer>>'),
   ]),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
72
 ('options', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
73
   ('_Configure IDLE...', '<<open-config-dialog>>'),
74
   None,
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
75
   ]),
David Scherer's avatar
David Scherer committed
76
 ('help', [
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
77
   ('_About IDLE', '<<about-idle>>'),
David Scherer's avatar
David Scherer committed
78
   None,
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
79 80
   ('_IDLE Help', '<<help>>'),
   ('Python _Docs', '<<python-docs>>'),
Kurt B. Kaiser's avatar
Kurt B. Kaiser committed
81
   ]),
David Scherer's avatar
David Scherer committed
82 83
]

84
if macosxSupport.runningAsOSXApp():
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    # Running as a proper MacOS application bundle. This block restructures
    # the menus a little to make them conform better to the HIG.

    quitItem = menudefs[0][1][-1]
    closeItem = menudefs[0][1][-2]

    # Remove the last 3 items of the file menu: a separator, close window and
    # quit. Close window will be reinserted just above the save item, where
    # it should be according to the HIG. Quit is in the application menu.
    del menudefs[0][1][-3:]
    menudefs[0][1].insert(6, closeItem)

    # Remove the 'About' entry from the help menu, it is in the application
    # menu
    del menudefs[-1][1][0:2]

101 102 103 104
    # Remove the 'Configure' entry from the options menu, it is in the
    # application menu as 'Preferences'
    del menudefs[-2][1][0:2]

105
default_keydefs = idleConf.GetCurrentKeySet()
David Scherer's avatar
David Scherer committed
106 107

del sys