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

Skip to content

Commit 9930061

Browse files
author
Steven M. Gava
committed
further config system work
1 parent c99213f commit 9930061

4 files changed

Lines changed: 56 additions & 17 deletions

File tree

Lib/idlelib/PyShell.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from UndoDelegator import UndoDelegator
4444
from OutputWindow import OutputWindow, OnDemandOutputWindow
4545
from IdleConf import idleconf
46+
from configHandler import idleConf
4647
import idlever
4748

4849
# We need to patch linecache.checkcache, because we don't want it
@@ -141,15 +142,15 @@ def recolorize_main(self):
141142
ColorDelegator.recolorize_main(self)
142143

143144
tagdefs = ColorDelegator.tagdefs.copy()
144-
cconf = idleconf.getsection('Colors')
145-
145+
theme = idleConf.GetOption('main','Theme','name')
146146
tagdefs.update({
147-
"stdin": cconf.getcolor("stdin"),
148-
"stdout": cconf.getcolor("stdout"),
149-
"stderr": cconf.getcolor("stderr"),
150-
"console": cconf.getcolor("console"),
151-
"ERROR": cconf.getcolor("ERROR"),
152-
None: cconf.getcolor("normal"),
147+
148+
"stdin": idleConf.GetHighlight(theme, "stdin"),
149+
"stdout": idleConf.GetHighlight(theme, "stdout"),
150+
"stderr": idleConf.GetHighlight(theme, "stderr"),
151+
"console": idleConf.GetHighlight(theme, "console"),
152+
"ERROR": idleConf.GetHighlight(theme, "error"),
153+
None: idleConf.GetHighlight(theme, "normal"),
153154
})
154155

155156

Lib/idlelib/config-highlight.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ break-fontStyle= normal
2121
hit-background= #000000
2222
hit-foreground= #ffffff
2323
hit-fontStyle= normal
24-
cursor-background= black
24+
cursor-foreround= black
2525
error-background= #ff7777
2626
#shell window
2727
stdout-foreground= blue
@@ -48,7 +48,7 @@ hilite-background= #006868
4848
break-foreground= #ff7777
4949
hit-background= #000000
5050
hit-foreground= #ffffff
51-
cursor-background= black
51+
cursor-foreground= black
5252
error-background= #ff7777
5353
#shell window
5454
stdout-foreground= blue

Lib/idlelib/configDialog.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,11 @@ def CreatePageHighlight(self):
320320
('#to choose items','comment'),('\n','normal'),('def','keyword'),
321321
(' ','normal'),('func','definition'),('(param):','normal'),
322322
('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'),
323-
("'string'",'string'),('\n var1 = ','normal'),("'selected'",'selected'),('\n var2 = ','normal'),
324-
("'found'",'found'),('\n\n','normal'),(' error ','error'),
325-
('cursor |','cursor'),('\n ','normal'),('shell','shfg'),(' ','normal'),('stdout','shstdout'),(' ','normal'),
326-
('stderr','shstderr'))
323+
("'string'",'string'),('\n var1 = ','normal'),("'selected'",'selected'),
324+
('\n var2 = ','normal'),("'found'",'found'),('\n\n','normal'),
325+
(' error ','error'),(' ','normal'),('cursor |','cursor'),
326+
('\n ','normal'),('shell','shfg'),(' ','normal'),('stdout','shstdout'),
327+
(' ','normal'),('stderr','shstderr'),('\n','normal'))
327328
for txTa in textAndTags:
328329
text.insert(END,txTa[0],txTa[1])
329330
for element in self.themeElements.keys():
@@ -535,8 +536,36 @@ def CreatePageGeneral(self):
535536
return frame
536537

537538
def PaintThemeSample(self):
538-
pass
539-
539+
if self.themeBuiltin.get: #a default theme
540+
theme=self.builtinTheme.get()
541+
else: #a user theme
542+
theme=self.customTheme.get()
543+
colours=idleConf.GetHighlight(theme, 'normal')
544+
#normalBg=colours['background']
545+
apply(self.textHighlightSample.tag_config,('normal',),colours)
546+
colours=idleConf.GetHighlight(theme, 'keyword')
547+
apply(self.textHighlightSample.tag_config,('keyword',),colours)
548+
colours=idleConf.GetHighlight(theme, 'comment')
549+
apply(self.textHighlightSample.tag_config,('comment',),colours)
550+
colours=idleConf.GetHighlight(theme, 'definition')
551+
apply(self.textHighlightSample.tag_config,('definition',),colours)
552+
colours=idleConf.GetHighlight(theme, 'string')
553+
apply(self.textHighlightSample.tag_config,('string',),colours)
554+
colours=idleConf.GetHighlight(theme, 'hilite')
555+
apply(self.textHighlightSample.tag_config,('selected',),colours)
556+
colours=idleConf.GetHighlight(theme, 'hit')
557+
apply(self.textHighlightSample.tag_config,('found',),colours)
558+
colours=idleConf.GetHighlight(theme, 'cursor')
559+
apply(self.textHighlightSample.tag_config,('cursor',),colours)
560+
colours=idleConf.GetHighlight(theme, 'error')
561+
apply(self.textHighlightSample.tag_config,('error',),colours)
562+
colours=idleConf.GetHighlight(theme, 'console')
563+
apply(self.textHighlightSample.tag_config,('shfg',),colours)
564+
colours=idleConf.GetHighlight(theme, 'stdout')
565+
apply(self.textHighlightSample.tag_config,('shstdout',),colours)
566+
colours=idleConf.GetHighlight(theme, 'stderr')
567+
apply(self.textHighlightSample.tag_config,('shstderr',),colours)
568+
540569
def LoadFontCfg(self):
541570
##base editor font selection list
542571
fonts=list(tkFont.families(self))

Lib/idlelib/configHandler.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
##
66
##---------------------------------------------------------------------------##
77
"""
8-
Provides access to configuration information
8+
Provides access to stored idle configuration information
99
"""
1010

1111
import os
@@ -153,8 +153,17 @@ def GetSectionList(self, configSet, configType):
153153
return cfgParser.sections()
154154

155155
def GetHighlight(self, theme, element):
156+
#get some fallback defaults
157+
defaultFg=self.GetOption('highlight', theme, 'normal' + "-foreground",
158+
default='#000000')
159+
defaultBg=self.GetOption('highlight', theme, 'normal' + "-background",
160+
default='#ffffff')
161+
#try for requested element colours
156162
fore = self.GetOption('highlight', theme, element + "-foreground")
157163
back = self.GetOption('highlight', theme, element + "-background")
164+
#fall back if required
165+
if not fore: fore=defaultFg
166+
if not back: back=defaultBg
158167
return {"foreground": fore,
159168
"background": back}
160169

0 commit comments

Comments
 (0)