Skip to content

Commit c141957

Browse files
authored
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight() (GH-12491)
This param was only used once and changed the return type.
1 parent 5086589 commit c141957

File tree

7 files changed

+41
-58
lines changed

7 files changed

+41
-58
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Released on 2019-10-20?
33
======================================
44

55

6+
bpo-36396: Remove fgBg param of idlelib.config.GetHighlight().
7+
This param was only used twice and changed the return type.
8+
9+
bpo-23216: IDLE: Add docstrings to search modules.
10+
611
bpo-36176: Fix IDLE autocomplete & calltip popup colors.
712
Prevent conflicts with Linux dark themes
813
(and slightly darken calltip background).

Lib/idlelib/colorizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def color_config(text):
4040
# Not automatic because ColorDelegator does not know 'text'.
4141
theme = idleConf.CurrentTheme()
4242
normal_colors = idleConf.GetHighlight(theme, 'normal')
43-
cursor_color = idleConf.GetHighlight(theme, 'cursor', fgBg='fg')
43+
cursor_color = idleConf.GetHighlight(theme, 'cursor')['foreground']
4444
select_colors = idleConf.GetHighlight(theme, 'hilite')
4545
text.config(
4646
foreground=normal_colors['foreground'],

Lib/idlelib/config.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
class InvalidConfigType(Exception): pass
3636
class InvalidConfigSet(Exception): pass
37-
class InvalidFgBg(Exception): pass
3837
class InvalidTheme(Exception): pass
3938

4039
class IdleConfParser(ConfigParser):
@@ -283,34 +282,20 @@ def GetSectionList(self, configSet, configType):
283282
raise InvalidConfigSet('Invalid configSet specified')
284283
return cfgParser.sections()
285284

286-
def GetHighlight(self, theme, element, fgBg=None):
287-
"""Return individual theme element highlight color(s).
285+
def GetHighlight(self, theme, element):
286+
"""Return dict of theme element highlight colors.
288287
289-
fgBg - string ('fg' or 'bg') or None.
290-
If None, return a dictionary containing fg and bg colors with
291-
keys 'foreground' and 'background'. Otherwise, only return
292-
fg or bg color, as specified. Colors are intended to be
293-
appropriate for passing to Tkinter in, e.g., a tag_config call).
288+
The keys are 'foreground' and 'background'. The values are
289+
tkinter color strings for configuring backgrounds and tags.
294290
"""
295-
if self.defaultCfg['highlight'].has_section(theme):
296-
themeDict = self.GetThemeDict('default', theme)
297-
else:
298-
themeDict = self.GetThemeDict('user', theme)
299-
fore = themeDict[element + '-foreground']
300-
if element == 'cursor': # There is no config value for cursor bg
301-
back = themeDict['normal-background']
302-
else:
303-
back = themeDict[element + '-background']
304-
highlight = {"foreground": fore, "background": back}
305-
if not fgBg: # Return dict of both colors
306-
return highlight
307-
else: # Return specified color only
308-
if fgBg == 'fg':
309-
return highlight["foreground"]
310-
if fgBg == 'bg':
311-
return highlight["background"]
312-
else:
313-
raise InvalidFgBg('Invalid fgBg specified')
291+
cfg = ('default' if self.defaultCfg['highlight'].has_section(theme)
292+
else 'user')
293+
theme_dict = self.GetThemeDict(cfg, theme)
294+
fore = theme_dict[element + '-foreground']
295+
if element == 'cursor':
296+
element = 'normal'
297+
back = theme_dict[element + '-background']
298+
return {"foreground": fore, "background": back}
314299

315300
def GetThemeDict(self, type, themeName):
316301
"""Return {option:value} dict for elements in themeName.

Lib/idlelib/configdialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ def paint_theme_sample(self):
12521252
colors = idleConf.GetHighlight(theme, element)
12531253
if element == 'cursor': # Cursor sample needs special painting.
12541254
colors['background'] = idleConf.GetHighlight(
1255-
theme, 'normal', fgBg='bg')
1255+
theme, 'normal')['background']
12561256
# Handle any unsaved changes to this theme.
12571257
if theme in changes['highlight']:
12581258
theme_dict = changes['highlight'][theme]

