Skip to content

[3.6] bpo-30781: IDLE - use ttk widgets in configdialog (GH-2654) #3214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 54 additions & 55 deletions Lib/idlelib/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
Refer to comments in EditorWindow autoindent code for details.

"""
from tkinter import (Toplevel, Frame, LabelFrame, Listbox, Label, Button,
Entry, Text, Scale, Radiobutton, Checkbutton, Canvas,
from tkinter import (Toplevel, Listbox, Text, Scale, Canvas,
StringVar, BooleanVar, IntVar, TRUE, FALSE,
TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE, NORMAL, DISABLED,
NONE, BOTH, X, Y, W, E, EW, NS, NSEW, NW,
HORIZONTAL, VERTICAL, ANCHOR, ACTIVE, END)
from tkinter.ttk import Notebook, Scrollbar
from tkinter.ttk import (Button, Checkbutton, Entry, Frame, Label, LabelFrame,
Notebook, Radiobutton, Scrollbar, Style)
import tkinter.colorchooser as tkColorChooser
import tkinter.font as tkFont
import tkinter.messagebox as tkMessageBox
Expand Down Expand Up @@ -137,9 +137,9 @@ def create_action_buttons(self):
# text in the buttons.
padding_args = {}
else:
padding_args = {'padx':6, 'pady':3}
outer = Frame(self, pady=2)
buttons = Frame(outer, pady=2)
padding_args = {'padding': (6, 3)}
outer = Frame(self, padding=2)
buttons = Frame(outer, padding=2)
for txt, cmd in (
('Ok', self.ok),
('Apply', self.apply),
Expand Down Expand Up @@ -266,7 +266,7 @@ def create_page_extensions(self):
self.extension_list.grid(column=0, row=0, sticky='nws')
scroll.grid(column=1, row=0, sticky='ns')
self.details_frame.grid(column=2, row=0, sticky='nsew', padx=[10, 0])
frame.configure(padx=10, pady=10)
frame.configure(padding=10)
self.config_frame = {}
self.current_extension = None

Expand Down Expand Up @@ -356,9 +356,8 @@ def create_extension_frame(self, ext_name):
label.grid(row=row, column=0, sticky=NW)
var = opt['var']
if opt['type'] == 'bool':
Checkbutton(entry_area, textvariable=var, variable=var,
onvalue='True', offvalue='False',
indicatoron=FALSE, selectcolor='', width=8
Checkbutton(entry_area, variable=var,
onvalue='True', offvalue='False', width=8
).grid(row=row, column=1, sticky=W, padx=7)
elif opt['type'] == 'int':
Entry(entry_area, textvariable=var, validate='key',
Expand Down Expand Up @@ -635,6 +634,7 @@ class HighPage(Frame):
def __init__(self, master):
super().__init__(master)
self.cd = master.master
self.style = Style(master)
self.create_page_highlight()
self.load_theme_cfg()

Expand Down Expand Up @@ -821,12 +821,14 @@ def tem(event, elem=element):
self.highlight_target.set(elem)
text.tag_bind(
self.theme_elements[element][0], '<ButtonPress-1>', tem)
text['state'] = DISABLED
self.frame_color_set = Frame(frame_custom, relief=SOLID, borderwidth=1)
text['state'] = 'disabled'
self.style.configure('frame_color_set.TFrame', borderwidth=1,
relief='solid')
self.frame_color_set = Frame(frame_custom, style='frame_color_set.TFrame')
frame_fg_bg_toggle = Frame(frame_custom)
self.button_set_color = Button(
self.frame_color_set, text='Choose Color for :',
command=self.get_color, highlightthickness=0)
command=self.get_color)
self.targetlist = DynOptionMenu(
self.frame_color_set, self.highlight_target, None,
highlightthickness=0) #, command=self.set_highlight_targetBinding
Expand Down Expand Up @@ -855,7 +857,7 @@ def tem(event, elem=element):
self.button_delete_custom = Button(
frame_theme, text='Delete Custom Theme',
command=self.delete_custom)
self.theme_message = Label(frame_theme, bd=2)
self.theme_message = Label(frame_theme, borderwidth=2)

# Pack widgets:
# body.
Expand Down Expand Up @@ -913,7 +915,7 @@ def load_theme_cfg(self):
item_list = idleConf.GetSectionList('user', 'highlight')
item_list.sort()
if not item_list:
self.custom_theme_on['state'] = DISABLED
self.custom_theme_on.state(('disabled',))
self.custom_name.set('- no custom themes -')
else:
self.customlist.SetMenu(item_list, item_list[0])
Expand Down Expand Up @@ -945,12 +947,10 @@ def var_changed_builtin_name(self, *params):
changes.add_option('main', 'Theme', 'name', old_themes[0])
changes.add_option('main', 'Theme', 'name2', value)
self.theme_message['text'] = 'New theme, see Help'
self.theme_message['fg'] = '#500000'
else:
changes.add_option('main', 'Theme', 'name', value)
changes.add_option('main', 'Theme', 'name2', '')
self.theme_message['text'] = ''
self.theme_message['fg'] = 'black'
self.paint_theme_sample()

def var_changed_custom_name(self, *params):
Expand Down Expand Up @@ -1004,14 +1004,14 @@ def set_theme_type(self):
load_theme_cfg
"""
if self.theme_source.get():
self.builtinlist['state'] = NORMAL
self.customlist['state'] = DISABLED
self.button_delete_custom['state'] = DISABLED
self.builtinlist['state'] = 'normal'
self.customlist['state'] = 'disabled'
self.button_delete_custom.state(('disabled',))
else:
self.builtinlist['state'] = DISABLED
self.custom_theme_on['state'] = NORMAL
self.customlist['state'] = NORMAL
self.button_delete_custom['state'] = NORMAL
self.builtinlist['state'] = 'disabled'
self.custom_theme_on.state(('!disabled',))
self.customlist['state'] = 'normal'
self.button_delete_custom.state(('!disabled',))

