mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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
This commit is contained in:
parent
4102478f46
commit
73360a3e61
9 changed files with 42 additions and 16 deletions
|
@ -17,6 +17,7 @@ import pyclbr
|
|||
import PyShell
|
||||
from WindowList import ListedToplevel
|
||||
from TreeWidget import TreeNode, TreeItem, ScrolledCanvas
|
||||
from configHandler import idleConf
|
||||
|
||||
class ClassBrowser:
|
||||
|
||||
|
@ -42,7 +43,9 @@ class ClassBrowser:
|
|||
self.settitle()
|
||||
top.focus_set()
|
||||
# create scrolled canvas
|
||||
sc = ScrolledCanvas(top, bg="white", highlightthickness=0, takefocus=1)
|
||||
theme = idleConf.GetOption('main','Theme','name')
|
||||
background = idleConf.GetHighlight(theme, 'normal')['background']
|
||||
sc = ScrolledCanvas(top, bg=background, highlightthickness=0, takefocus=1)
|
||||
sc.frame.pack(expand=1, fill="both")
|
||||
item = self.rootnode()
|
||||
self.node = node = TreeNode(sc.canvas, None, item)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import time
|
||||
import re
|
||||
import keyword
|
||||
import __builtin__
|
||||
from Tkinter import *
|
||||
from Delegator import Delegator
|
||||
from configHandler import idleConf
|
||||
|
@ -17,13 +18,16 @@ def any(name, list):
|
|||
|
||||
def make_pat():
|
||||
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
|
||||
builtinlist = [str(name) for name in dir(__builtin__)
|
||||
if not name.startswith('_')]
|
||||
builtin = r"([^\\.]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
|
||||
comment = any("COMMENT", [r"#[^\n]*"])
|
||||
sqstring = r"(\b[rR])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
|
||||
dqstring = r'(\b[rR])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
|
||||
sq3string = r"(\b[rR])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
|
||||
dq3string = r'(\b[rR])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
|
||||
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
|
||||
return kw + "|" + comment + "|" + string + "|" + any("SYNC", [r"\n"])
|
||||
return kw + "|" + builtin + "|" + comment + "|" + string + "|" + any("SYNC", [r"\n"])
|
||||
|
||||
prog = re.compile(make_pat(), re.S)
|
||||
idprog = re.compile(r"\s+(\w+)", re.S)
|
||||
|
@ -58,6 +62,7 @@ class ColorDelegator(Delegator):
|
|||
self.tagdefs = {
|
||||
"COMMENT": idleConf.GetHighlight(theme, "comment"),
|
||||
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
|
||||
"BUILTIN": idleConf.GetHighlight(theme, "builtin"),
|
||||
"STRING": idleConf.GetHighlight(theme, "string"),
|
||||
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
|
||||
"SYNC": {'background':None,'foreground':None},
|
||||
|
@ -68,7 +73,7 @@ class ColorDelegator(Delegator):
|
|||
"hit": idleConf.GetHighlight(theme, "hit"),
|
||||
}
|
||||
|
||||
if DEBUG: print 'tagdefs',tagdefs
|
||||
if DEBUG: print 'tagdefs',self.tagdefs
|
||||
|
||||
def insert(self, index, chars, tags=None):
|
||||
index = self.index(index)
|
||||
|
|
|
@ -510,6 +510,8 @@ class EditorWindow:
|
|||
if self.color:
|
||||
self.color = self.ColorDelegator()
|
||||
self.per.insertfilter(self.color)
|
||||
theme = idleConf.GetOption('main','Theme','name')
|
||||
self.text.config(idleConf.GetHighlight(theme, "normal"))
|
||||
|
||||
def ResetFont(self):
|
||||
"Update the text widgets' font if it is changed"
|
||||
|
|
|
@ -3,6 +3,8 @@ What's New in IDLE 1.1a0?
|
|||
|
||||
*Release date: XX-XXX-2004*
|
||||
|
||||
- Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe
|
||||
|
||||
- rpc.py:SocketIO - Large modules were generating large pickles when downloaded
|
||||
to the execution server. The return of the OK response from the subprocess
|
||||
initialization was interfering and causing the sending socket to be not
|
||||
|
|
|
@ -528,7 +528,9 @@ class ModifiedInterpreter(InteractiveInterpreter):
|
|||
item = RemoteObjectBrowser.StubObjectTreeItem(self.rpcclt, oid)
|
||||
from TreeWidget import ScrolledCanvas, TreeNode
|
||||
top = Toplevel(self.tkconsole.root)
|
||||
sc = ScrolledCanvas(top, bg="white", highlightthickness=0)
|
||||
theme = idleConf.GetOption('main','Theme','name')
|
||||
background = idleConf.GetHighlight(theme, 'normal')['background']
|
||||
sc = ScrolledCanvas(top, bg=background, highlightthickness=0)
|
||||
sc.frame.pack(expand=1, fill="both")
|
||||
node = TreeNode(sc.canvas, None, item)
|
||||
node.expand()
|
||||
|
|
|
@ -20,6 +20,7 @@ from Tkinter import *
|
|||
import imp
|
||||
|
||||
import ZoomHeight
|
||||
from configHandler import idleConf
|
||||
|
||||
ICONDIR = "Icons"
|
||||
|
||||
|
@ -249,10 +250,11 @@ class TreeNode:
|
|||
except AttributeError:
|
||||
# padding carefully selected (on Windows) to match Entry widget:
|
||||
self.label = Label(self.canvas, text=text, bd=0, padx=2, pady=2)
|
||||
theme = idleConf.GetOption('main','Theme','name')
|
||||
if self.selected:
|
||||
self.label.configure(fg="white", bg="darkblue")
|
||||
self.label.configure(idleConf.GetHighlight(theme, 'hilite'))
|
||||
else:
|
||||
self.label.configure(fg="black", bg="white")
|
||||
self.label.configure(idleConf.GetHighlight(theme, 'normal'))
|
||||
id = self.canvas.create_window(textx, texty,
|
||||
anchor="nw", window=self.label)
|
||||
self.label.bind("<1>", self.select_or_edit)
|
||||
|
|
|
@ -6,6 +6,8 @@ normal-foreground= #000000
|
|||
normal-background= #ffffff
|
||||
keyword-foreground= #ff7700
|
||||
keyword-background= #ffffff
|
||||
builtin-foreground= #ca00ca
|
||||
builtin-background= #ffffff
|
||||
comment-foreground= #dd0000
|
||||
comment-background= #ffffff
|
||||
string-foreground= #00aa00
|
||||
|
@ -35,6 +37,8 @@ normal-foreground= #000000
|
|||
normal-background= #ffffff
|
||||
keyword-foreground= #ff7700
|
||||
keyword-background= #ffffff
|
||||
builtin-foreground= #ca00ca
|
||||
builtin-background= #ffffff
|
||||
comment-foreground= #dd0000
|
||||
comment-background= #ffffff
|
||||
string-foreground= #00aa00
|
||||
|
|
|
@ -35,15 +35,17 @@ class ConfigDialog(Toplevel):
|
|||
self.themeElements={'Normal Text':('normal','00'),
|
||||
'Python Keywords':('keyword','01'),
|
||||
'Python Definitions':('definition','02'),
|
||||
'Python Comments':('comment','03'),
|
||||
'Python Strings':('string','04'),
|
||||
'Selected Text':('hilite','05'),
|
||||
'Found Text':('hit','06'),
|
||||
'Cursor':('cursor','07'),
|
||||
'Error Text':('error','08'),
|
||||
'Shell Normal Text':('console','09'),
|
||||
'Shell Stdout Text':('stdout','10'),
|
||||
'Shell Stderr Text':('stderr','11')}
|
||||
'Python Builtins':('builtin', '03'),
|
||||
'Python Comments':('comment','04'),
|
||||
'Python Strings':('string','05'),
|
||||
'Selected Text':('hilite','06'),
|
||||
'Found Text':('hit','07'),
|
||||
'Cursor':('cursor','08'),
|
||||
'Error Text':('error','09'),
|
||||
'Shell Normal Text':('console','10'),
|
||||
'Shell Stdout Text':('stdout','11'),
|
||||
'Shell Stderr Text':('stderr','12'),
|
||||
}
|
||||
self.ResetChangedItems() #load initial values in changed items dict
|
||||
self.CreateWidgets()
|
||||
self.resizable(height=FALSE,width=FALSE)
|
||||
|
@ -197,7 +199,9 @@ class ConfigDialog(Toplevel):
|
|||
(' ','normal'),('func','definition'),('(param):','normal'),
|
||||
('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
|
||||
("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'),
|
||||
('\n var2 = ','normal'),("'found'",'hit'),('\n\n','normal'),
|
||||
('\n var2 = ','normal'),("'found'",'hit'),
|
||||
('\n var3 = ','normal'),('list', 'builtin'), ('(','normal'),
|
||||
('None', 'builtin'),(')\n\n','normal'),
|
||||
(' error ','error'),(' ','normal'),('cursor |','cursor'),
|
||||
('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'),
|
||||
(' ','normal'),('stderr','stderr'),('\n','normal'))
|
||||
|
|
|
@ -306,6 +306,8 @@ class IdleConf:
|
|||
'normal-background':'#ffffff',
|
||||
'keyword-foreground':'#000000',
|
||||
'keyword-background':'#ffffff',
|
||||
'builtin-foreground':'#000000',
|
||||
'builtin-background':'#ffffff',
|
||||
'comment-foreground':'#000000',
|
||||
'comment-background':'#ffffff',
|
||||
'string-foreground':'#000000',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue