Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e81f28b

Browse files
committed
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.
1 parent 583abb8 commit e81f28b

6 files changed

Lines changed: 51 additions & 86 deletions

File tree

Tools/idle/ColorDelegator.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import keyword
55
from Tkinter import *
66
from Delegator import Delegator
7-
import IdlePrefs
7+
from IdleConf import IdleConf
88

99
#$ event <<toggle-auto-coloring>>
1010
#$ win <Control-slash>
@@ -51,29 +51,18 @@ def config_colors(self):
5151
apply(self.tag_configure, (tag,), cnf)
5252
self.tag_raise('sel')
5353

54-
cprefs = IdlePrefs.ColorPrefs()
54+
cconf = IdleConf.getsection('Colors')
5555

5656
tagdefs = {
57-
"COMMENT": {"foreground": cprefs.CComment[0],
58-
"background": cprefs.CComment[1]},
59-
"KEYWORD": {"foreground": cprefs.CKeyword[0],
60-
"background": cprefs.CKeyword[1]},
61-
"STRING": {"foreground": cprefs.CString[0],
62-
"background": cprefs.CString[1]},
63-
"DEFINITION": {"foreground": cprefs.CDefinition[0],
64-
"background": cprefs.CDefinition[1]},
65-
66-
"SYNC": {"background": cprefs.CSync[0],
67-
"background": cprefs.CSync[1]},
68-
"TODO": {"background": cprefs.CTodo[0],
69-
"background": cprefs.CTodo[1]},
70-
71-
"BREAK": {"background": cprefs.CBreak[0],
72-
"background": cprefs.CBreak[1]},
73-
57+
"COMMENT": cconf.getcolor("comment"),
58+
"KEYWORD": cconf.getcolor("keyword"),
59+
"STRING": cconf.getcolor("string"),
60+
"DEFINITION": cconf.getcolor("definition"),
61+
"SYNC": cconf.getcolor("sync"),
62+
"TODO": cconf.getcolor("todo"),
63+
"BREAK": cconf.getcolor("break"),
7464
# The following is used by ReplaceDialog:
75-
"hit": {"foreground": cprefs.CHit[0],
76-
"background": cprefs.CHit[1]},
65+
"hit": cconf.getcolor("hit"),
7766
}
7867

7968
def insert(self, index, chars, tags=None):

Tools/idle/EditorWindow.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,7 @@
88
import tkMessageBox
99
import idlever
1010
import WindowList
11-
12-
# Customization of default window size and font
13-
# standard
14-
WIDTH = 80
15-
HEIGHT = 24
16-
if sys.platform[:3] == 'win':
17-
FONT = ("courier new", 10)
18-
else:
19-
FONT = ("courier", 10)
20-
if 0:
21-
# for demos (on Windows)
22-
WIDTH = 70
23-
HEIGHT = 16
24-
FONT = ("lucida console", 14)
25-
if 0:
26-
# for Windows 98
27-
FONT = ("lucida console", 8)
11+
from IdleConf import IdleConf
2812

2913
# The default tab setting for a Text widget, in average-width characters.
3014
TK_TABWIDTH_DEFAULT = 8
@@ -110,7 +94,8 @@ class EditorWindow:
11094
vars = {}
11195

11296
def __init__(self, flist=None, filename=None, key=None, root=None):
113-
cprefs = self.ColorDelegator.cprefs
97+
edconf = IdleConf.getsection('EditorWindow')
98+
coconf = IdleConf.getsection('Colors')
11499
self.flist = flist
115100
root = root or flist.root
116101
self.root = root
@@ -121,13 +106,14 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
121106
self.vbar = vbar = Scrollbar(top, name='vbar')
122107
self.text_frame = text_frame = Frame(top)
123108
self.text = text = Text(text_frame, name='text', padx=5,
124-
foreground=cprefs.CNormal[0],
125-
background=cprefs.CNormal[1],
126-
highlightcolor=cprefs.CHilite[0],
127-
highlightbackground=cprefs.CHilite[1],
128-
insertbackground=cprefs.CCursor[1],
129-
width=WIDTH, height=HEIGHT,
130-
wrap="none")
109+
foreground=coconf.getdef('normal-foreground'),
110+
background=coconf.getdef('normal-background'),
111+
highlightcolor=coconf.getdef('hilite-foreground'),
112+
highlightbackground=coconf.getdef('hilite-background'),
113+
insertbackground=coconf.getdef('cursor-background'),
114+
width=edconf.getint('width'),
115+
height=edconf.getint('height'),
116+
wrap="none")
131117

132118
self.createmenubar()
133119
self.apply_bindings()
@@ -156,7 +142,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
156142
vbar.pack(side=RIGHT, fill=Y)
157143

