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

Skip to content

Commit 73360a3

Browse files
committed
Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
M ClassBrowser.py M ColorDelegator.py M EditorWindow.py M NEWS.txt M PyShell.py M TreeWidget.py M config-highlight.def M configDialog.py M configHandler.py
1 parent 4102478 commit 73360a3

9 files changed

Lines changed: 42 additions & 16 deletions

File tree

Lib/idlelib/ClassBrowser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import PyShell
1818
from WindowList import ListedToplevel
1919
from TreeWidget import TreeNode, TreeItem, ScrolledCanvas
20+
from configHandler import idleConf
2021

2122
class ClassBrowser:
2223

@@ -42,7 +43,9 @@ def init(self, flist):
4243
self.settitle()
4344
top.focus_set()
4445
# create scrolled canvas
45-
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
46+
theme = idleConf.GetOption('main','Theme','name')
47+
background = idleConf.GetHighlight(theme, 'normal')['background']
48+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0, takefocus=1)
4649
sc.frame.pack(expand=1, fill="both")
4750
item = self.rootnode()
4851
self.node = node = TreeNode(sc.canvas, None, item)

Lib/idlelib/ColorDelegator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
import re
33
import keyword
4+
import __builtin__
45
from Tkinter import *
56
from Delegator import Delegator
67
from configHandler import idleConf
@@ -17,13 +18,16 @@ def any(name, list):
1718

1819
def make_pat():
1920
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
21+
builtinlist = [str(name) for name in dir(__builtin__)
22+
if not name.startswith('_')]
23+
builtin = r"([^\\.]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
2024
comment = any("COMMENT", [r"#[^\n]*"])
2125
sqstring = r"(\b[rR])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
2226
dqstring = r'(\b[rR])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
2327
sq3string = r"(\b[rR])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
2428
dq3string = r'(\b[rR])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
2529
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
26-
return kw + "|" + comment + "|" + string + "|" + any("SYNC", [r"\n"])
30+
return kw + "|" + builtin + "|" + comment + "|" + string + "|" + any("SYNC", [r"\n"])
2731

2832
prog = re.compile(make_pat(), re.S)
2933
idprog = re.compile(r"\s+(\w+)", re.S)
@@ -58,6 +62,7 @@ def LoadTagDefs(self):
5862
self.tagdefs = {
5963
"COMMENT": idleConf.GetHighlight(theme, "comment"),
6064
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
65+
"BUILTIN": idleConf.GetHighlight(theme, "builtin"),
6166
"STRING": idleConf.GetHighlight(theme, "string"),
6267
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
6368
"SYNC": {'background':None,'foreground':None},
@@ -68,7 +73,7 @@ def LoadTagDefs(self):
6873
"hit": idleConf.GetHighlight(theme, "hit"),
6974
}
7075

71-
if DEBUG: print 'tagdefs',tagdefs
76+
if DEBUG: print 'tagdefs',self.tagdefs
7277

7378
def insert(self, index, chars, tags=None):
7479
index = self.index(index)

Lib/idlelib/EditorWindow.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ def ResetColorizer(self):
510510
if self.color:
511511
self.color = self.ColorDelegator()
512512
self.per.insertfilter(self.color)
513+
theme = idleConf.GetOption('main','Theme','name')
514+
self.text.config(idleConf.GetHighlight(theme, "normal"))
513515

514516
def ResetFont(self):
515517
"Update the text widgets' font if it is changed"

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ What's New in IDLE 1.1a0?
33

44
*Release date: XX-XXX-2004*
55

6+
- Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
7+
68
- rpc.py:SocketIO - Large modules were generating large pickles when downloaded
79
to the execution server. The return of the OK response from the subprocess
810
initialization was interfering and causing the sending socket to be not

Lib/idlelib/PyShell.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ def remote_stack_viewer(self):
528528
item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid)
529529
from TreeWidget import ScrolledCanvas, TreeNode
530530
top = Toplevel(self.tkconsole.root)
531-
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
531+
theme = idleConf.GetOption('main','Theme','name')
532+
background = idleConf.GetHighlight(theme, 'normal')['background']
533+
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
532534
sc.frame.pack(expand=1, fill="both")
533535
node = TreeNode(sc.canvas, None, item)
534536
node.expand()

