summaryrefslogtreecommitdiffstats
path: root/Tools/idle/Bindings.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-01-02 21:28:54 (GMT)
committerGuido van Rossum <guido@python.org>1999-01-02 21:28:54 (GMT)
commit504b0bf066e4fddb21646331e89c2f6836c5c638 (patch)
treef5454648430eb4818810305325561aabb02cf035 /Tools/idle/Bindings.py
parentf07c328c072e62ada8671ec30392572add22d904 (diff)
downloadcpython-504b0bf066e4fddb21646331e89c2f6836c5c638.zip
cpython-504b0bf066e4fddb21646331e89c2f6836c5c638.tar.gz
cpython-504b0bf066e4fddb21646331e89c2f6836c5c638.tar.bz2
Checking in IDLE 0.2.
Much has changed -- too much, in fact, to write down. The big news is that there's a standard way to write IDLE extensions; see extend.txt. Some sample extensions have been provided, and some existing code has been converted to extensions. Probably the biggest new user feature is a new search dialog with more options, search and replace, and even search in files (grep). This is exactly as downloaded from my laptop after returning from the holidays -- it hasn't even been tested on Unix yet.
Diffstat (limited to 'Tools/idle/Bindings.py')
-rw-r--r--Tools/idle/Bindings.py115
1 files changed, 15 insertions, 100 deletions
diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py
index 5a13d22..dbca89a 100644
--- a/Tools/idle/Bindings.py
+++ b/Tools/idle/Bindings.py
@@ -8,6 +8,7 @@
import sys
import string
import re
+from keydefs import *
menudefs = [
# underscore prefixes character to underscore
@@ -15,7 +16,8 @@ menudefs = [
('_New window', '<<open-new-window>>'),
('_Open...', '<<open-window-from-file>>'),
('Open _module...', '<<open-module>>'),
- ('Class _browser...', '<<open-class-browser>>'),
+ ('Class _browser', '<<open-class-browser>>'),
+ ('Python shell', '<<open-python-shell>>'),
None,
('_Save', '<<save-window>>'),
('Save _As...', '<<save-window-as-file>>'),
@@ -31,19 +33,15 @@ menudefs = [
('Cu_t', '<<Cut>>'),
('_Copy', '<<Copy>>'),
('_Paste', '<<Paste>>'),
- None,
- ('_Find...', '<<find>>'),
- ('Find _next', '<<find-next>>'),
- ('Find _same', '<<find-same>>'),
- ('_Go to line', '<<goto-line>>'),
- None,
- ('_Dedent region', '<<dedent-region>>'),
- ('_Indent region', '<<indent-region>>'),
- ('Comment _out region', '<<comment-region>>'),
- ('U_ncomment region', '<<uncomment-region>>'),
+ ('Select _All', '<<select-all>>'),
+ ]),
+ ('script', [
+ ('Run module', '<<run-module>>'),
+ ('Run script', '<<run-script>>'),
+ ('New shell', '<<new-shell>>'),
]),
('debug', [
- ('_Go to line from traceback', '<<goto-traceback-line>>'),
+ ('_Go to file/line', '<<goto-file-line>>'),
('_Open stack viewer', '<<open-stack-viewer>>'),
('_Debugger toggle', '<<toggle-debugger>>'),
]),
@@ -54,81 +52,6 @@ menudefs = [
]),
]
-windows_keydefs = {
- '<<beginning-of-line>>': ['<Control-a>', '<Home>'],
- '<<close-all-windows>>': ['<Control-q>'],
- '<<comment-region>>': ['<Meta-Key-3>', '<Alt-Key-3>'],
- '<<dedent-region>>': ['<Control-bracketleft>'],
- '<<dump-undo-state>>': ['<Control-backslash>'],
- '<<end-of-file>>': ['<Control-d>'],
- '<<expand-word>>': ['<Meta-slash>', '<Alt-slash>'],
- '<<find-next>>': ['<F3>', '<Control-g>'],
- '<<find-same>>': ['<Control-F3>'],
- '<<find>>': ['<Control-f>'],
- '<<goto-line>>': ['<Alt-g>', '<Meta-g>'],
- '<<history-next>>': ['<Meta-n>', '<Alt-n>'],
- '<<history-previous>>': ['<Meta-p>', '<Alt-p>'],
- '<<indent-region>>': ['<Control-bracketright>'],
- '<<interrupt-execution>>': ['<Control-c>'],
- '<<newline-and-indent>>': ['<Key-Return>', '<KP_Enter>'],
- '<<open-new-window>>': ['<Control-n>'],
- '<<open-window-from-file>>': ['<Control-o>'],
- '<<plain-newline-and-indent>>': ['<Control-j>'],
- '<<redo>>': ['<Control-y>'],
- '<<save-copy-of-window-as-file>>': ['<Meta-w>'],
- '<<save-window-as-file>>': ['<Control-w>'],
- '<<save-window>>': ['<Control-s>'],
- '<<toggle-auto-coloring>>': ['<Control-slash>'],
- '<<uncomment-region>>': ['<Meta-Key-4>', '<Alt-Key-4>'],
- '<<undo>>': ['<Control-z>'],
-}
-
-emacs_keydefs = {
- '<<Copy>>': ['<Alt-w>'],
- '<<Cut>>': ['<Control-w>'],
- '<<Paste>>': ['<Control-y>'],
- '<<about-idle>>': [],
- '<<beginning-of-line>>': ['<Control-a>', '<Home>'],
- '<<center-insert>>': ['<Control-l>'],
- '<<close-all-windows>>': ['<Control-x><Control-c>'],
- '<<close-window>>': ['<Control-x><Control-0>'],
- '<<comment-region>>': ['<Meta-Key-3>', '<Alt-Key-3>'],
- '<<dedent-region>>': ['<Meta-bracketleft>',
- '<Alt-bracketleft>',
- '<Control-bracketleft>'],
- '<<do-nothing>>': ['<Control-x>'],
- '<<dump-undo-state>>': ['<Control-backslash>'],
- '<<end-of-file>>': ['<Control-d>'],
- '<<expand-word>>': ['<Meta-slash>', '<Alt-slash>'],
- '<<find-next>>': ['<Control-u><Control-s>'],
- '<<find-same>>': ['<Control-s>'],
- '<<find>>': ['<Control-u><Control-u><Control-s>'],
- '<<goto-line>>': ['<Alt-g>', '<Meta-g>'],
- '<<goto-traceback-line>>': [],
- '<<help>>': [],
- '<<history-next>>': ['<Meta-n>', '<Alt-n>'],
- '<<history-previous>>': ['<Meta-p>', '<Alt-p>'],
- '<<indent-region>>': ['<Meta-bracketright>',
- '<Alt-bracketright>',
- '<Control-bracketright>'],
- '<<interrupt-execution>>': ['<Control-c>'],
- '<<newline-and-indent>>': ['<Key-Return>', '<KP_Enter>'],
- '<<open-class-browser>>': ['<Control-x><Control-b>'],
- '<<open-module>>': ['<Control-x><Control-m>'],
- '<<open-new-window>>': ['<Control-x><Control-n>'],
- '<<open-stack-viewer>>': [],
- '<<open-window-from-file>>': ['<Control-x><Control-f>'],
- '<<plain-newline-and-indent>>': ['<Control-j>'],
- '<<redo>>': ['<Alt-z>', '<Meta-z>'],
- '<<save-copy-of-window-as-file>>': ['<Control-x><w>'],
- '<<save-window-as-file>>': ['<Control-x><Control-w>'],
- '<<save-window>>': ['<Control-x><Control-s>'],
- '<<toggle-auto-coloring>>': ['<Control-slash>'],
- '<<toggle-debugger>>': [],
- '<<uncomment-region>>': ['<Meta-Key-4>', '<Alt-Key-4>'],
- '<<undo>>': ['<Control-z>'],
-}
-
def prepstr(s):
# Helper to extract the underscore from a string,
# e.g. prepstr("Co_py") returns (2, "Copy").
@@ -140,18 +63,14 @@ def prepstr(s):
keynames = {
'bracketleft': '[',
'bracketright': ']',
+ 'slash': '/',
}
-def getaccelerator(keydefs, event):
+def get_accelerator(keydefs, event):
keylist = keydefs.get(event)
if not keylist:
return ""
s = keylist[0]
- if s[:6] == "<Meta-":
- # Prefer Alt over Meta -- they should be the same thing anyway
- alts = "<Alt-" + s[6:]
- if alts in keylist:
- s = alts
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)
@@ -165,7 +84,7 @@ def getaccelerator(keydefs, event):
if sys.platform == 'win32':
default_keydefs = windows_keydefs
else:
- default_keydefs = emacs_keydefs
+ default_keydefs = unix_keydefs
def apply_bindings(text, keydefs=default_keydefs):
text.keydefs = keydefs
@@ -173,14 +92,10 @@ def apply_bindings(text, keydefs=default_keydefs):
if keylist:
apply(text.event_add, (event,) + tuple(keylist))
-def fill_menus(text, menudict, defs=menudefs):
+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.
- if hasattr(text, "keydefs"):
- keydefs = text.keydefs
- else:
- keydefs = default_keydefs
for mname, itemlist in defs:
menu = menudict.get(mname)
if not menu:
@@ -191,7 +106,7 @@ def fill_menus(text, menudict, defs=menudefs):
else:
label, event = item
underline, label = prepstr(label)
- accelerator = getaccelerator(keydefs, event)
+ accelerator = get_accelerator(keydefs, event)
def command(text=text, event=event):
text.event_generate(event)
menu.add_command(label=label, underline=underline,