summaryrefslogtreecommitdiffstats
path: root/Tools/idle/eventparse.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/eventparse.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/eventparse.py')
-rw-r--r--Tools/idle/eventparse.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/Tools/idle/eventparse.py b/Tools/idle/eventparse.py
new file mode 100644
index 0000000..cb2028d
--- /dev/null
+++ b/Tools/idle/eventparse.py
@@ -0,0 +1,93 @@
+#! /usr/bin/env python
+
+"""Parse event definitions out of comments in source files."""
+
+import re
+import sys
+import os
+import string
+import getopt
+import glob
+import fileinput
+import pprint
+
+def main():
+ hits = []
+ sublist = []
+ args = sys.argv[1:]
+ if not args:
+ args = filter(lambda s: 'A' <= s[0] <= 'Z', glob.glob("*.py"))
+ if not args:
+ print "No arguments, no [A-Z]*.py files."
+ return 1
+ for line in fileinput.input(args):
+ if line[:2] == '#$':
+ if not sublist:
+ sublist.append('file %s' % fileinput.filename())
+ sublist.append('line %d' % fileinput.lineno())
+ sublist.append(string.strip(line[2:-1]))
+ else:
+ if sublist:
+ hits.append(sublist)
+ sublist = []
+ if sublist:
+ hits.append(sublist)
+ sublist = []
+ dd = {}
+ for sublist in hits:
+ d = {}
+ for line in sublist:
+ words = string.split(line, None, 1)
+ if len(words) != 2:
+ continue
+ tag = words[0]
+ l = d.get(tag, [])
+ l.append(words[1])
+ d[tag] = l
+ if d.has_key('event'):
+ keys = d['event']
+ if len(keys) != 1:
+ print "Multiple event keys in", d
+ print 'File "%s", line %d' % (d['file'], d['line'])
+ key = keys[0]
+ if dd.has_key(key):
+ print "Duplicate event in", d
+ print 'File "%s", line %d' % (d['file'], d['line'])
+ return
+ dd[key] = d
+ else:
+ print "No event key in", d
+ print 'File "%s", line %d' % (d['file'], d['line'])
+ winevents = getevents(dd, "win")
+ unixevents = getevents(dd, "unix")
+ save = sys.stdout
+ f = open("keydefs.py", "w")
+ try:
+ sys.stdout = f
+ print "windows_keydefs = \\"
+ pprint.pprint(winevents)
+ print
+ print "unix_keydefs = \\"
+ pprint.pprint(unixevents)
+ finally:
+ sys.stdout = save
+ f.close()
+
+def getevents(dd, key):
+ res = {}
+ events = dd.keys()
+ events.sort()
+ for e in events:
+ d = dd[e]
+ if d.has_key(key) or d.has_key("all"):
+ list = []
+ for x in d.get(key, []) + d.get("all", []):
+ list.append(x)
+ if key == "unix" and x[:5] == "<Alt-":
+ x = "<Meta-" + x[5:]
+ list.append(x)
+ res[e] = list
+ return res
+
+if __name__ == '__main__':
+ sys.exit(main())