Lib/idlelib/TreeWidget.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import imp
2121

2222
import ZoomHeight
23+
from configHandler import idleConf
2324

2425
ICONDIR = "Icons"
2526

@@ -249,10 +250,11 @@ def drawtext(self):
249250
except AttributeError:
250251
# padding carefully selected (on Windows) to match Entry widget:
251252
self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
253+
theme = idleConf.GetOption('main','Theme','name')
252254
if self.selected:
253-
self.label.configure(fg="white", bg="darkblue")
255+
self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
254256
else:
255-
self.label.configure(fg="black", bg="white")
257+
self.label.configure(idleConf.GetHighlight(theme, 'normal'))
256258
id = self.canvas.create_window(textx, texty,
257259
anchor="nw", window=self.label)
258260
self.label.bind("<1>", self.select_or_edit)

Lib/idlelib/config-highlight.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ normal-foreground= #000000
66
normal-background= #ffffff
77
keyword-foreground= #ff7700
88
keyword-background= #ffffff
9+
builtin-foreground= #ca00ca
10+
builtin-background= #ffffff
911
comment-foreground= #dd0000
1012
comment-background= #ffffff
1113
string-foreground= #00aa00
@@ -35,6 +37,8 @@ normal-foreground= #000000
3537
normal-background= #ffffff
3638
keyword-foreground= #ff7700
3739
keyword-background= #ffffff
40+
builtin-foreground= #ca00ca
41+
builtin-background= #ffffff
3842
comment-foreground= #dd0000
3943
comment-background= #ffffff
4044
string-foreground= #00aa00

Lib/idlelib/configDialog.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ def __init__(self,parent,title):
3535
self.themeElements={'Normal Text':('normal','00'),
3636
'Python Keywords':('keyword','01'),
3737
'Python Definitions':('definition','02'),
38-
'Python Comments':('comment','03'),
39-
'Python Strings':('string','04'),
40-
'Selected Text':('hilite','05'),
41-
'Found Text':('hit','06'),
42-
'Cursor':('cursor','07'),
43-
'Error Text':('error','08'),
44-
'Shell Normal Text':('console','09'),
45-
'Shell Stdout Text':('stdout','10'),
46-
'Shell Stderr Text':('stderr','11')}
38+
'Python Builtins':('builtin', '03'),
39+
'Python Comments':('comment','04'),
40+
'Python Strings':('string','05'),
41+
'Selected Text':('hilite','06'),
42+
'Found Text':('hit','07'),
43+
'Cursor':('cursor','08'),
44+
'Error Text':('error','09'),
45+
'Shell Normal Text':('console','10'),
46+
'Shell Stdout Text':('stdout','11'),
47+
'Shell Stderr Text':('stderr','12'),
48+
}
4749
self.ResetChangedItems() #load initial values in changed items dict
4850
self.CreateWidgets()
4951
self.resizable(height=FALSE,width=FALSE)
@@ -197,7 +199,9 @@ def CreatePageHighlight(self):
197199
(' ','normal'),('func','definition'),('(param):','normal'),
198200
('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
199201
("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
200-
('\n var2 = ','normal'),("'found'",'hit'),('\n\n','normal'),
202+
('\n var2 = ','normal'),("'found'",'hit'),
203+
('\n var3 = ','normal'),('list', 'builtin'), ('(','normal'),
204+
('None', 'builtin'),(')\n\n','normal'),
201205
(' error ','error'),(' ','normal'),('cursor |','cursor'),
202206
('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
203207
(' ','normal'),('stderr','stderr'),('\n','normal'))

Lib/idlelib/configHandler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def GetThemeDict(self,type,themeName):
306306
'normal-background':'#ffffff',
307307
'keyword-foreground':'#000000',
308308
'keyword-background':'#ffffff',
309+
'builtin-foreground':'#000000',
310+
'builtin-background':'#ffffff',
309311
'comment-foreground':'#000000',
310312
'comment-background':'#ffffff',
311313
'string-foreground':'#000000',

0 commit comments

Comments
 (0)