diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-03-03 22:57:42 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-03-03 22:57:42 (GMT) |
commit | daca630e4058fcdc5cb4397b5e49329e9b07776b (patch) | |
tree | 0d6c39416ab5f1e07a5a96744a77cbe1a0d88b7c | |
parent | 820314ea954963937ee51190ea916b1f54361d0f (diff) | |
download | cpython-daca630e4058fcdc5cb4397b5e49329e9b07776b.zip cpython-daca630e4058fcdc5cb4397b5e49329e9b07776b.tar.gz cpython-daca630e4058fcdc5cb4397b5e49329e9b07776b.tar.bz2 |
a ConfigParser for idle and three configuration files
-rw-r--r-- | Tools/idle/IdleConf.py | 117 | ||||
-rw-r--r-- | Tools/idle/config-unix.txt | 3 | ||||
-rw-r--r-- | Tools/idle/config-win.txt | 3 | ||||
-rw-r--r-- | Tools/idle/config.txt | 64 |
4 files changed, 187 insertions, 0 deletions
diff --git a/Tools/idle/IdleConf.py b/Tools/idle/IdleConf.py new file mode 100644 index 0000000..de208b0 --- /dev/null +++ b/Tools/idle/IdleConf.py @@ -0,0 +1,117 @@ +"""Provides access to configuration information""" + +import os +import sys +from ConfigParser import ConfigParser, NoOptionError + +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 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.startswith('win'): + genplatfile = os.path.join(dir, "config-win.txt") + # XXX don't know what the platform string is on a Mac + elif sys.platform.startswith('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) + + for file in (os.path.join(dir, "config.txt"), + genplatfile, + platfile, + # XXX watch out for KeyError + os.path.join(os.environ['HOME'], ".idle"), + ): + try: + f = open(file) + except IOError: + continue + IdleConf.readfp(f) + f.close() + +IdleConf = IdleConfParser() diff --git a/Tools/idle/config-unix.txt b/Tools/idle/config-unix.txt new file mode 100644 index 0000000..e3170d0 --- /dev/null +++ b/Tools/idle/config-unix.txt @@ -0,0 +1,3 @@ +[EditorWindow] +font-name: courier +font-size: 10 diff --git a/Tools/idle/config-win.txt b/Tools/idle/config-win.txt new file mode 100644 index 0000000..9faa635 --- /dev/null +++ b/Tools/idle/config-win.txt @@ -0,0 +1,3 @@ +[EditorWindow] +font-name: courier new +font-size: 10 diff --git a/Tools/idle/config.txt b/Tools/idle/config.txt new file mode 100644 index 0000000..545ac3c --- /dev/null +++ b/Tools/idle/config.txt @@ -0,0 +1,64 @@ +# 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 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 ; ParenMatch conflicts with CallTips +style: expression +flash-delay: 500 +bell: 1 +hilite-foreground: black +hilite-background: #43cd80 ; SeaGreen3 |