migrate to use of IdleConf and config files to set options

idle.py:
    Load the config files before anything else happens
    XXX Need to define standard way to get files relative to the
       IDLE install dir

PyShell.py:
ColorDelegator.py:
    Get color defns out of IdleConf instead of IdlePrefs

EditorWindow.py:
    Replace hard-coded font & window size with config options
    Get extension names via IdleConf.getextensions

extend.py:
   Obsolete.  Extensions defined in config file.

ParenMatch.py:
   Use config file for extension options.
   Revise comment about parser requirements.
   Simplify logic on find returning None.
This commit is contained in:
Jeremy Hylton 2000-03-03 23:06:45 +00:00
parent 583abb8027
commit e81f28b630
6 changed files with 51 additions and 86 deletions

View File

@ -4,7 +4,7 @@ import re
import keyword
from Tkinter import *
from Delegator import Delegator
import IdlePrefs
from IdleConf import IdleConf
#$ event <<toggle-auto-coloring>>
#$ win <Control-slash>
@ -51,29 +51,18 @@ class ColorDelegator(Delegator):
apply(self.tag_configure, (tag,), cnf)
self.tag_raise('sel')
cprefs = IdlePrefs.ColorPrefs()
cconf = IdleConf.getsection('Colors')
tagdefs = {
"COMMENT": {"foreground": cprefs.CComment[0],
"background": cprefs.CComment[1]},
"KEYWORD": {"foreground": cprefs.CKeyword[0],
"background": cprefs.CKeyword[1]},
"STRING": {"foreground": cprefs.CString[0],
"background": cprefs.CString[1]},
"DEFINITION": {"foreground": cprefs.CDefinition[0],
"background": cprefs.CDefinition[1]},
"SYNC": {"background": cprefs.CSync[0],
"background": cprefs.CSync[1]},
"TODO": {"background": cprefs.CTodo[0],
"background": cprefs.CTodo[1]},
"BREAK": {"background": cprefs.CBreak[0],
"background": cprefs.CBreak[1]},
"COMMENT": cconf.getcolor("comment"),
"KEYWORD": cconf.getcolor("keyword"),
"STRING": cconf.getcolor("string"),
"DEFINITION": cconf.getcolor("definition"),
"SYNC": cconf.getcolor("sync"),
"TODO": cconf.getcolor("todo"),
"BREAK": cconf.getcolor("break"),
# The following is used by ReplaceDialog:
"hit": {"foreground": cprefs.CHit[0],
"background": cprefs.CHit[1]},
"hit": cconf.getcolor("hit"),
}
def insert(self, index, chars, tags=None):

View File

@ -8,23 +8,7 @@ import tkSimpleDialog
import tkMessageBox
import idlever
import WindowList
# Customization of default window size and font
# standard
WIDTH = 80
HEIGHT = 24
if sys.platform[:3] == 'win':
FONT = ("courier new", 10)
else:
FONT = ("courier", 10)
if 0:
# for demos (on Windows)
WIDTH = 70
HEIGHT = 16
FONT = ("lucida console", 14)
if 0:
# for Windows 98
FONT = ("lucida console", 8)
from IdleConf import IdleConf
# The default tab setting for a Text widget, in average-width characters.
TK_TABWIDTH_DEFAULT = 8
@ -110,7 +94,8 @@ class EditorWindow:
vars = {}
def __init__(self, flist=None, filename=None, key=None, root=None):
cprefs = self.ColorDelegator.cprefs
edconf = IdleConf.getsection('EditorWindow')
coconf = IdleConf.getsection('Colors')
self.flist = flist
root = root or flist.root
self.root = root
@ -121,13 +106,14 @@ class EditorWindow:
self.vbar = vbar = Scrollbar(top, name='vbar')
self.text_frame = text_frame = Frame(top)
self.text = text = Text(text_frame, name='text', padx=5,
foreground=cprefs.CNormal[0],
background=cprefs.CNormal[1],
highlightcolor=cprefs.CHilite[0],
highlightbackground=cprefs.CHilite[1],
insertbackground=cprefs.CCursor[1],
width=WIDTH, height=HEIGHT,
wrap="none")
foreground=coconf.getdef('normal-foreground'),
background=coconf.getdef('normal-background'),
highlightcolor=coconf.getdef('hilite-foreground'),
highlightbackground=coconf.getdef('hilite-background'),
insertbackground=coconf.getdef('cursor-background'),
width=edconf.getint('width'),
height=edconf.getint('height'),
wrap="none")
self.createmenubar()
self.apply_bindings()
@ -156,7 +142,7 @@ class EditorWindow:
vbar.pack(side=RIGHT, fill=Y)
text['yscrollcommand'] = vbar.set
text['font'] = FONT
text['font'] = edconf.get('font-name'), edconf.get('font-size')
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
text.pack(side=TOP, fill=BOTH, expand=1)
text.focus_set()
@ -544,8 +530,7 @@ class EditorWindow:
traceback.print_exc()
def get_standard_extension_names(self):
import extend
return extend.standard
return IdleConf.getextensions()
def load_extension(self, name):
mod = __import__(name, globals(), locals(), [])

