mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight() (GH-12491)
This param was only used once and changed the return type.
This commit is contained in:
parent
5086589305
commit
c1419578a1
7 changed files with 41 additions and 58 deletions
|
@ -3,6 +3,11 @@ Released on 2019-10-20?
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
|
|
||||||
|
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
|
||||||
|
This param was only used twice and changed the return type.
|
||||||
|
|
||||||
|
bpo-23216: IDLE: Add docstrings to search modules.
|
||||||
|
|
||||||
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
|
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
|
||||||
Prevent conflicts with Linux dark themes
|
Prevent conflicts with Linux dark themes
|
||||||
(and slightly darken calltip background).
|
(and slightly darken calltip background).
|
||||||
|
|
|
@ -40,7 +40,7 @@ def color_config(text):
|
||||||
# Not automatic because ColorDelegator does not know 'text'.
|
# Not automatic because ColorDelegator does not know 'text'.
|
||||||
theme = idleConf.CurrentTheme()
|
theme = idleConf.CurrentTheme()
|
||||||
normal_colors = idleConf.GetHighlight(theme, 'normal')
|
normal_colors = idleConf.GetHighlight(theme, 'normal')
|
||||||
cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
|
cursor_color = idleConf.GetHighlight(theme, 'cursor')['foreground']
|
||||||
select_colors = idleConf.GetHighlight(theme, 'hilite')
|
select_colors = idleConf.GetHighlight(theme, 'hilite')
|
||||||
text.config(
|
text.config(
|
||||||
foreground=normal_colors['foreground'],
|
foreground=normal_colors['foreground'],
|
||||||
|
|
|
@ -34,7 +34,6 @@ import idlelib
|
||||||
|
|
||||||
class InvalidConfigType(Exception): pass
|
class InvalidConfigType(Exception): pass
|
||||||
class InvalidConfigSet(Exception): pass
|
class InvalidConfigSet(Exception): pass
|
||||||
class InvalidFgBg(Exception): pass
|
|
||||||
class InvalidTheme(Exception): pass
|
class InvalidTheme(Exception): pass
|
||||||
|
|
||||||
class IdleConfParser(ConfigParser):
|
class IdleConfParser(ConfigParser):
|
||||||
|
@ -283,34 +282,20 @@ class IdleConf:
|
||||||
raise InvalidConfigSet('Invalid configSet specified')
|
raise InvalidConfigSet('Invalid configSet specified')
|
||||||
return cfgParser.sections()
|
return cfgParser.sections()
|
||||||
|
|
||||||
def GetHighlight(self, theme, element, fgBg=None):
|
def GetHighlight(self, theme, element):
|
||||||
"""Return individual theme element highlight color(s).
|
"""Return dict of theme element highlight colors.
|
||||||
|
|
||||||
fgBg - string ('fg' or 'bg') or None.
|
The keys are 'foreground' and 'background'. The values are
|
||||||
If None, return a dictionary containing fg and bg colors with
|
tkinter color strings for configuring backgrounds and tags.
|
||||||
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):
|
cfg = ('default' if self.defaultCfg['highlight'].has_section(theme)
|
||||||
themeDict = self.GetThemeDict('default', theme)
|
else 'user')
|
||||||
else:
|
theme_dict = self.GetThemeDict(cfg, theme)
|
||||||
themeDict = self.GetThemeDict('user', theme)
|
fore = theme_dict[element + '-foreground']
|
||||||
fore = themeDict[element + '-foreground']
|
if element == 'cursor':
|
||||||
if element == 'cursor': # There is no config value for cursor bg
|
element = 'normal'
|
||||||
back = themeDict['normal-background']
|
back = theme_dict[element + '-background']
|
||||||
else:
|
return {"foreground": fore, "background": back}
|
||||||
back = themeDict[element + '-background']
|
|
||||||
highlight = {"foreground": fore, "background": back}
|
|
||||||
if not fgBg: # Return dict of both colors
|
|
||||||
return highlight
|
|
||||||
else: # Return specified color only
|
|
||||||
if fgBg == 'fg':
|
|
||||||
return highlight["foreground"]
|
|
||||||
if fgBg == 'bg':
|
|
||||||
return highlight["background"]
|
|
||||||
else:
|
|
||||||
raise InvalidFgBg('Invalid fgBg specified')
|
|
||||||
|
|
||||||
def GetThemeDict(self, type, themeName):
|
def GetThemeDict(self, type, themeName):
|
||||||
"""Return {option:value} dict for elements in themeName.
|
"""Return {option:value} dict for elements in themeName.
|
||||||
|
|
|
@ -1252,7 +1252,7 @@ class HighPage(Frame):
|
||||||
colors = idleConf.GetHighlight(theme, element)
|
colors = idleConf.GetHighlight(theme, element)
|
||||||
if element == 'cursor': # Cursor sample needs special painting.
|
if element == 'cursor': # Cursor sample needs special painting.
|
||||||
colors['background'] = idleConf.GetHighlight(
|
colors['background'] = idleConf.GetHighlight(
|
||||||
theme, 'normal', fgBg='bg')
|
theme, 'normal')['background']
|
||||||
# Handle any unsaved changes to this theme.
|
# Handle any unsaved changes to this theme.
|
||||||
if theme in changes['highlight']:
|
if theme in changes['highlight']:
|
||||||
theme_dict = changes['highlight'][theme]
|
theme_dict = changes['highlight'][theme]
|
||||||
|
|
|
@ -373,10 +373,6 @@ class IdleConfTest(unittest.TestCase):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
eq(conf.GetHighlight('IDLE Classic', 'normal'), {'foreground': '#000000',
|
eq(conf.GetHighlight('IDLE Classic', 'normal'), {'foreground': '#000000',
|
||||||
'background': '#ffffff'})
|
'background': '#ffffff'})
|
||||||
eq(conf.GetHighlight('IDLE Classic', 'normal', 'fg'), '#000000')
|
|
||||||
eq(conf.GetHighlight('IDLE Classic', 'normal', 'bg'), '#ffffff')
|
|
||||||
with self.assertRaises(config.InvalidFgBg):
|
|
||||||
conf.GetHighlight('IDLE Classic', 'normal', 'fb')
|
|
||||||
|
|
||||||
# Test cursor (this background should be normal-background)
|
# Test cursor (this background should be normal-background)
|
||||||
eq(conf.GetHighlight('IDLE Classic', 'cursor'), {'foreground': 'black',
|
eq(conf.GetHighlight('IDLE Classic', 'cursor'), {'foreground': 'black',
|
||||||
|
|
|
@ -606,40 +606,35 @@ class HighPageTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_paint_theme_sample(self):
|
def test_paint_theme_sample(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
d = self.page
|
page = self.page
|
||||||
del d.paint_theme_sample
|
del page.paint_theme_sample # Delete masking mock.
|
||||||
hs_tag = d.highlight_sample.tag_cget
|
hs_tag = page.highlight_sample.tag_cget
|
||||||
gh = idleConf.GetHighlight
|
gh = idleConf.GetHighlight
|
||||||
fg = 'foreground'
|
|
||||||
bg = 'background'
|
|
||||||
|
|
||||||
# Create custom theme based on IDLE Dark.
|
# Create custom theme based on IDLE Dark.
|
||||||
d.theme_source.set(True)
|
page.theme_source.set(True)
|
||||||
d.builtin_name.set('IDLE Dark')
|
page.builtin_name.set('IDLE Dark')
|
||||||
theme = 'IDLE Test'
|
theme = 'IDLE Test'
|
||||||
d.create_new(theme)
|
page.create_new(theme)
|
||||||
d.set_color_sample.called = 0
|
page.set_color_sample.called = 0
|
||||||
|
|
||||||
# Base theme with nothing in `changes`.
|
# Base theme with nothing in `changes`.
|
||||||
d.paint_theme_sample()
|
page.paint_theme_sample()
|
||||||
eq(hs_tag('break', fg), gh(theme, 'break', fgBg='fg'))
|
new_console = {'foreground': 'blue',
|
||||||
eq(hs_tag('cursor', bg), gh(theme, 'normal', fgBg='bg'))
|
'background': 'yellow',}
|
||||||
self.assertNotEqual(hs_tag('console', fg), 'blue')
|
for key, value in new_console.items():
|
||||||
self.assertNotEqual(hs_tag('console', bg), 'yellow')
|
self.assertNotEqual(hs_tag('console', key), value)
|
||||||
eq(d.set_color_sample.called, 1)
|
eq(page.set_color_sample.called, 1)
|
||||||
|
|
||||||
# Apply changes.
|
# Apply changes.
|
||||||
changes.add_option('highlight', theme, 'console-foreground', 'blue')
|
for key, value in new_console.items():
|
||||||
changes.add_option('highlight', theme, 'console-background', 'yellow')
|
changes.add_option('highlight', theme, 'console-'+key, value)
|
||||||
d.paint_theme_sample()
|
page.paint_theme_sample()
|
||||||
|
for key, value in new_console.items():
|
||||||
|
eq(hs_tag('console', key), value)
|
||||||
|
eq(page.set_color_sample.called, 2)
|
||||||
|
|
||||||
eq(hs_tag('break', fg), gh(theme, 'break', fgBg='fg'))
|
page.paint_theme_sample = Func()
|
||||||
eq(hs_tag('cursor', bg), gh(theme, 'normal', fgBg='bg'))
|
|
||||||
eq(hs_tag('console', fg), 'blue')
|
|
||||||
eq(hs_tag('console', bg), 'yellow')
|
|
||||||
eq(d.set_color_sample.called, 2)
|
|
||||||
|
|
||||||
d.paint_theme_sample = Func()
|
|
||||||
|
|
||||||
def test_delete_custom(self):
|
def test_delete_custom(self):
|
||||||
eq = self.assertEqual
|
eq = self.assertEqual
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Remove fgBg param of idlelib.config.GetHighlight(). This param was only used
|
||||||
|
twice and changed the return type.
|
Loading…
Add table
Add a link
Reference in a new issue