mirror of
https://github.com/python/cpython.git
synced 2025-09-17 22:20:23 +00:00
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:
parent
583abb8027
commit
e81f28b630
6 changed files with 51 additions and 86 deletions
|
@ -4,7 +4,7 @@ import re
|
||||||
import keyword
|
import keyword
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
from Delegator import Delegator
|
from Delegator import Delegator
|
||||||
import IdlePrefs
|
from IdleConf import IdleConf
|
||||||
|
|
||||||
#$ event <<toggle-auto-coloring>>
|
#$ event <<toggle-auto-coloring>>
|
||||||
#$ win <Control-slash>
|
#$ win <Control-slash>
|
||||||
|
@ -51,29 +51,18 @@ class ColorDelegator(Delegator):
|
||||||
apply(self.tag_configure, (tag,), cnf)
|
apply(self.tag_configure, (tag,), cnf)
|
||||||
self.tag_raise('sel')
|
self.tag_raise('sel')
|
||||||
|
|
||||||
cprefs = IdlePrefs.ColorPrefs()
|
cconf = IdleConf.getsection('Colors')
|
||||||
|
|
||||||
tagdefs = {
|
tagdefs = {
|
||||||
"COMMENT": {"foreground": cprefs.CComment[0],
|
"COMMENT": cconf.getcolor("comment"),
|
||||||
"background": cprefs.CComment[1]},
|
"KEYWORD": cconf.getcolor("keyword"),
|
||||||
"KEYWORD": {"foreground": cprefs.CKeyword[0],
|
"STRING": cconf.getcolor("string"),
|
||||||
"background": cprefs.CKeyword[1]},
|
"DEFINITION": cconf.getcolor("definition"),
|
||||||
"STRING": {"foreground": cprefs.CString[0],
|
"SYNC": cconf.getcolor("sync"),
|
||||||
"background": cprefs.CString[1]},
|
"TODO": cconf.getcolor("todo"),
|
||||||
"DEFINITION": {"foreground": cprefs.CDefinition[0],
|
"BREAK": cconf.getcolor("break"),
|
||||||
"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]},
|
|
||||||
|
|
||||||
# The following is used by ReplaceDialog:
|
# The following is used by ReplaceDialog:
|
||||||
"hit": {"foreground": cprefs.CHit[0],
|
"hit": cconf.getcolor("hit"),
|
||||||
"background": cprefs.CHit[1]},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def insert(self, index, chars, tags=None):
|
def insert(self, index, chars, tags=None):
|
||||||
|
|
|
@ -8,23 +8,7 @@ import tkSimpleDialog
|
||||||
import tkMessageBox
|
import tkMessageBox
|
||||||
import idlever
|
import idlever
|
||||||
import WindowList
|
import WindowList
|
||||||
|
from IdleConf import IdleConf
|
||||||
# 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)
|
|
||||||
|
|
||||||
# The default tab setting for a Text widget, in average-width characters.
|
# The default tab setting for a Text widget, in average-width characters.
|
||||||
TK_TABWIDTH_DEFAULT = 8
|
TK_TABWIDTH_DEFAULT = 8
|
||||||
|
@ -110,7 +94,8 @@ class EditorWindow:
|
||||||
vars = {}
|
vars = {}
|
||||||
|
|
||||||
def __init__(self, flist=None, filename=None, key=None, root=None):
|
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
|
self.flist = flist
|
||||||
root = root or flist.root
|
root = root or flist.root
|
||||||
self.root = root
|
self.root = root
|
||||||
|
@ -121,13 +106,14 @@ class EditorWindow:
|
||||||
self.vbar = vbar = Scrollbar(top, name='vbar')
|
self.vbar = vbar = Scrollbar(top, name='vbar')
|
||||||
self.text_frame = text_frame = Frame(top)
|
self.text_frame = text_frame = Frame(top)
|
||||||
self.text = text = Text(text_frame, name='text', padx=5,
|
self.text = text = Text(text_frame, name='text', padx=5,
|
||||||
foreground=cprefs.CNormal[0],
|
foreground=coconf.getdef('normal-foreground'),
|
||||||
background=cprefs.CNormal[1],
|
background=coconf.getdef('normal-background'),
|
||||||
highlightcolor=cprefs.CHilite[0],
|
highlightcolor=coconf.getdef('hilite-foreground'),
|
||||||
highlightbackground=cprefs.CHilite[1],
|
highlightbackground=coconf.getdef('hilite-background'),
|
||||||
insertbackground=cprefs.CCursor[1],
|
insertbackground=coconf.getdef('cursor-background'),
|
||||||
width=WIDTH, height=HEIGHT,
|
width=edconf.getint('width'),
|
||||||
wrap="none")
|
height=edconf.getint('height'),
|
||||||
|
wrap="none")
|
||||||
|
|
||||||
self.createmenubar()
|
self.createmenubar()
|
||||||
self.apply_bindings()
|
self.apply_bindings()
|
||||||
|
@ -156,7 +142,7 @@ class EditorWindow:
|
||||||
vbar.pack(side=RIGHT, fill=Y)
|
vbar.pack(side=RIGHT, fill=Y)
|
||||||
|
|
||||||
text['yscrollcommand'] = vbar.set
|
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_frame.pack(side=LEFT, fill=BOTH, expand=1)
|
||||||
text.pack(side=TOP, fill=BOTH, expand=1)
|
text.pack(side=TOP, fill=BOTH, expand=1)
|
||||||
text.focus_set()
|
text.focus_set()
|
||||||
|
@ -544,8 +530,7 @@ class EditorWindow:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
def get_standard_extension_names(self):
|
def get_standard_extension_names(self):
|
||||||
import extend
|
return IdleConf.getextensions()
|
||||||
return extend.standard
|
|
||||||
|
|
||||||
def load_extension(self, name):
|
def load_extension(self, name):
|
||||||
mod = __import__(name, globals(), locals(), [])
|
mod = __import__(name, globals(), locals(), [])
|
||||||
|
|
|
@ -14,6 +14,7 @@ import string
|
||||||
|
|
||||||
import PyParse
|
import PyParse
|
||||||
from AutoIndent import AutoIndent, index2line
|
from AutoIndent import AutoIndent, index2line
|
||||||
|
from IdleConf import IdleConf
|
||||||
|
|
||||||
class ParenMatch:
|
class ParenMatch:
|
||||||
"""Highlight matching parentheses
|
"""Highlight matching parentheses
|
||||||
|
@ -55,12 +56,12 @@ class ParenMatch:
|
||||||
windows_keydefs = {}
|
windows_keydefs = {}
|
||||||
unix_keydefs = {}
|
unix_keydefs = {}
|
||||||
|
|
||||||
STYLE = "default" # or "expression"
|
iconf = IdleConf.getsection('ParenMatch')
|
||||||
FLASH_DELAY = 500
|
STYLE = iconf.get('style')
|
||||||
HILITE_CONFIG = {"foreground": "black",
|
FLASH_DELAY = iconf.getint('flash-delay')
|
||||||
"background": "#43cd80", # SeaGreen3
|
HILITE_CONFIG = iconf.getcolor('hilite')
|
||||||
}
|
BELL = iconf.getboolean('bell')
|
||||||
BELL = 1 # set to false for no bell
|
del iconf
|
||||||
|
|
||||||
def __init__(self, editwin):
|
def __init__(self, editwin):
|
||||||
self.editwin = editwin
|
self.editwin = editwin
|
||||||
|
@ -156,9 +157,8 @@ class LastOpenBracketFinder:
|
||||||
startat = max(lno - context, 1)
|
startat = max(lno - context, 1)
|
||||||
startatindex = `startat` + ".0"
|
startatindex = `startat` + ".0"
|
||||||
# rawtext needs to contain everything up to the last
|
# rawtext needs to contain everything up to the last
|
||||||
# character, which was the close paren. also need to
|
# character, which was the close paren. the parser also
|
||||||
# append "\n" to please the parser, which seems to expect
|
# requires that the last line ends with "\n"
|
||||||
# a complete line
|
|
||||||
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
|
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
|
||||||
y.set_str(rawtext)
|
y.set_str(rawtext)
|
||||||
bod = y.find_good_parse_start(
|
bod = y.find_good_parse_start(
|
||||||
|
@ -174,9 +174,8 @@ class LastOpenBracketFinder:
|
||||||
"""Return the location of the last open paren"""
|
"""Return the location of the last open paren"""
|
||||||
lno = index2line(self.text.index("insert"))
|
lno = index2line(self.text.index("insert"))
|
||||||
i, buf = self._find_offset_in_buf(lno)
|
i, buf = self._find_offset_in_buf(lno)
|
||||||
if i is None:
|
if i is None \
|
||||||
return i
|
or keysym_type(buf[i]) != right_keysym_type:
|
||||||
if keysym_type(buf[i]) != right_keysym_type:
|
|
||||||
return None
|
return None
|
||||||
lines_back = buf[i:].count("\n") - 1
|
lines_back = buf[i:].count("\n") - 1
|
||||||
# subtract one for the "\n" added to please the parser
|
# subtract one for the "\n" added to please the parser
|
||||||
|
|
|
@ -16,6 +16,7 @@ from EditorWindow import EditorWindow, fixwordbreaks
|
||||||
from FileList import FileList
|
from FileList import FileList
|
||||||
from ColorDelegator import ColorDelegator
|
from ColorDelegator import ColorDelegator
|
||||||
from OutputWindow import OutputWindow
|
from OutputWindow import OutputWindow
|
||||||
|
from IdleConf import IdleConf
|
||||||
import idlever
|
import idlever
|
||||||
|
|
||||||
# We need to patch linecache.checkcache, because we don't want it
|
# We need to patch linecache.checkcache, because we don't want it
|
||||||
|
@ -114,21 +115,15 @@ class ModifiedColorDelegator(ColorDelegator):
|
||||||
ColorDelegator.recolorize_main(self)
|
ColorDelegator.recolorize_main(self)
|
||||||
|
|
||||||
tagdefs = ColorDelegator.tagdefs.copy()
|
tagdefs = ColorDelegator.tagdefs.copy()
|
||||||
cprefs = ColorDelegator.cprefs
|
cconf = IdleConf.getsection('Colors')
|
||||||
|
|
||||||
tagdefs.update({
|
tagdefs.update({
|
||||||
"stdin": {"foreground": cprefs.CStdIn[0],
|
"stdin": cconf.getcolor("stdin"),
|
||||||
"background": cprefs.CStdIn[1]},
|
"stdout": cconf.getcolor("stdout"),
|
||||||
"stdout": {"foreground": cprefs.CStdOut[0],
|
"stderr": cconf.getcolor("stderr"),
|
||||||
"background": cprefs.CStdOut[1]},
|
"console": cconf.getcolor("console"),
|
||||||
"stderr": {"foreground": cprefs.CStdErr[0],
|
"ERROR": cconf.getcolor("ERROR"),
|
||||||
"background": cprefs.CStdErr[1]},
|
None: cconf.getcolor("normal"),
|
||||||
"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]},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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",
|
|
||||||
]
|
|
|
@ -1,3 +1,12 @@
|
||||||
#! /usr/bin/env python
|
#! /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
|
import PyShell
|
||||||
PyShell.main()
|
PyShell.main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue