mirror of https://github.com/python/cpython
Merge with 3.4: decolourize
This commit is contained in:
commit
e66dc2aecc
|
@ -766,7 +766,7 @@ class EditorWindow(object):
|
||||||
self.color = None
|
self.color = None
|
||||||
|
|
||||||
def ResetColorizer(self):
|
def ResetColorizer(self):
|
||||||
"Update the colour theme"
|
"Update the color theme"
|
||||||
# Called from self.filename_change_hook and from configDialog.py
|
# Called from self.filename_change_hook and from configDialog.py
|
||||||
self._rmcolorizer()
|
self._rmcolorizer()
|
||||||
self._addcolorizer()
|
self._addcolorizer()
|
||||||
|
|
|
@ -274,25 +274,27 @@ class IdleConf:
|
||||||
return cfgParser.sections()
|
return cfgParser.sections()
|
||||||
|
|
||||||
def GetHighlight(self, theme, element, fgBg=None):
|
def GetHighlight(self, theme, element, fgBg=None):
|
||||||
"""Return individual highlighting theme elements.
|
"""Return individual theme element highlight color(s).
|
||||||
|
|
||||||
fgBg - string ('fg'or'bg') or None, if None return a dictionary
|
fgBg - string ('fg' or 'bg') or None.
|
||||||
containing fg and bg colours (appropriate for passing to Tkinter in,
|
If None, return a dictionary containing fg and bg colors with
|
||||||
e.g., a tag_config call), otherwise fg or bg colour only as specified.
|
keys 'foreground' and 'background'. Otherwise, only return
|
||||||
|
fg or bg color, as specified. Colors are intended to be
|
||||||
|
appropriate for passing to Tkinter in, e.g., a tag_config call).
|
||||||
"""
|
"""
|
||||||
if self.defaultCfg['highlight'].has_section(theme):
|
if self.defaultCfg['highlight'].has_section(theme):
|
||||||
themeDict = self.GetThemeDict('default', theme)
|
themeDict = self.GetThemeDict('default', theme)
|
||||||
else:
|
else:
|
||||||
themeDict = self.GetThemeDict('user', theme)
|
themeDict = self.GetThemeDict('user', theme)
|
||||||
fore = themeDict[element + '-foreground']
|
fore = themeDict[element + '-foreground']
|
||||||
if element == 'cursor': #there is no config value for cursor bg
|
if element == 'cursor': # There is no config value for cursor bg
|
||||||
back = themeDict['normal-background']
|
back = themeDict['normal-background']
|
||||||
else:
|
else:
|
||||||
back = themeDict[element + '-background']
|
back = themeDict[element + '-background']
|
||||||
highlight = {"foreground": fore, "background": back}
|
highlight = {"foreground": fore, "background": back}
|
||||||
if not fgBg: #return dict of both colours
|
if not fgBg: # Return dict of both colors
|
||||||
return highlight
|
return highlight
|
||||||
else: #return specified colour only
|
else: # Return specified color only
|
||||||
if fgBg == 'fg':
|
if fgBg == 'fg':
|
||||||
return highlight["foreground"]
|
return highlight["foreground"]
|
||||||
if fgBg == 'bg':
|
if fgBg == 'bg':
|
||||||
|
@ -314,11 +316,11 @@ class IdleConf:
|
||||||
cfgParser = self.defaultCfg['highlight']
|
cfgParser = self.defaultCfg['highlight']
|
||||||
else:
|
else:
|
||||||
raise InvalidTheme('Invalid theme type specified')
|
raise InvalidTheme('Invalid theme type specified')
|
||||||
#foreground and background values are provded for each theme element
|
# Provide foreground and background colors for each theme
|
||||||
#(apart from cursor) even though all these values are not yet used
|
# element (other than cursor) even though some values are not
|
||||||
#by idle, to allow for their use in the future. Default values are
|
# yet used by idle, to allow for their use in the future.
|
||||||
#generally black and white.
|
# Default values are generally black and white.
|
||||||
# TODO make theme, a constant, a module or class attribute
|
# TODO copy theme from a class attribute.
|
||||||
theme ={'normal-foreground':'#000000',
|
theme ={'normal-foreground':'#000000',
|
||||||
'normal-background':'#ffffff',
|
'normal-background':'#ffffff',
|
||||||
'keyword-foreground':'#000000',
|
'keyword-foreground':'#000000',
|
||||||
|
@ -350,18 +352,18 @@ class IdleConf:
|
||||||
'console-background':'#ffffff' }
|
'console-background':'#ffffff' }
|
||||||
for element in theme:
|
for element in theme:
|
||||||
if not cfgParser.has_option(themeName, element):
|
if not cfgParser.has_option(themeName, element):
|
||||||
#we are going to return a default, print warning
|
# Print warning that will return a default color
|
||||||
warning = ('\n Warning: configHandler.py - IdleConf.GetThemeDict'
|
warning = ('\n Warning: configHandler.IdleConf.GetThemeDict'
|
||||||
' -\n problem retrieving theme element %r'
|
' -\n problem retrieving theme element %r'
|
||||||
'\n from theme %r.\n'
|
'\n from theme %r.\n'
|
||||||
' returning default value: %r' %
|
' returning default color: %r' %
|
||||||
(element, themeName, theme[element]))
|
(element, themeName, theme[element]))
|
||||||
try:
|
try:
|
||||||
print(warning, file=sys.stderr)
|
print(warning, file=sys.stderr)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
colour = cfgParser.Get(themeName, element, default=theme[element])
|
theme[element] = cfgParser.Get(
|
||||||
theme[element] = colour
|
themeName, element, default=theme[element])
|
||||||
return theme
|
return theme
|
||||||
|
|
||||||
def CurrentTheme(self):
|
def CurrentTheme(self):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# tk common colour chooser dialogue
|
# tk common color chooser dialogue
|
||||||
#
|
#
|
||||||
# this module provides an interface to the native color dialogue
|
# this module provides an interface to the native color dialogue
|
||||||
# available in Tk 4.2 and newer.
|
# available in Tk 4.2 and newer.
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# options (all have default values):
|
# options (all have default values):
|
||||||
#
|
#
|
||||||
# - initialcolor: colour to mark as selected when dialog is displayed
|
# - initialcolor: color to mark as selected when dialog is displayed
|
||||||
# (given as an RGB triplet or a Tk color string)
|
# (given as an RGB triplet or a Tk color string)
|
||||||
#
|
#
|
||||||
# - parent: which window to place the dialog on top of
|
# - parent: which window to place the dialog on top of
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
(1) How to use the demo viewer.
|
(1) How to use the demo viewer.
|
||||||
|
|
||||||
Select a demoscript from the example menu.
|
Select a demoscript from the example menu.
|
||||||
The (syntax coloured) source code appears in the left
|
The (syntax colored) source code appears in the left
|
||||||
source code window. IT CANNOT BE EDITED, but ONLY VIEWED!
|
source code window. IT CANNOT BE EDITED, but ONLY VIEWED!
|
||||||
|
|
||||||
The demo viewer windows can be resized. The divider between text
|
The demo viewer windows can be resized. The divider between text
|
||||||
|
|
|
@ -29,8 +29,8 @@ def coosys():
|
||||||
line(-1, 0, N+1, 0)
|
line(-1, 0, N+1, 0)
|
||||||
line(0, -0.1, 0, 1.1)
|
line(0, -0.1, 0, 1.1)
|
||||||
|
|
||||||
def plot(fun, start, colour):
|
def plot(fun, start, color):
|
||||||
pencolor(colour)
|
pencolor(color)
|
||||||
x = start
|
x = start
|
||||||
jumpto(0, x)
|
jumpto(0, x)
|
||||||
pendown()
|
pendown()
|
||||||
|
|
Loading…
Reference in New Issue