diff options
author | Guido van Rossum <guido@python.org> | 1999-01-28 22:02:47 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-28 22:02:47 (GMT) |
commit | 07ec8967078a966365a44db301a9063f70c7f474 (patch) | |
tree | f97b034c2f3489958e47ae03a3cb41c5312a745c /Tools/idle/Bindings.py | |
parent | 85ef9dce9f4b1982c1f26daa0fe9f4af08e124a6 (diff) | |
download | cpython-07ec8967078a966365a44db301a9063f70c7f474.zip cpython-07ec8967078a966365a44db301a9063f70c7f474.tar.gz cpython-07ec8967078a966365a44db301a9063f70c7f474.tar.bz2 |
Move menu/key binding code from Bindings.py to EditorWindow.py,
with changed APIs -- it makes much more sense there.
Also add a new feature: if the first character of a menu label is
a '!', it gets a checkbox. Checkboxes are bound to Boolean Tcl variables
that can be accessed through the new getvar/setvar/getrawvar API;
the variable is named after the event to which the menu is bound.
Diffstat (limited to 'Tools/idle/Bindings.py')
-rw-r--r-- | Tools/idle/Bindings.py | 62 |
1 files changed, 3 insertions, 59 deletions
diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py index e365032..e0a2570 100644 --- a/Tools/idle/Bindings.py +++ b/Tools/idle/Bindings.py @@ -7,7 +7,6 @@ import sys import string -import re from keydefs import * menudefs = [ @@ -42,9 +41,9 @@ menudefs = [ ]), ('debug', [ ('_Go to file/line', '<<goto-file-line>>'), - ('_Open stack viewer', '<<open-stack-viewer>>'), - ('_Debugger toggle', '<<toggle-debugger>>'), - ('_JIT Stack viewer toggle', '<<toggle-jit-stack-viewer>>' ), + ('_Stack viewer', '<<open-stack-viewer>>'), + ('!_Debugger', '<<toggle-debugger>>'), + ('!_Auto-open stack viewer', '<<toggle-jit-stack-viewer>>' ), ]), ('help', [ ('_Help...', '<<help>>'), @@ -53,62 +52,7 @@ menudefs = [ ]), ] -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': ']', - 'slash': '/', -} - -def get_accelerator(keydefs, event): - 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: default_keydefs = unix_keydefs - -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)) - -def fill_menus(text, menudict, defs=menudefs, keydefs=default_keydefs): - # Fill the menus for the given text widget. The menudict argument is - # a dictionary containing the menus, keyed by their lowercased name. - # Menus that are absent or None are ignored. - for mname, itemlist in defs: - menu = menudict.get(mname) - if not menu: - continue - for item in itemlist: - if not item: - menu.add_separator() - else: - label, event = item - underline, label = prepstr(label) - accelerator = get_accelerator(keydefs, event) - def command(text=text, event=event): - text.event_generate(event) - menu.add_command(label=label, underline=underline, - command=command, accelerator=accelerator) |