def get_color(self):
"""Handle button to select a new color for the target tag.
Expand All @@ -1032,7 +1032,8 @@ def get_color(self):
create_new
"""
target = self.highlight_target.get()
prev_color = self.frame_color_set.cget('bg')
prev_color = self.style.lookup(self.frame_color_set['style'],
'background')
rgbTuplet, color_string = tkColorChooser.askcolor(
parent=self, title='Pick new color for : '+target,
initialcolor=prev_color)
Expand All @@ -1053,7 +1054,7 @@ def get_color(self):
def on_new_color_set(self):
"Display sample of new color selection on the dialog."
new_color = self.color.get()
self.frame_color_set['bg'] = new_color # Set sample.
self.style.configure('frame_color_set.TFrame', background=new_color)
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
sample_element = self.theme_elements[self.highlight_target.get()][0]
self.highlight_sample.tag_config(sample_element, **{plane: new_color})
Expand Down Expand Up @@ -1139,12 +1140,12 @@ def set_highlight_target(self):
load_theme_cfg
"""
if self.highlight_target.get() == 'Cursor': # bg not possible
self.fg_on['state'] = DISABLED
self.bg_on['state'] = DISABLED
self.fg_on.state(('disabled',))
self.bg_on.state(('disabled',))
self.fg_bg_toggle.set(1)
else: # Both fg and bg can be set.
self.fg_on['state'] = NORMAL
self.bg_on['state'] = NORMAL
self.fg_on.state(('!disabled',))
self.bg_on.state(('!disabled',))
self.fg_bg_toggle.set(1)
self.set_color_sample()

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

def paint_theme_sample(self):
"""Apply the theme colors to each element tag in the sample text.
Expand Down Expand Up @@ -1260,7 +1261,7 @@ def delete_custom(self):
item_list = idleConf.GetSectionList('user', 'highlight')
item_list.sort()
if not item_list:
self.custom_theme_on['state'] = DISABLED
self.custom_theme_on.state(('disabled',))
self.customlist.SetMenu(item_list, '- no custom themes -')
else:
self.customlist.SetMenu(item_list, item_list[0])
Expand Down Expand Up @@ -1397,7 +1398,7 @@ def create_page_keys(self):
frame_custom, text='Get New Keys for Selection',
command=self.get_new_keys, state=DISABLED)
# frame_key_sets.
frames = [Frame(frame_key_sets, padx=2, pady=2, borderwidth=0)
frames = [Frame(frame_key_sets, padding=2, borderwidth=0)
for i in range(2)]
self.builtin_keyset_on = Radiobutton(
frames[0], variable=self.keyset_source, value=1,
Expand All @@ -1415,7 +1416,7 @@ def create_page_keys(self):
self.button_save_custom_keys = Button(
frames[1], text='Save as New Custom Key Set',
command=self.save_as_new_key_set)
self.keys_message = Label(frames[0], bd=2)
self.keys_message = Label(frames[0], borderwidth=2)

# Pack widgets:
# body.
Expand Down Expand Up @@ -1457,7 +1458,7 @@ def load_key_cfg(self):
item_list = idleConf.GetSectionList('user', 'keys')
item_list.sort()
if not item_list:
self.custom_keyset_on['state'] = DISABLED
self.custom_keyset_on.state(('disabled',))
self.custom_name.set('- no custom keys -')
else:
self.customlist.SetMenu(item_list, item_list[0])
Expand Down Expand Up @@ -1487,12 +1488,10 @@ def var_changed_builtin_name(self, *params):
changes.add_option('main', 'Keys', 'name', old_keys[0])
changes.add_option('main', 'Keys', 'name2', value)
self.keys_message['text'] = 'New key set, see Help'
self.keys_message['fg'] = '#500000'
else:
changes.add_option('main', 'Keys', 'name', value)
changes.add_option('main', 'Keys', 'name2', '')
self.keys_message['text'] = ''
self.keys_message['fg'] = 'black'
self.load_keys_list(value)

def var_changed_custom_name(self, *params):
Expand Down Expand Up @@ -1526,14 +1525,14 @@ def var_changed_keybinding(self, *params):
def set_keys_type(self):
"Set available screen options based on builtin or custom key set."
if self.keyset_source.get():
self.builtinlist['state'] = NORMAL
self.customlist['state'] = DISABLED
self.button_delete_custom_keys['state'] = DISABLED
self.builtinlist['state'] = 'normal'
self.customlist['state'] = 'disabled'
self.button_delete_custom_keys.state(('disabled',))
else:
self.builtinlist['state'] = DISABLED
self.custom_keyset_on['state'] = NORMAL
self.customlist['state'] = NORMAL
self.button_delete_custom_keys['state'] = NORMAL
self.builtinlist['state'] = 'disabled'
self.custom_keyset_on.state(('!disabled',))
self.customlist['state'] = 'normal'
self.button_delete_custom_keys.state(('!disabled',))

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

def on_bindingslist_select(self, event):
"Activate button to assign new keys to selected action."
self.button_new_keys['state'] = NORMAL
self.button_new_keys.state(('!disabled',))

def create_new_key_set(self, new_key_set_name):
"""Create a new custom key set with the given name.
Expand Down Expand Up @@ -1689,7 +1688,7 @@ def delete_custom_keys(self):
item_list = idleConf.GetSectionList('user', 'keys')
item_list.sort()
if not item_list:
self.custom_keyset_on['state'] = DISABLED
self.custom_keyset_on.state(('disabled',))
self.customlist.SetMenu(item_list, '- no custom keys -')
else:
self.customlist.SetMenu(item_list, item_list[0])
Expand Down Expand Up @@ -1809,13 +1808,13 @@ def create_page_general(self):
self.helplist['yscrollcommand'] = scroll_helplist.set
self.helplist.bind('<ButtonRelease-1>', self.help_source_selected)
self.button_helplist_edit = Button(
frame_helplist_buttons, text='Edit', state=DISABLED,
frame_helplist_buttons, text='Edit', state='disabled',
width=8, command=self.helplist_item_edit)
self.button_helplist_add = Button(
frame_helplist_buttons, text='Add',
width=8, command=self.helplist_item_add)
self.button_helplist_remove = Button(
frame_helplist_buttons, text='Remove', state=DISABLED,
frame_helplist_buttons, text='Remove', state='disabled',
width=8, command=self.helplist_item_remove)

# Pack widgets:
Expand Down Expand Up @@ -1874,15 +1873,15 @@ def help_source_selected(self, event):
def set_add_delete_state(self):
"Toggle the state for the help list buttons based on list entries."
if self.helplist.size() < 1: # No entries in list.
self.button_helplist_edit['state'] = DISABLED
self.button_helplist_remove['state'] = DISABLED
self.button_helplist_edit.state(('disabled',))
self.button_helplist_remove.state(('disabled',))
else: # Some entries.
if self.helplist.curselection(): # There currently is a selection.
self.button_helplist_edit['state'] = NORMAL
self.button_helplist_remove['state'] = NORMAL
self.button_helplist_edit.state(('!disabled',))
self.button_helplist_remove.state(('!disabled',))
else: # There currently is not a selection.
self.button_helplist_edit['state'] = DISABLED
self.button_helplist_remove['state'] = DISABLED
self.button_helplist_edit.state(('disabled',))
self.button_helplist_remove.state(('disabled',))

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