View File

@ -14,6 +14,7 @@ import string
import PyParse
from AutoIndent import AutoIndent, index2line
from IdleConf import IdleConf
class ParenMatch:
"""Highlight matching parentheses
@ -55,12 +56,12 @@ class ParenMatch:
windows_keydefs = {}
unix_keydefs = {}
STYLE = "default" # or "expression"
FLASH_DELAY = 500
HILITE_CONFIG = {"foreground": "black",
"background": "#43cd80", # SeaGreen3
}
BELL = 1 # set to false for no bell
iconf = IdleConf.getsection('ParenMatch')
STYLE = iconf.get('style')
FLASH_DELAY = iconf.getint('flash-delay')
HILITE_CONFIG = iconf.getcolor('hilite')
BELL = iconf.getboolean('bell')
del iconf
def __init__(self, editwin):
self.editwin = editwin
@ -156,9 +157,8 @@ class LastOpenBracketFinder:
startat = max(lno - context, 1)
startatindex = `startat` + ".0"
# rawtext needs to contain everything up to the last
# character, which was the close paren. also need to
# append "\n" to please the parser, which seems to expect
# a complete line
# character, which was the close paren. the parser also
# requires that the last line ends with "\n"
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
y.set_str(rawtext)
bod = y.find_good_parse_start(
@ -174,9 +174,8 @@ class LastOpenBracketFinder:
"""Return the location of the last open paren"""
lno = index2line(self.text.index("insert"))
i, buf = self._find_offset_in_buf(lno)
if i is None:
return i
if keysym_type(buf[i]) != right_keysym_type:
if i is None \
or keysym_type(buf[i]) != right_keysym_type:
return None
lines_back = buf[i:].count("\n") - 1
# subtract one for the "\n" added to please the parser

View File

@ -16,6 +16,7 @@ from EditorWindow import EditorWindow, fixwordbreaks
from FileList import FileList
from ColorDelegator import ColorDelegator
from OutputWindow import OutputWindow
from IdleConf import IdleConf
import idlever
# We need to patch linecache.checkcache, because we don't want it
@ -114,21 +115,15 @@ class ModifiedColorDelegator(ColorDelegator):
ColorDelegator.recolorize_main(self)
tagdefs = ColorDelegator.tagdefs.copy()
cprefs = ColorDelegator.cprefs
cconf = IdleConf.getsection('Colors')
tagdefs.update({
"stdin": {"foreground": cprefs.CStdIn[0],
"background": cprefs.CStdIn[1]},
"stdout": {"foreground": cprefs.CStdOut[0],
"background": cprefs.CStdOut[1]},
"stderr": {"foreground": cprefs.CStdErr[0],
"background": cprefs.CStdErr[1]},
"console": {"foreground": cprefs.CConsole[0],
"background": cprefs.CConsole[1]},
"ERROR": {"background": cprefs.CError[0],
"background": cprefs.CError[1]},
None: {"foreground": cprefs.CNormal[0],
"background": cprefs.CNormal[1]},
"stdin": cconf.getcolor("stdin"),
"stdout": cconf.getcolor("stdout"),
"stderr": cconf.getcolor("stderr"),
"console": cconf.getcolor("console"),
"ERROR": cconf.getcolor("ERROR"),
None: cconf.getcolor("normal"),
})

View File

@ -1,12 +0,0 @@
# IDLE extensions to be loaded by default (see extend.txt).
# Edit this file to configure your set of IDLE extensions.
standard = [
"SearchBinding",
"AutoIndent",
"AutoExpand",
"FormatParagraph",
"ZoomHeight",
"ScriptBinding",
"CallTips",
]

View File

@ -1,3 +1,12 @@
#! /usr/bin/env python
import os
import sys
import IdleConf
idle_dir = os.path.split(sys.argv[0])[0]
IdleConf.load(idle_dir)
# defer importing Pyshell until IdleConf is loaded
import PyShell
PyShell.main()