1998-11-26 23:17:49 -04:00
|
|
|
# This file defines the menu contents and key bindings. Note that
|
|
|
|
# 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 by the code here. This makes it possible to define the
|
|
|
|
# Debug menu here, which is only present in the PythonShell window.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
import re
|
1999-01-02 17:28:54 -04:00
|
|
|
from keydefs import *
|
1998-11-26 23:17:49 -04:00
|
|
|
|
|
|
|
menudefs = [
|
|
|
|
# underscore prefixes character to underscore
|
|
|
|
('file', [
|
|
|
|
('_New window', '<<open-new-window>>'),
|
|
|
|
('_Open...', '<<open-window-from-file>>'),
|
|
|
|
('Open _module...', '<<open-module>>'),
|
1999-01-02 17:28:54 -04:00
|
|
|
('Class _browser', '<<open-class-browser>>'),
|
|
|
|
('Python shell', '<<open-python-shell>>'),
|
1998-11-26 23:17:49 -04:00
|
|
|
None,
|
|
|
|
('_Save', '<<save-window>>'),
|
|
|
|
('Save _As...', '<<save-window-as-file>>'),
|
|
|
|
('Save Co_py As...', '<<save-copy-of-window-as-file>>'),
|
|
|
|
None,
|
|
|
|
('_Close', '<<close-window>>'),
|
|
|
|
('E_xit', '<<close-all-windows>>'),
|
|
|
|
]),
|
|
|
|
('edit', [
|
|
|
|
('_Undo', '<<undo>>'),
|
|
|
|
('_Redo', '<<redo>>'),
|
|
|
|
None,
|
|
|
|
('Cu_t', '<<Cut>>'),
|
|
|
|
('_Copy', '<<Copy>>'),
|
|
|
|
('_Paste', '<<Paste>>'),
|
1999-01-02 17:28:54 -04:00
|
|
|
('Select _All', '<<select-all>>'),
|
|
|
|
]),
|
|
|
|
('script', [
|
|
|
|
('Run module', '<<run-module>>'),
|
|
|
|
('Run script', '<<run-script>>'),
|
|
|
|
('New shell', '<<new-shell>>'),
|
1998-11-26 23:17:49 -04:00
|
|
|
]),
|
|
|
|
('debug', [
|
1999-01-02 17:28:54 -04:00
|
|
|
('_Go to file/line', '<<goto-file-line>>'),
|
1998-11-26 23:17:49 -04:00
|
|
|
('_Open stack viewer', '<<open-stack-viewer>>'),
|
|
|
|
('_Debugger toggle', '<<toggle-debugger>>'),
|
1999-01-08 11:31:07 -04:00
|
|
|
('_JIT Stack viewer toggle', '<<toggle-jit-stack-viewer>>' ),
|
1998-11-26 23:17:49 -04:00
|
|
|
]),
|
|
|
|
('help', [
|
|
|
|
('_Help...', '<<help>>'),
|
|
|
|
None,
|
|
|
|
('_About IDLE...', '<<about-idle>>'),
|
|
|
|
]),
|
1998-10-10 15:48:31 -03:00
|
|
|
]
|
|
|
|
|
1998-11-26 23:17:49 -04:00
|
|
|
def prepstr(s):
|
|
|
|
# Helper to extract the underscore from a string,
|
|
|
|
# e.g. prepstr("Co_py") returns (2, "Copy").
|
|
|
|
i = string.find(s, '_')
|
|
|
|
if i >= 0:
|
|
|
|
s = s[:i] + s[i+1:]
|
|
|
|
return i, s
|
|
|
|
|
|
|
|
keynames = {
|
|
|
|
'bracketleft': '[',
|
|
|
|
'bracketright': ']',
|
1999-01-02 17:28:54 -04:00
|
|
|
'slash': '/',
|
1998-11-26 23:17:49 -04:00
|
|
|
}
|
|
|
|
|
1999-01-02 17:28:54 -04:00
|
|
|
def get_accelerator(keydefs, event):
|
1998-11-26 23:17:49 -04:00
|
|
|
keylist = keydefs.get(event)
|
|
|
|
if not keylist:
|
|
|
|
return ""
|
|
|
|
s = keylist[0]
|
|
|
|
s = re.sub(r"-[a-z]\b", lambda m: string.upper(m.group()), s)
|
|
|
|
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
|
|
|
|
s = re.sub("Key-", "", s)
|
|
|
|
s = re.sub("Control-", "Ctrl-", s)
|
|
|
|
s = re.sub("-", "+", s)
|
|
|
|
s = re.sub("><", " ", s)
|
|
|
|
s = re.sub("<", "", s)
|
|
|
|
s = re.sub(">", "", s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
default_keydefs = windows_keydefs
|
|
|
|
else:
|
1999-01-02 17:28:54 -04:00
|
|
|
default_keydefs = unix_keydefs
|
1998-11-26 23:17:49 -04:00
|
|
|
|
|
|
|
def apply_bindings(text, keydefs=default_keydefs):
|
|
|
|
text.keydefs = keydefs
|
|
|
|
for event, keylist in keydefs.items():
|
|
|
|
if keylist:
|
|
|
|
apply(text.event_add, (event,) + tuple(keylist))
|
|
|
|
|
1999-01-02 17:28:54 -04:00
|
|
|
def fill_menus(text, menudict, defs=menudefs, keydefs=default_keydefs):
|
1998-11-26 23:17:49 -04:00
|
|
|
# Fill the menus for the given text widget. The menudict argument is
|
1998-10-12 17:57:09 -03:00
|
|
|
# a dictionary containing the menus, keyed by their lowercased name.
|
1998-10-12 20:55:10 -03:00
|
|
|
# Menus that are absent or None are ignored.
|
1998-11-26 23:17:49 -04:00
|
|
|
for mname, itemlist in defs:
|
|
|
|
menu = menudict.get(mname)
|
1998-10-12 17:57:09 -03:00
|
|
|
if not menu:
|
|
|
|
continue
|
1998-11-26 23:17:49 -04:00
|
|
|
for item in itemlist:
|
|
|
|
if not item:
|
|
|
|
menu.add_separator()
|
|
|
|
else:
|
|
|
|
label, event = item
|
|
|
|
underline, label = prepstr(label)
|
1999-01-02 17:28:54 -04:00
|
|
|
accelerator = get_accelerator(keydefs, event)
|
1998-11-26 23:17:49 -04:00
|
|
|
def command(text=text, event=event):
|
|
|
|
text.event_generate(event)
|
|
|
|
menu.add_command(label=label, underline=underline,
|
|
|
|
command=command, accelerator=accelerator)
|