158144
text['yscrollcommand'] = vbar.set
159-
text['font'] = FONT
145+
text['font'] = edconf.get('font-name'), edconf.get('font-size')
160146
text_frame.pack(side=LEFT, fill=BOTH, expand=1)
161147
text.pack(side=TOP, fill=BOTH, expand=1)
162148
text.focus_set()
@@ -544,8 +530,7 @@ def load_standard_extensions(self):
544530
traceback.print_exc()
545531

546532
def get_standard_extension_names(self):
547-
import extend
548-
return extend.standard
533+
return IdleConf.getextensions()
549534

550535
def load_extension(self, name):
551536
mod = __import__(name, globals(), locals(), [])

Tools/idle/ParenMatch.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import PyParse
1616
from AutoIndent import AutoIndent, index2line
17+
from IdleConf import IdleConf
1718

1819
class ParenMatch:
1920
"""Highlight matching parentheses
@@ -55,12 +56,12 @@ class ParenMatch:
5556
windows_keydefs = {}
5657
unix_keydefs = {}
5758

58-
STYLE = "default" # or "expression"
59-
FLASH_DELAY = 500
60-
HILITE_CONFIG = {"foreground": "black",
61-
"background": "#43cd80", # SeaGreen3
62-
}
63-
BELL = 1 # set to false for no bell
59+
iconf = IdleConf.getsection('ParenMatch')
60+
STYLE = iconf.get('style')
61+
FLASH_DELAY = iconf.getint('flash-delay')
62+
HILITE_CONFIG = iconf.getcolor('hilite')
63+
BELL = iconf.getboolean('bell')
64+
del iconf
6465

6566
def __init__(self, editwin):
6667
self.editwin = editwin
@@ -156,9 +157,8 @@ def _find_offset_in_buf(self, lno):
156157
startat = max(lno - context, 1)
157158
startatindex = `startat` + ".0"
158159
# rawtext needs to contain everything up to the last
159-
# character, which was the close paren. also need to
160-
# append "\n" to please the parser, which seems to expect
161-
# a complete line
160+
# character, which was the close paren. the parser also
161+
# requires that the last line ends with "\n"
162162
rawtext = self.text.get(startatindex, "insert")[:-1] + "\n"
163163
y.set_str(rawtext)
164164
bod = y.find_good_parse_start(
@@ -174,9 +174,8 @@ def find(self, right_keysym_type):
174174
"""Return the location of the last open paren"""
175175
lno = index2line(self.text.index("insert"))
176176
i, buf = self._find_offset_in_buf(lno)
177-
if i is None:
178-
return i
179-
if keysym_type(buf[i]) != right_keysym_type:
177+
if i is None \
178+
or keysym_type(buf[i]) != right_keysym_type:
180179
return None
181180
lines_back = buf[i:].count("\n") - 1
182181
# subtract one for the "\n" added to please the parser

Tools/idle/PyShell.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from FileList import FileList
1717
from ColorDelegator import ColorDelegator
1818
from OutputWindow import OutputWindow
19+
from IdleConf import IdleConf
1920
import idlever
2021

2122
# We need to patch linecache.checkcache, because we don't want it
@@ -114,21 +115,15 @@ def recolorize_main(self):
114115
ColorDelegator.recolorize_main(self)
115116

116117
tagdefs = ColorDelegator.tagdefs.copy()
117-
cprefs = ColorDelegator.cprefs
118+
cconf = IdleConf.getsection('Colors')
118119

119120
tagdefs.update({
120-
"stdin": {"foreground": cprefs.CStdIn[0],
121-
"background": cprefs.CStdIn[1]},
122-
"stdout": {"foreground": cprefs.CStdOut[0],
123-
"background": cprefs.CStdOut[1]},
124-
"stderr": {"foreground": cprefs.CStdErr[0],
125-
"background": cprefs.CStdErr[1]},
126-
"console": {"foreground": cprefs.CConsole[0],
127-
"background": cprefs.CConsole[1]},
128-
"ERROR": {"background": cprefs.CError[0],
129-
"background": cprefs.CError[1]},
130-
None: {"foreground": cprefs.CNormal[0],
131-
"background": cprefs.CNormal[1]},
121+
"stdin": cconf.getcolor("stdin"),
122+
"stdout": cconf.getcolor("stdout"),
123+
"stderr": cconf.getcolor("stderr"),
124+
"console": cconf.getcolor("console"),
125+
"ERROR": cconf.getcolor("ERROR"),
126+
None: cconf.getcolor("normal"),
132127
})
133128

134129

Tools/idle/extend.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

Tools/idle/idle.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
#! /usr/bin/env python
2+
3+
import os
4+
import sys
5+
import IdleConf
6+
7+
idle_dir = os.path.split(sys.argv[0])[0]
8+
IdleConf.load(idle_dir)
9+
10+
# defer importing Pyshell until IdleConf is loaded
211
import PyShell
312
PyShell.main()

0 commit comments

Comments
 (0)