Lib/idlelib/idle_test/test_config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ def test_get_highlight(self):
373373
eq = self.assertEqual
374374
eq(conf.GetHighlight('IDLE Classic', 'normal'), {'foreground': '#000000',
375375
'background': '#ffffff'})
376-
eq(conf.GetHighlight('IDLE Classic', 'normal', 'fg'), '#000000')
377-
eq(conf.GetHighlight('IDLE Classic', 'normal', 'bg'), '#ffffff')
378-
with self.assertRaises(config.InvalidFgBg):
379-
conf.GetHighlight('IDLE Classic', 'normal', 'fb')
380376

381377
# Test cursor (this background should be normal-background)
382378
eq(conf.GetHighlight('IDLE Classic', 'cursor'), {'foreground': 'black',

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -606,40 +606,35 @@ def test_set_color_sample(self):
606606

607607
def test_paint_theme_sample(self):
608608
eq = self.assertEqual
609-
d = self.page
610-
del d.paint_theme_sample
611-
hs_tag = d.highlight_sample.tag_cget
609+
page = self.page
610+
del page.paint_theme_sample # Delete masking mock.
611+
hs_tag = page.highlight_sample.tag_cget
612612
gh = idleConf.GetHighlight
613-
fg = 'foreground'
614-
bg = 'background'
615613

616614
# Create custom theme based on IDLE Dark.
617-
d.theme_source.set(True)
618-
d.builtin_name.set('IDLE Dark')
615+
page.theme_source.set(True)
616+
page.builtin_name.set('IDLE Dark')
619617
theme = 'IDLE Test'
620-
d.create_new(theme)
621-
d.set_color_sample.called = 0
618+
page.create_new(theme)
619+
page.set_color_sample.called = 0
622620

623621
# Base theme with nothing in `changes`.
624-
d.paint_theme_sample()
625-
eq(hs_tag('break', fg), gh(theme, 'break', fgBg='fg'))
626-
eq(hs_tag('cursor', bg), gh(theme, 'normal', fgBg='bg'))
627-
self.assertNotEqual(hs_tag('console', fg), 'blue')
628-
self.assertNotEqual(hs_tag('console', bg), 'yellow')
629-
eq(d.set_color_sample.called, 1)
622+
page.paint_theme_sample()
623+
new_console = {'foreground': 'blue',
624+
'background': 'yellow',}
625+
for key, value in new_console.items():
626+
self.assertNotEqual(hs_tag('console', key), value)
627+
eq(page.set_color_sample.called, 1)
630628

631629
# Apply changes.
632-
changes.add_option('highlight', theme, 'console-foreground', 'blue')
633-
changes.add_option('highlight', theme, 'console-background', 'yellow')
634-
d.paint_theme_sample()
635-
636-
eq(hs_tag('break', fg), gh(theme, 'break', fgBg='fg'))
637-
eq(hs_tag('cursor', bg), gh(theme, 'normal', fgBg='bg'))
638-
eq(hs_tag('console', fg), 'blue')
639-
eq(hs_tag('console', bg), 'yellow')
640-
eq(d.set_color_sample.called, 2)
630+
for key, value in new_console.items():
631+
changes.add_option('highlight', theme, 'console-'+key, value)
632+
page.paint_theme_sample()
633+
for key, value in new_console.items():
634+
eq(hs_tag('console', key), value)
635+
eq(page.set_color_sample.called, 2)
641636

642-
d.paint_theme_sample = Func()
637+
page.paint_theme_sample = Func()
643638

644639
def test_delete_custom(self):
645640
eq = self.assertEqual
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove fgBg param of idlelib.config.GetHighlight(). This param was only used
2+
twice and changed the return type.

0 commit comments

Comments
 (0)