8000 gh-111050: IDLE - Simplify configdialog.HighPage.theme_elements (#111… · python/cpython@642eb8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 642eb8d

Browse files
authored
gh-111050: IDLE - Simplify configdialog.HighPage.theme_elements (#111053)
Replace tuple value with internal name, removing numbers. Remove sorting of already ordered dislay names. Remove '[0]' indexing into now-gone tuple.
1 parent 1991694 commit 642eb8d

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

Lib/idlelib/configdialog.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -576,24 +576,23 @@ def create_page_highlight(self):
576576
(*)theme_message: Label
577577
"""
578578
self.theme_elements = {
579-
# Display_name: ('internal_name, sort_number').
580-
# TODO: remove sort_number unneeded with dict ordering.
581-
'Normal Code or Text': ('normal', '00'),
582-
'Code Context': ('context', '01'),
583-
'Python Keywords': ('keyword', '02'),
584-
'Python Definitions': ('definition', '03'),
585-
'Python Builtins': ('builtin', '04'),
586-
'Python Comments': ('comment', '05'),
587-
'Python Strings': ('string', '06'),
588-
'Selected Text': ('hilite', '07'),
589-
'Found Text': ('hit', '08'),
590-
'Cursor': ('cursor', '09'),
591-
'Editor Breakpoint': ('break', '10'),
592-
'Shell Prompt': ('console', '11'),
593-
'Error Text': ('error', '12'),
594-
'Shell User Output': ('stdout', '13'),
595-
'Shell User Exception': ('stderr', '14'),
596-
'Line Number': ('linenumber', '16'),
579+
# Display-name: internal-config-tag-name.
580+
'Normal Code or Text': 'normal',
581+
'Code Context': 'context',
582+
'Python Keywords': 'keyword',
583+
'Python Definitions': 'definition',
584+
'Python Builtins': 'builtin',
585+
'Python Comments': 'comment',
586+
'Python Strings': 'string',
587+
'Selected Text': 'hilite',
588+
'Found Text': 'hit',
589+
'Cursor': 'cursor',
590+
'Editor Breakpoint': 'break',
591+
'Shell Prompt': 'console',
592+
'Error Text': 'error',
593+
'Shell User Output': 'stdout',
594+
'Shell User Exception': 'stderr',
595+
'Line Number': 'linenumber',
597596
}
598597
self.builtin_name = tracers.add(
599598
StringVar(self), self.var_changed_builtin_name)
@@ -653,7 +652,7 @@ def tem(event, elem=element):
653652
# event.widget.winfo_top_level().highlight_target.set(elem)
654653
self.highlight_target.set(elem)
655654
text.tag_bind(
656-
self.theme_elements[element][0], '<ButtonPress-1>', tem)
655+
self.theme_elements[element], '<ButtonPress-1>', tem)
657656
text['state'] = 'disabled'
658657
self.style.configure('frame_color_set.TFrame', borderwidth=1,
659658
relief='solid')
@@ -761,7 +760,6 @@ def load_theme_cfg(self):
761760
self.set_theme_type()
762761
# Load theme element option menu.
763762
theme_names = list(self.theme_elements)
764-
theme_names.sort(key=lambda x: self.theme_elements[x][1])
765763
self.targetlist.SetMenu(theme_names, theme_names[0])
766764
self.paint_theme_sample()
767765
self.set_highlight_target()
@@ -888,7 +886,7 @@ def on_new_color_set(self):
888886
new_color = self.color.get()
889887
self.style.configure('frame_color_set.TFrame', background=new_color)
890888
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
891-
sample_element = self.theme_elements[self.highlight_target.get()][0]
889+
sample_element = self.theme_elements[self.highlight_target.get()]
892890
self.highlight_sample.tag_config(sample_element, **{plane: new_color})
893891
theme = self.custom_name.get()
894892
theme_element = sample_element + '-' + plane
@@ -1002,7 +1000,7 @@ def set_color_sample(self):
10021000
frame_color_set
10031001
"""
10041002
# Set the color sample area.
1005-
tag = self.theme_elements[self.highlight_target.get()][0]
1003+
tag = self.theme_elements[self.highlight_target.get()]
10061004
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
10071005
color = self.highlight_sample.tag_cget(tag, plane)
10081006
self.style.configure('frame_color_set.TFrame', background=color)
@@ -1032,7 +1030,7 @@ def paint_theme_sample(self):
10321030
else: # User theme
10331031
theme = self.custom_name.get()
10341032
for element_title in self.theme_elements:
1035-
element = self.theme_elements[element_title][0]
1033+
element = self.theme_elements[element_title]
10361034
colors = 8000 idleConf.GetHighlight(theme, element)
10371035
if element == 'cursor': # Cursor sample needs special painting.
10381036
colors['background'] = idleConf.GetHighlight(

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def test_highlight_target_text_mouse(self):
430430

431431
def tag_to_element(elem):
432432
for element, tag in d.theme_elements.items():
433-
elem[tag[0]] = element
433+
elem[tag] = element
434434

435435
def click_it(start):
436436
x, y, dx, dy = hs.bbox(start)

0 commit comments

Comments
 (0)
0