Bindings.py 2.97 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.

"""
11 12
from importlib.util import find_spec

13
from idlelib.configHandler import idleConf
14 15 16 17 18 19 20

#   Warning: menudefs is altered in macosxSupport.overrideRootMenu()
#   after it is determined that an OS X Aqua Tk is in use,
#   which cannot be done until after Tk() is first called.
#   Do not alter the 'file', 'options', or 'help' cascades here
#   without altering overrideRootMenu() as well.
#       TODO: Make this more robust
David Scherer's avatar
David Scherer committed
21 22 23 24

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

91 92 93
if find_spec('turtledemo'):
    menudefs[-1][1].append(('Turtle Demo', '<<open-turtle-demo>>'))

94
default_keydefs = idleConf.GetCurrentKeySet()