[3.12] gh-111050: IDLE - Simplify configdialog.HighPage.theme_elements (GH-111053) (#111055)

gh-111050: IDLE - Simplify configdialog.HighPage.theme_elements (GH-111053)

Replace tuple value with internal name, removing numbers.
Remove sorting of already ordered dislay names.
Remove '[0]' indexing into now-gone tuple.
(cherry picked from commit 642eb8df95)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2023-10-19 06:32:06 +02:00 committed by GitHub
parent d312135764
commit e37d56e8dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 24 deletions

View file

@ -576,24 +576,23 @@ class HighPage(Frame):
(*)theme_message: Label (*)theme_message: Label
""" """
self.theme_elements = { self.theme_elements = {
# Display_name: ('internal_name, sort_number'). # Display-name: internal-config-tag-name.
# TODO: remove sort_number unneeded with dict ordering. 'Normal Code or Text': 'normal',
'Normal Code or Text': ('normal', '00'), 'Code Context': 'context',
'Code Context': ('context', '01'), 'Python Keywords': 'keyword',
'Python Keywords': ('keyword', '02'), 'Python Definitions': 'definition',
'Python Definitions': ('definition', '03'), 'Python Builtins': 'builtin',
'Python Builtins': ('builtin', '04'), 'Python Comments': 'comment',
'Python Comments': ('comment', '05'), 'Python Strings': 'string',
'Python Strings': ('string', '06'), 'Selected Text': 'hilite',
'Selected Text': ('hilite', '07'), 'Found Text': 'hit',
'Found Text': ('hit', '08'), 'Cursor': 'cursor',
'Cursor': ('cursor', '09'), 'Editor Breakpoint': 'break',
'Editor Breakpoint': ('break', '10'), 'Shell Prompt': 'console',
'Shell Prompt': ('console', '11'), 'Error Text': 'error',
'Error Text': ('error', '12'), 'Shell User Output': 'stdout',
'Shell User Output': ('stdout', '13'), 'Shell User Exception': 'stderr',
'Shell User Exception': ('stderr', '14'), 'Line Number': 'linenumber',
'Line Number': ('linenumber', '16'),
} }
self.builtin_name = tracers.add( self.builtin_name = tracers.add(
StringVar(self), self.var_changed_builtin_name) StringVar(self), self.var_changed_builtin_name)
@ -653,7 +652,7 @@ class HighPage(Frame):
# event.widget.winfo_top_level().highlight_target.set(elem) # event.widget.winfo_top_level().highlight_target.set(elem)
self.highlight_target.set(elem) self.highlight_target.set(elem)
text.tag_bind( text.tag_bind(
self.theme_elements[element][0], '<ButtonPress-1>', tem) self.theme_elements[element], '<ButtonPress-1>', tem)
text['state'] = 'disabled' text['state'] = 'disabled'
self.style.configure('frame_color_set.TFrame', borderwidth=1, self.style.configure('frame_color_set.TFrame', borderwidth=1,
relief='solid') relief='solid')
@ -761,7 +760,6 @@ class HighPage(Frame):
self.set_theme_type() self.set_theme_type()
# Load theme element option menu. # Load theme element option menu.
theme_names = list(self.theme_elements) theme_names = list(self.theme_elements)
theme_names.sort(key=lambda x: self.theme_elements[x][1])
self.targetlist.SetMenu(theme_names, theme_names[0]) self.targetlist.SetMenu(theme_names, theme_names[0])
self.paint_theme_sample() self.paint_theme_sample()
self.set_highlight_target() self.set_highlight_target()
@ -888,7 +886,7 @@ class HighPage(Frame):
new_color = self.color.get() new_color = self.color.get()
self.style.configure('frame_color_set.TFrame', background=new_color) self.style.configure('frame_color_set.TFrame', background=new_color)
plane = 'foreground' if self.fg_bg_toggle.get() else 'background' plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
sample_element = self.theme_elements[self.highlight_target.get()][0] sample_element = self.theme_elements[self.highlight_target.get()]
self.highlight_sample.tag_config(sample_element, **{plane: new_color}) self.highlight_sample.tag_config(sample_element, **{plane: new_color})
theme = self.custom_name.get() theme = self.custom_name.get()
theme_element = sample_element + '-' + plane theme_element = sample_element + '-' + plane
@ -1002,7 +1000,7 @@ class HighPage(Frame):
frame_color_set frame_color_set
""" """
# Set the color sample area. # Set the color sample area.
tag = self.theme_elements[self.highlight_target.get()][0] tag = self.theme_elements[self.highlight_target.get()]
plane = 'foreground' if self.fg_bg_toggle.get() else 'background' plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
color = self.highlight_sample.tag_cget(tag, plane) color = self.highlight_sample.tag_cget(tag, plane)
self.style.configure('frame_color_set.TFrame', background=color) self.style.configure('frame_color_set.TFrame', background=color)
@ -1032,7 +1030,7 @@ class HighPage(Frame):
else: # User theme else: # User theme
theme = self.custom_name.get() theme = self.custom_name.get()
for element_title in self.theme_elements: for element_title in self.theme_elements:
element = self.theme_elements[element_title][0] element = self.theme_elements[element_title]
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(

View file

@ -430,7 +430,7 @@ class HighPageTest(unittest.TestCase):
def tag_to_element(elem): def tag_to_element(elem):
for element, tag in d.theme_elements.items(): for element, tag in d.theme_elements.items():
elem[tag[0]] = element elem[tag] = element
def click_it(start): def click_it(start):
x, y, dx, dy = hs.bbox(start) x, y, dx, dy = hs.bbox(start)