diff --git a/Tools/idle/ColorDelegator.py b/Tools/idle/ColorDelegator.py index 68c2d33321c..212afa5ed89 100644 --- a/Tools/idle/ColorDelegator.py +++ b/Tools/idle/ColorDelegator.py @@ -4,7 +4,7 @@ import re import keyword from Tkinter import * from Delegator import Delegator -import IdlePrefs +from IdleConf import IdleConf #$ event <> #$ win @@ -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): diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py index 0e0e0dcda91..ee3b9c34d4a 100644 --- a/Tools/idle/EditorWindow.py +++ b/Tools/idle/EditorWindow.py @@ -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(), []) diff --git a/Tools/idle/ParenMatch.py b/Tools/idle/ParenMatch.py index 75006037b78..d8482b9f457 100644 --- a/Tools/idle/ParenMatch.py +++ b/Tools/idle/ParenMatch.py @@ -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 diff --git a/Tools/idle/PyShell.py b/Tools/idle/PyShell.py index 8c93f4daf0e..1e2f1ae3d2a 100644 --- a/Tools/idle/PyShell.py +++ b/Tools/idle/PyShell.py @@ -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"), }) diff --git a/Tools/idle/extend.py b/Tools/idle/extend.py deleted file mode 100644 index de90f3677fa..00000000000 --- a/Tools/idle/extend.py +++ /dev/null @@ -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", -] diff --git a/Tools/idle/idle.py b/Tools/idle/idle.py index 3c06e05488d..71fdce56bb1 100755 --- a/Tools/idle/idle.py +++ b/Tools/idle/idle.py @@ -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()