Skip to content

Commit b77d343

Browse files
author
Steven M. Gava
committed
First work on making config changes dynamic,
dynamic theme changes
1 parent 03b1883 commit b77d343

File tree

5 files changed

+56
-36
lines changed

5 files changed

+56
-36
lines changed

Lib/idlelib/ColorDelegator.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self):
3737
self.prog = prog
3838
self.idprog = idprog
3939
self.asprog = asprog
40+
self.LoadTagDefs()
4041

4142
def setdelegate(self, delegate):
4243
if self.delegate is not None:
@@ -52,21 +53,21 @@ def config_colors(self):
5253
if cnf:
5354
apply(self.tag_configure, (tag,), cnf)
5455
self.tag_raise('sel')
55-
56-
theme = idleConf.GetOption('main','Theme','name')
57-
58-
tagdefs = {
59-
"COMMENT": idleConf.GetHighlight(theme, "comment"),
60-
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
61-
"STRING": idleConf.GetHighlight(theme, "string"),
62-
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
63-
"SYNC": {'background':None,'foreground':None},
64-
"TODO": {'background':None,'foreground':None},
65-
"BREAK": idleConf.GetHighlight(theme, "break"),
66-
# The following is used by ReplaceDialog:
67-
"hit": idleConf.GetHighlight(theme, "hit"),
68-
}
6956

57+
def LoadTagDefs(self):
58+
theme = idleConf.GetOption('main','Theme','name')
59+
self.tagdefs = {
60+
"COMMENT": idleConf.GetHighlight(theme, "comment"),
61+
"KEYWORD": idleConf.GetHighlight(theme, "keyword"),
62+
"STRING": idleConf.GetHighlight(theme, "string"),
63+
"DEFINITION": idleConf.GetHighlight(theme, "definition"),
64+
"SYNC": {'background':None,'foreground':None},
65+
"TODO": {'background':None,'foreground':None},
66+
"BREAK": idleConf.GetHighlight(theme, "break"),
67+
# The following is used by ReplaceDialog:
68+
"hit": idleConf.GetHighlight(theme, "hit"),
69+
}
70+
7071
if DEBUG: print 'tagdefs',tagdefs
7172

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

