Commit 3ae4eaab authored by Kurt B. Kaiser's avatar Kurt B. Kaiser

MERGE DS_RPC_BRANCH into MAIN

 Removed Files:
 	AutoIndent.py IdleConf.py MultiScrolledLists.py Separator.py
 	config-unix.txt config-win.txt config.txt eventparse.py
 	keydefs.py
parent 9ef8f428
This diff is collapsed.
"""Provides access to configuration information"""
import os
import sys
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
class IdleConfParser(ConfigParser):
# these conf sections do not define extensions!
builtin_sections = {}
for section in ('EditorWindow', 'Colors'):
builtin_sections[section] = section
def getcolor(self, sec, name):
"""Return a dictionary with foreground and background colors
The return value is appropriate for passing to Tkinter in, e.g.,
a tag_config call.
"""
fore = self.getdef(sec, name + "-foreground")
back = self.getdef(sec, name + "-background")
return {"foreground": fore,
"background": back}
def getdef(self, sec, options, raw=0, vars=None, default=None):
"""Get an option value for given section or return default"""
try:
return self.get(sec, options, raw, vars)
except (NoSectionError, NoOptionError):
return default
def getsection(self, section):
"""Return a SectionConfigParser object"""
return SectionConfigParser(section, self)
def getextensions(self):
exts = []
for sec in self.sections():
if self.builtin_sections.has_key(sec):
continue
# enable is a bool, but it may not be defined
if self.getdef(sec, 'enable') != '0':
exts.append(sec)
return exts
def reload(self):
global idleconf
idleconf = IdleConfParser()
load(_dir) # _dir is a global holding the last directory loaded
class SectionConfigParser:
"""A ConfigParser object specialized for one section
This class has all the get methods that a regular ConfigParser does,
but without requiring a section argument.
"""
def __init__(self, section, config):
self.section = section
self.config = config
def options(self):
return self.config.options(self.section)
def get(self, options, raw=0, vars=None):
return self.config.get(self.section, options, raw, vars)
def getdef(self, options, raw=0, vars=None, default=None):
return self.config.getdef(self.section, options, raw, vars, default)
def getint(self, option):
return self.config.getint(self.section, option)
def getfloat(self, option):
return self.config.getint(self.section, option)
def getboolean(self, option):
return self.config.getint(self.section, option)
def getcolor(self, option):
return self.config.getcolor(self.section, option)
def load(dir):
"""Load IDLE configuration files based on IDLE install in dir
Attempts to load two config files:
dir/config.txt
dir/config-[win/mac/unix].txt
dir/config-%(sys.platform)s.txt
~/.idle
"""
global _dir
_dir = dir
if sys.platform[:3] == 'win':
genplatfile = os.path.join(dir, "config-win.txt")
# XXX don't know what the platform string is on a Mac
elif sys.platform[:3] == 'mac':
genplatfile = os.path.join(dir, "config-mac.txt")
else:
genplatfile = os.path.join(dir, "config-unix.txt")
platfile = os.path.join(dir, "config-%s.txt" % sys.platform)
try:
homedir = os.environ['HOME']
except KeyError:
homedir = os.getcwd()
idleconf.read((os.path.join(dir, "config.txt"), genplatfile, platfile,
os.path.join(homedir, ".idle")))
idleconf = IdleConfParser()
load(os.path.dirname(__file__))
# One or more ScrolledLists with HSeparators between them.
# There is a hierarchical relationship between them:
# the right list displays the substructure of the selected item
# in the left list.
import string
from Tkinter import *
from WindowList import ListedToplevel
from Separator import HSeparator
from ScrolledList import ScrolledList
class MultiScrolledLists:
def __init__(self, root, nlists=2):
assert nlists >= 1
self.root = root
self.nlists = nlists
self.path = []
# create top
self.top = top = ListedToplevel(root)
top.protocol("WM_DELETE_WINDOW", self.close)
top.bind("<Escape>", self.close)
self.settitle()
# create frames and separators in between
self.frames = []
self.separators = []
last = top
for i in range(nlists-1):
sepa = HSeparator(last)
self.separators.append(sepa)
frame, last = sepa.parts()
self.frames.append(frame)
self.frames.append(last)
# create labels and lists
self.labels = []
self.lists = []
for i in range(nlists):
frame = self.frames[i]
label = Label(frame, text=self.subtitle(i),
relief="groove", borderwidth=2)
label.pack(fill="x")
self.labels.append(label)
list = ScrolledList(frame, width=self.width(i),
height=self.height(i))
self.lists.append(list)
list.on_select = \
lambda index, i=i, self=self: self.on_select(index, i)
list.on_double = \
lambda index, i=i, self=self: self.on_double(index, i)
# fill leftmost list (rest get filled on demand)
self.fill(0)
# XXX one after_idle isn't enough; two are...
top.after_idle(self.call_pack_propagate_1)
def call_pack_propagate_1(self):
self.top.after_idle(self.call_pack_propagate)
def call_pack_propagate(self):
for frame in self.frames:
frame.pack_propagate(0)
def close(self, event=None):
self.top.destroy()
def settitle(self):
short = self.shorttitle()
long = self.longtitle()
if short and long:
title = short + " - " + long
elif short:
title = short
elif long:
title = long
else:
title = "Untitled"
icon = short or long or title
self.top.wm_title(title)
self.top.wm_iconname(icon)
def longtitle(self):
# override this
return "Multi Scrolled Lists"
def shorttitle(self):
# override this
return None
def width(self, i):
# override this
return 20
def height(self, i):
# override this
return 10
def subtitle(self, i):
# override this
return "Column %d" % i
def fill(self, i):
for k in range(i, self.nlists):
self.lists[k].clear()
self.labels[k].configure(text=self.subtitle(k))
list = self.lists[i]
l = self.items(i)
for s in l:
list.append(s)
def on_select(self, index, i):
item = self.lists[i].get(index)
del self.path[i:]
self.path.append(item)
if i+1 < self.nlists:
self.fill(i+1)
def items(self, i):
# override this
l = []
for k in range(10):
s = str(k)
if i > 0:
s = self.path[i-1] + "." + s
l.append(s)
return l
def on_double(self, index, i):
pass
def main():
root = Tk()
quit = Button(root, text="Exit", command=root.destroy)
quit.pack()
MultiScrolledLists(root, 4)
root.mainloop()
if __name__ == "__main__":
main()
from Tkinter import *
class Separator:
def __init__(self, master, orient, min=10, thickness=5, bg=None):
self.min = max(1, min)
self.thickness = max(1, thickness)
if orient in ("h", "horizontal"):
self.side = "left"
self.dim = "width"
self.dir = "x"
self.cursor = "sb_h_double_arrow"
elif orient in ("v", "vertical"):
self.side = "top"
self.dim = "height"
self.dir = "y"
self.cursor = "sb_v_double_arrow"
else:
raise ValueError, "Separator: orient should be h or v"
self.winfo_dim = "winfo_" + self.dim
self.master = master = Frame(master)
master.pack(expand=1, fill="both")
self.f1 = Frame(master)
self.f1.pack(expand=1, fill="both", side=self.side)
self.div = Frame(master, cursor=self.cursor)
self.div[self.dim] = self.thickness
self.div.pack(fill="both", side=self.side)
self.f2 = Frame(master)
self.f2.pack(expand=1, fill="both", side=self.side)
self.div.bind("<ButtonPress-1>", self.divider_press)
if bg:
##self.f1["bg"] = bg
##self.f2["bg"] = bg
self.div["bg"] = bg
def parts(self):
return self.f1, self.f2
def divider_press(self, event):
self.press_event = event
self.f1.pack_propagate(0)
self.f2.pack_propagate(0)
for f in self.f1, self.f2:
for dim in "width", "height":
f[dim] = getattr(f, "winfo_"+dim)()
self.div.bind("<Motion>", self.div_motion)
self.div.bind("<ButtonRelease-1>", self.div_release)
self.div.grab_set()
def div_motion(self, event):
delta = getattr(event, self.dir) - getattr(self.press_event, self.dir)
if delta:
dim1 = getattr(self.f1, self.winfo_dim)()
dim2 = getattr(self.f2, self.winfo_dim)()
delta = max(delta, self.min-dim1)
delta = min(delta, dim2-self.min)
dim1 = dim1 + delta
dim2 = dim2 - delta
self.f1[self.dim] = dim1
self.f2[self.dim] = dim2
def div_release(self, event):
self.div_motion(event)
self.div.unbind("<Motion>")
self.div.grab_release()
class VSeparator(Separator):
def __init__(self, master, min=10, thickness=5, bg=None):
Separator.__init__(self, master, "v", min, thickness, bg)
class HSeparator(Separator):
def __init__(self, master, min=10, thickness=5, bg=None):
Separator.__init__(self, master, "h", min, thickness, bg)
def main():
root = Tk()
tlist = []
outer = HSeparator(root, bg="red")
for part in outer.parts():
inner = VSeparator(part, bg="blue")
for f in inner.parts():
t = Text(f, width=40, height=10, borderwidth=0)
t.pack(fill="both", expand=1)
tlist.append(t)
tlist[0].insert("1.0", "Make your own Mondrian!")
tlist[1].insert("1.0", "Move the colored dividers...")
root.mainloop()
if __name__ == '__main__':
main()
[EditorWindow]
font-name= courier
font-size= 10
[EditorWindow]
font-name: courier new
font-size: 10
# IDLE reads several config files to determine user preferences. This
# file is the default config file. When IDLE starts, it will look in
# the following four files in order:
# config.txt the default config file
# config-[win/unix/mac].txt the generic platform config file
# config-[sys.platform].txt the specific platform config file
# ~/.idle the user config file
# XXX what about Windows?
#
# The last definition of each option is used. For example, you can
# override the default window size (80x24) by defining width and
# height options in the EditorWindow section of your ~/.idle file
#
# IDLE extensions can be enabled and disabled by adding them to one of
# the config files. To enable an extension, create a section with the
# same name as the extension, e.g. the [ParenMatch] section below. To
# disable an extension, either remove the section or add the 'enable'
# option with the value 0.
[EditorWindow]
width= 80
height= 24
# fonts defined in config-[win/unix].txt
[Colors]
normal-foreground= black
normal-background= white
# These color types are not explicitly defined= sync, todo, stdin
keyword-foreground= #ff7700
comment-foreground= #dd0000
string-foreground= #00aa00
definition-foreground= #0000ff
hilite-foreground= #000068
hilite-background= #006868
break-foreground= #ff7777
hit-foreground= #ffffff
hit-background= #000000
stdout-foreground= blue
stderr-foreground= red
console-foreground= #770000
error-background= #ff7777
cursor-background= black
[SearchBinding]
[AutoIndent]
[AutoExpand]
[FormatParagraph]
#[ZoomHeight]
[ScriptBinding]
[CallTips]
[ParenMatch]
enable= 0
style= expression
flash-delay= 500
bell= 1
hilite-foreground= black
hilite-background= #43cd80
#! /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())
windows_keydefs = \
{'<<Copy>>': ['<Control-c>', '<Control-C>'],
'<<Cut>>': ['<Control-x>', '<Control-X>'],
'<<Paste>>': ['<Control-v>', '<Control-V>'],
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
'<<center-insert>>': ['<Control-l>'],
'<<close-all-windows>>': ['<Control-q>'],
'<<close-window>>': ['<Alt-F4>'],
'<<dump-undo-state>>': ['<Control-backslash>'],
'<<end-of-file>>': ['<Control-d>'],
'<<python-docs>>': ['<F1>'],
'<<history-next>>': ['<Alt-n>'],
'<<history-previous>>': ['<Alt-p>'],
'<<interrupt-execution>>': ['<Control-c>'],
'<<open-class-browser>>': ['<Alt-c>'],
'<<open-module>>': ['<Alt-m>'],
'<<open-new-window>>': ['<Control-n>'],
'<<open-window-from-file>>': ['<Control-o>'],
'<<plain-newline-and-indent>>': ['<Control-j>'],
'<<redo>>': ['<Control-y>'],
'<<remove-selection>>': ['<Escape>'],
'<<save-copy-of-window-as-file>>': ['<Alt-Shift-s>'],
'<<save-window-as-file>>': ['<Alt-s>'],
'<<save-window>>': ['<Control-s>'],
'<<select-all>>': ['<Alt-a>'],
'<<toggle-auto-coloring>>': ['<Control-slash>'],
'<<undo>>': ['<Control-z>']}
unix_keydefs = \
{'<<Copy>>': ['<Alt-w>', '<Meta-w>'],
'<<Cut>>': ['<Control-w>'],
'<<Paste>>': ['<Control-y>'],
'<<beginning-of-line>>': ['<Control-a>', '<Home>'],
'<<center-insert>>': ['<Control-l>'],
'<<close-all-windows>>': ['<Control-x><Control-c>'],
'<<close-window>>': ['<Control-x><Control-0>', '<Control-x><Key-0>'],
'<<do-nothing>>': ['<Control-x>'],
'<<dump-undo-state>>': ['<Control-backslash>'],
'<<end-of-file>>': ['<Control-d>'],
'<<help>>': ['<F1>'],
'<<history-next>>': ['<Alt-n>', '<Meta-n>'],
'<<history-previous>>': ['<Alt-p>', '<Meta-p>'],
'<<interrupt-execution>>': ['<Control-c>'],
'<<open-class-browser>>': ['<Control-x><Control-b>'],
'<<open-module>>': ['<Control-x><Control-m>'],
'<<open-new-window>>': ['<Control-x><Control-n>'],
'<<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>'],
'<<select-all>>': ['<Alt-a>', '<Meta-a>'],
'<<toggle-auto-coloring>>': ['<Control-slash>'],
'<<undo>>': ['<Control-z>']}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment