Skip to content

Commit 7b55602

Browse files
authored
[3.6] bpo-30781: IDLE - use ttk widgets in configdialog (GH-2654) (#3214)
Patch by Cheryl Sabella. (cherry picked from commit 7028e59)
1 parent 9bcbc6c commit 7b55602

File tree

3 files changed

+87
-86
lines changed

3 files changed

+87
-86
lines changed

Lib/idlelib/configdialog.py

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
Refer to comments in EditorWindow autoindent code for details.
1010
1111
"""
12-
from tkinter import (Toplevel, Frame, LabelFrame, Listbox, Label, Button,
13-
Entry, Text, Scale, Radiobutton, Checkbutton, Canvas,
12+
from tkinter import (Toplevel, Listbox, Text, Scale, Canvas,
1413
StringVar, BooleanVar, IntVar, TRUE, FALSE,
1514
TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE, NORMAL, DISABLED,
1615
NONE, BOTH, X, Y, W, E, EW, NS, NSEW, NW,
1716
HORIZONTAL, VERTICAL, ANCHOR, ACTIVE, END)
18-
from tkinter.ttk import Notebook, Scrollbar
17+
from tkinter.ttk import (Button, Checkbutton, Entry, Frame, Label, LabelFrame,
18+
Notebook, Radiobutton, Scrollbar, Style)
1919
import tkinter.colorchooser as tkColorChooser
2020
import tkinter.font as tkFont
2121
import tkinter.messagebox as tkMessageBox
@@ -137,9 +137,9 @@ def create_action_buttons(self):
137137
# text in the buttons.
138138
padding_args = {}
139139
else:
140-
padding_args = {'padx':6, 'pady':3}
141-
outer = Frame(self, pady=2)
142-
buttons = Frame(outer, pady=2)
140+
padding_args = {'padding': (6, 3)}
141+
outer = Frame(self, padding=2)
142+
buttons = Frame(outer, padding=2)
143143
for txt, cmd in (
144144
('Ok', self.ok),
145145
('Apply', self.apply),
@@ -266,7 +266,7 @@ def create_page_extensions(self):
266266
self.extension_list.grid(column=0, row=0, sticky='nws')
267267
scroll.grid(column=1, row=0, sticky='ns')
268268
self.details_frame.grid(column=2, row=0, sticky='nsew', padx=[10, 0])
269-
frame.configure(padx=10, pady=10)
269+
frame.configure(padding=10)
270270
self.config_frame = {}
271271
self.current_extension = None
272272

@@ -356,9 +356,8 @@ def create_extension_frame(self, ext_name):
356356
label.grid(row=row, column=0, sticky=NW)
357357
var = opt['var']
358358
if opt['type'] == 'bool':
359-
Checkbutton(entry_area, textvariable=var, variable=var,
360-
onvalue='True', offvalue='False',
361-
indicatoron=FALSE, selectcolor='', width=8
359+
Checkbutton(entry_area, variable=var,
360+
onvalue='True', offvalue='False', width=8
362361
).grid(row=row, column=1, sticky=W, padx=7)
363362
elif opt['type'] == 'int':
364363
Entry(entry_area, textvariable=var, validate='key',
@@ -635,6 +634,7 @@ class HighPage(Frame):
635634
def __init__(self, master):
636635
super().__init__(master)
637636
self.cd = master.master
637+
self.style = Style(master)
638638
self.create_page_highlight()
639639
self.load_theme_cfg()
640640

@@ -821,12 +821,14 @@ def tem(event, elem=element):
821821
self.highlight_target.set(elem)
822822
text.tag_bind(
823823
self.theme_elements[element][0], '<ButtonPress-1>', tem)
824-
text['state'] = DISABLED
825-
self.frame_color_set = Frame(frame_custom, relief=SOLID, borderwidth=1)
824+
text['state'] = 'disabled'
825+
self.style.configure('frame_color_set.TFrame', borderwidth=1,
826+
relief='solid')
827+
self.frame_color_set = Frame(frame_custom, style='frame_color_set.TFrame')
826828
frame_fg_bg_toggle = Frame(frame_custom)
827829
self.button_set_color = Button(
828830
self.frame_color_set, text='Choose Color for :',
829-
command=self.get_color, highlightthickness=0)
831+
command=self.get_color)
830832
self.targetlist = DynOptionMenu(
831833
self.frame_color_set, self.highlight_target, None,
832834
highlightthickness=0) #, command=self.set_highlight_targetBinding
@@ -855,7 +857,7 @@ def tem(event, elem=element):
855857
self.button_delete_custom = Button(
856858
frame_theme, text='Delete Custom Theme',
857859
command=self.delete_custom)
858-
self.theme_message = Label(frame_theme, bd=2)
860+
self.theme_message = Label(frame_theme, borderwidth=2)
859861

860862
# Pack widgets:
861863
# body.
@@ -913,7 +915,7 @@ def load_theme_cfg(self):
913915
item_list = idleConf.GetSectionList('user', 'highlight')
914916
item_list.sort()
915917
if not item_list:
916-
self.custom_theme_on['state'] = DISABLED
918+
self.custom_theme_on.state(('disabled',))
917919
self.custom_name.set('- no custom themes -')
918920
else:
919921
self.customlist.SetMenu(item_list, item_list[0])
@@ -945,12 +947,10 @@ def var_changed_builtin_name(self, *params):
945947
changes.add_option('main', 'Theme', 'name', old_themes[0])
946948
changes.add_option('main', 'Theme', 'name2', value)
947949
self.theme_message['text'] = 'New theme, see Help'
948-
self.theme_message['fg'] = '#500000'
949950
else:
950951
changes.add_option('main', 'Theme', 'name', value)
951952
changes.add_option('main', 'Theme', 'name2', '')
952953
self.theme_message['text'] = ''
953-
self.theme_message['fg'] = 'black'
954954
self.paint_theme_sample()
955955

956956
def var_changed_custom_name(self, *params):
@@ -1004,14 +1004,14 @@ def set_theme_type(self):
10041004
load_theme_cfg
10051005
"""
10061006
if self.theme_source.get():
1007-
self.builtinlist['state'] = NORMAL
1008-
self.customlist['state'] = DISABLED
1009-
self.button_delete_custom['state'] = DISABLED
1007+
self.builtinlist['state'] = 'normal'
1008+
self.customlist['state'] = 'disabled'
1009+
self.button_delete_custom.state(('disabled',))
10101010
else:
1011-
self.builtinlist['state'] = DISABLED
1012-
self.custom_theme_on['state'] = NORMAL
1013-
self.customlist['state'] = NORMAL
1014-
self.button_delete_custom['state'] = NORMAL
1011+
self.builtinlist['state'] = 'disabled'
1012+
self.custom_theme_on.state(('!disabled',))
1013+
self.customlist['state'] = 'normal'
1014+
self.button_delete_custom.state(('!disabled',))
10151015

10161016
def get_color(self):
10171017
"""Handle button to select a new color for the target tag.
@@ -1032,7 +1032,8 @@ def get_color(self):
10321032
create_new
10331033
"""
10341034
target = self.highlight_target.get()
1035-
prev_color = self.frame_color_set.cget('bg')
1035+
prev_color = self.style.lookup(self.frame_color_set['style'],
1036+
'background')
10361037
rgbTuplet, color_string = tkColorChooser.askcolor(
10371038
parent=self, title='Pick new color for : '+target,
10381039
initialcolor=prev_color)
@@ -1053,7 +1054,7 @@ def get_color(self):
10531054
def on_new_color_set(self):
10541055
"Display sample of new color selection on the dialog."
10551056
new_color = self.color.get()
1056-
self.frame_color_set['bg'] = new_color # Set sample.
1057+
self.style.configure('frame_color_set.TFrame', background=new_color)
10571058
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
10581059
sample_element = self.theme_elements[self.highlight_target.get()][0]
10591060
self.highlight_sample.tag_config(sample_element, **{plane: new_color})
@@ -1139,12 +1140,12 @@ def set_highlight_target(self):
11391140
load_theme_cfg
11401141
"""
11411142
if self.highlight_target.get() == 'Cursor': # bg not possible
1142-
self.fg_on['state'] = DISABLED
1143-
self.bg_on['state'] = DISABLED
1143+
self.fg_on.state(('disabled',))
1144+
self.bg_on.state(('disabled',))
11441145
self.fg_bg_toggle.set(1)
11451146
else: # Both fg and bg can be set.
1146-
self.fg_on['state'] = NORMAL
1147-
self.bg_on['state'] = NORMAL
1147+
self.fg_on.state(('!disabled',))
1148+
self.bg_on.state(('!disabled',))
11481149
self.fg_bg_toggle.set(1)
11491150
self.set_color_sample()
11501151

@@ -1172,7 +1173,7 @@ def set_color_sample(self):
11721173
tag = self.theme_elements[self.highlight_target.get()][0]
11731174
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
11741175
color = self.highlight_sample.tag_cget(tag, plane)
1175-
self.frame_color_set['bg'] = color
1176+
self.style.configure('frame_color_set.TFrame', background=color)
11761177

11771178
def paint_theme_sample(self):
11781179
"""Apply the theme colors to each element tag in the sample text.
@@ -1260,7 +1261,7 @@ def delete_custom(self):
12601261
item_list = idleConf.GetSectionList('user', 'highlight')
12611262
item_list.sort()
12621263
if not item_list:
1263-
self.custom_theme_on['state'] = DISABLED
1264+
self.custom_theme_on.state(('disabled',))
12641265
self.customlist.SetMenu(item_list, '- no custom themes -')
12651266
else:
12661267
self.customlist.SetMenu(item_list, item_list[0])
@@ -1397,7 +1398,7 @@ def create_page_keys(self):
13971398
frame_custom, text='Get New Keys for Selection',
13981399
command=self.get_new_keys, state=DISABLED)
13991400
# frame_key_sets.
1400-
frames = [Frame(frame_key_sets, padx=2, pady=2, borderwidth=0)
1401+
frames = [Frame(frame_key_sets, padding=2, borderwidth=0)
14011402
for i in range(2)]
14021403
self.builtin_keyset_on = Radiobutton(
14031404
frames[0], variable=self.keyset_source, value=1,
@@ -1415,7 +1416,7 @@ def create_page_keys(self):
14151416
self.button_save_custom_keys = Button(
14161417
frames[1], text='Save as New Custom Key Set',
14171418
command=self.save_as_new_key_set)
1418-
self.keys_message = Label(frames[0], bd=2)
1419+
self.keys_message = Label(frames[0], borderwidth=2)
14191420

14201421
# Pack widgets:
14211422
# body.
@@ -1457,7 +1458,7 @@ def load_key_cfg(self):
14571458
item_list = idleConf.GetSectionList('user', 'keys')
14581459
item_list.sort()
14591460
if not item_list:
1460-
self.custom_keyset_on['state'] = DISABLED
1461+
self.custom_keyset_on.state(('disabled',))
14611462
self.custom_name.set('- no custom keys -')
14621463
else:
14631464
self.customlist.SetMenu(item_list, item_list[0])
@@ -1487,12 +1488,10 @@ def var_changed_builtin_name(self, *params):
14871488
changes.add_option('main', 'Keys', 'name', old_keys[0])
14881489
changes.add_option('main', 'Keys', 'name2', value)
14891490
self.keys_message['text'] = 'New key set, see Help'
1490-
self.keys_message['fg'] = '#500000'
14911491
else:
14921492
changes.add_option('main', 'Keys', 'name', value)
14931493
changes.add_option('main', 'Keys', 'name2', '')
14941494
self.keys_message['text'] = ''
1495-
self.keys_message['fg'] = 'black'
14961495
self.load_keys_list(value)
14971496

14981497
def var_changed_custom_name(self, *params):
@@ -1526,14 +1525,14 @@ def var_changed_keybinding(self, *params):
15261525
def set_keys_type(self):
15271526
"Set available screen options based on builtin or custom key set."
15281527
if self.keyset_source.get():
1529-
self.builtinlist['state'] = NORMAL
1530-
self.customlist['state'] = DISABLED
1531-
self.button_delete_custom_keys['state'] = DISABLED
1528+
self.builtinlist['state'] = 'normal'
1529+
self.customlist['state'] = 'disabled'
1530+
self.button_delete_custom_keys.state(('disabled',))
15321531
else:
1533-
self.builtinlist['state'] = DISABLED
1534-
self.custom_keyset_on['state'] = NORMAL
1535-
self.customlist['state'] = NORMAL
1536-
self.button_delete_custom_keys['state'] = NORMAL
1532+
self.builtinlist['state'] = 'disabled'
1533+
self.custom_keyset_on.state(('!disabled',))
1534+
self.customlist['state'] = 'normal'
1535+
self.button_delete_custom_keys.state(('!disabled',))
15371536

15381537
def get_new_keys(self):
15391538
"""Handle event to change key binding for selected line.
@@ -1595,7 +1594,7 @@ def save_as_new_key_set(self):
15951594

15961595
def on_bindingslist_select(self, event):
15971596
"Activate button to assign new keys to selected action."
1598-
self.button_new_keys['state'] = NORMAL
1597+
self.button_new_keys.state(('!disabled',))
15991598

16001599
def create_new_key_set(self, new_key_set_name):
16011600
"""Create a new custom key set with the given name.
@@ -1689,7 +1688,7 @@ def delete_custom_keys(self):
16891688
item_list = idleConf.GetSectionList('user', 'keys')
16901689
item_list.sort()
16911690
if not item_list:
1692-
self.custom_keyset_on['state'] = DISABLED
1691+
self.custom_keyset_on.state(('disabled',))
16931692
self.customlist.SetMenu(item_list, '- no custom keys -')
16941693
else:
16951694
self.customlist.SetMenu(item_list, item_list[0])
@@ -1809,13 +1808,13 @@ def create_page_general(self):
18091808
self.helplist['yscrollcommand'] = scroll_helplist.set
18101809
self.helplist.bind('<ButtonRelease-1>', self.help_source_selected)
18111810
self.button_helplist_edit = Button(
1812-
frame_helplist_buttons, text='Edit', state=DISABLED,
1811+
frame_helplist_buttons, text='Edit', state='disabled',
18131812
width=8, command=self.helplist_item_edit)
18141813
self.button_helplist_add = Button(
18151814
frame_helplist_buttons, text='Add',
18161815
width=8, command=self.helplist_item_add)
18171816
self.button_helplist_remove = Button(
1818-
frame_helplist_buttons, text='Remove', state=DISABLED,
1817+
frame_helplist_buttons, text='Remove', state='disabled',
18191818
width=8, command=self.helplist_item_remove)
18201819

18211820
# Pack widgets:
@@ -1874,15 +1873,15 @@ def help_source_selected(self, event):
18741873
def set_add_delete_state(self):
18751874
"Toggle the state for the help list buttons based on list entries."
18761875
if self.helplist.size() < 1: # No entries in list.
1877-
self.button_helplist_edit['state'] = DISABLED
1878-
self.button_helplist_remove['state'] = DISABLED
1876+
self.button_helplist_edit.state(('disabled',))
1877+
self.button_helplist_remove.state(('disabled',))
18791878
else: # Some entries.
18801879
if self.helplist.curselection(): # There currently is a selection.
1881-
self.button_helplist_edit['state'] = NORMAL
1882-
self.button_helplist_remove['state'] = NORMAL
1880+
self.button_helplist_edit.state(('!disabled',))
1881+
self.button_helplist_remove.state(('!disabled',))
18831882
else: # There currently is not a selection.
1884-
self.button_helplist_edit['state'] = DISABLED
1885-
self.button_helplist_remove['state'] = DISABLED
1883+
self.button_helplist_edit.state(('disabled',))
1884+
self.button_helplist_remove.state(('disabled',))
18861885

18871886
def helplist_item_add(self):
18881887
"""Handle add button for the help list.
@@ -2062,7 +2061,7 @@ def __init__(self, parent, *args, **kw):
20622061
# Create a canvas object and a vertical scrollbar for scrolling it.
20632062
vscrollbar = Scrollbar(self, orient=VERTICAL)
20642063
vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
2065-
canvas = Canvas(self, bd=0, highlightthickness=0,
2064+
canvas = Canvas(self, borderwidth=0, highlightthickness=0,
20662065
yscrollcommand=vscrollbar.set, width=240)
20672066
canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
20682067
vscrollbar.config(command=canvas.yview)

0 commit comments

Comments
 (0)