Lib/idlelib/EditorWindow.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
102102
self.vars = flist.vars
103103
self.menubar = Menu(root)
104104
self.top = top = self.Toplevel(root, menu=self.menubar)
105+
#self.top.instanceDict makes flist.inversedict avalable to
106+
#configDialog.py so it can access all EditorWindow instaces
107+
self.top.instanceDict=flist.inversedict
105108
self.vbar = vbar = Scrollbar(top, name='vbar')
106109
self.text_frame = text_frame = Frame(top)
107110
self.text = text = Text(text_frame, name='text', padx=5, wrap=None,
@@ -467,6 +470,13 @@ def rmcolorizer(self):
467470
self.per.removefilter(self.color)
468471
self.color = None
469472
self.per.insertfilter(self.undo)
473+
474+
def ResetColorizer(self):
475+
#this function is called from configDialog.py
476+
#to update the colour theme if it is changed
477+
if self.color:
478+
self.color = self.ColorDelegator()
479+
self.per.insertfilter(self.color)
470480

471481
def saved_change_hook(self):
472482
short = self.short_title()

Lib/idlelib/PyShell.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,27 @@ def open_shell(self, event=None):
134134
class ModifiedColorDelegator(ColorDelegator):
135135

136136
# Colorizer for the shell window itself
137+
138+
def __init__(self):
139+
ColorDelegator.__init__(self)
140+
self.LoadTagDefs()
137141

138142
def recolorize_main(self):
139143
self.tag_remove("TODO", "1.0", "iomark")
140144
self.tag_add("SYNC", "1.0", "iomark")
141145
ColorDelegator.recolorize_main(self)
142-
143-
tagdefs = ColorDelegator.tagdefs.copy()
144-
theme = idleConf.GetOption('main','Theme','name')
145-
146-
tagdefs.update({
147-
"stdin": {'background':None,'foreground':None},
148-
"stdout": idleConf.GetHighlight(theme, "stdout"),
149-
"stderr": idleConf.GetHighlight(theme, "stderr"),
150-
"console": idleConf.GetHighlight(theme, "console"),
151-
"ERROR": idleConf.GetHighlight(theme, "error"),
152-
None: idleConf.GetHighlight(theme, "normal"),
153-
})
146+
147+
def LoadTagDefs(self):
148+
ColorDelegator.LoadTagDefs(self)
149+
theme = idleConf.GetOption('main','Theme','name')
150+
self.tagdefs.update({
151+
"stdin": {'background':None,'foreground':None},
152+
"stdout": idleConf.GetHighlight(theme, "stdout"),
153+
"stderr": idleConf.GetHighlight(theme, "stderr"),
154+
"console": idleConf.GetHighlight(theme, "console"),
155+
"ERROR": idleConf.GetHighlight(theme, "error"),
156+
None: idleConf.GetHighlight(theme, "normal"),
157+
})
154158

155159
class ModifiedUndoDelegator(UndoDelegator):
156160

Lib/idlelib/configDialog.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def __init__(self,parent,title):
2323
#Theme Elements. Each theme element key is it's display name.
2424
#The first value of the tuple is the sample area tag name.
2525
#The second value is the display name list sort index.
26-
#The third value indicates whether the element can have a foreground
27-
#or background colour or both.
2826
self.themeElements={'Normal Text':('normal','00'),
2927
'Python Keywords':('keyword','01'),
3028
'Python Definitions':('definition','02'),
@@ -180,8 +178,8 @@ def CreatePageHighlight(self):
180178
frameTheme=Frame(frame,borderwidth=2,relief=GROOVE)
181179
#frameCustom
182180
self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1,
183-
font=('courier',12,''),cursor='hand2',width=10,height=10,
184-
takefocus=FALSE,highlightthickness=0)
181+
font=('courier',12,''),cursor='hand2',width=21,height=10,
182+
takefocus=FALSE,highlightthickness=0,wrap=NONE)
185183
text=self.textHighlightSample
186184
text.bind('<Double-Button-1>',lambda e: 'break')
187185
text.bind('<B1-Motion>',lambda e: 'break')
@@ -514,7 +512,7 @@ def VarChanged_startupEdit(self,*params):
514512
self.AddChangedItem('main','General','editor-on-startup',value)
515513

516514
def ResetChangedItems(self):
517-
#changedItems. When any config item is changed in this dialog, an entry
515+
#When any config item is changed in this dialog, an entry
518516
#should be made in the relevant section (config type) of this
519517
#dictionary. The key should be the config file section name and the
520518
#value a dictionary, whose key:value pairs are item=value pairs for
@@ -1086,14 +1084,15 @@ def SaveAllChangedConfigs(self):
10861084
def ActivateConfigChanges(self):
10871085
#things that need to be done to make
10881086
#applied config changes dynamic:
1089-
#
10901087
#update editor/shell font and repaint
10911088
#dynamically update indentation setttings
10921089
#update theme and repaint
10931090
#update keybindings and re-bind
10941091
#update user help sources menu
1095-
pass
1096-
1092+
winInstances=self.parent.instanceDict.keys()
1093+
for instance in winInstances:
1094+
instance.ResetColorizer()
1095+
10971096
def Cancel(self):
10981097
self.destroy()
10991098

Lib/idlelib/configHandler.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def SetOption(self,section,option,value):
110110
self.set(section,option,value)
111111
return 1
112112

113+
def RemoveFile(self):
114+
"""
115+
Removes the user config file from disk if it exists.
116+
"""
117+
if os.path.exists(self.file):
118+
os.remove(self.file)
119+
113120
def Save(self):
114121
"""
115122
If config isn't empty, write file to disk. If config is empty,
@@ -119,8 +126,7 @@ def Save(self):
119126
cfgFile=open(self.file,'w')
120127
self.write(cfgFile)
121128
else:
122-
if os.path.exists(self.file):
123-
os.remove(self.file)
129+
self.RemoveFile()
124130

125131
class IdleConf:
126132
"""

0 commit comments

Comments
 (0)