From 3c2c302d952c4a44afc81e8bf459036e53ecdec5 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 30 Jul 2017 16:08:12 -0400 Subject: [PATCH 1/2] bpo-31050: IDLE: Factor out GenTab class from ConfigDialog --- Lib/idlelib/configdialog.py | 757 ++++++++++++++------- Lib/idlelib/idle_test/test_configdialog.py | 52 +- 2 files changed, 523 insertions(+), 286 deletions(-) diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index 92bbc106344d944..4bdc59c1cd69482 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -89,14 +89,14 @@ def create_widgets(self): """Create and place widgets for tabbed dialog. Widgets Bound to self: - tab_pages: TabbedPageSet + note: Notebook + highpage: self.create_page_highlight + fontpage: FontPage + keyspage: self.create_page_keys + genpage: GenPage + extpageL self.create_page_extensions Methods: - create_page_font_tab - create_page_highlight - create_page_keys - create_page_general - create_page_extensions create_action_buttons load_configs: Load pages except for extensions. activate_config_changes: Tell editors to reload. @@ -105,13 +105,13 @@ def create_widgets(self): self.highpage = self.create_page_highlight() self.fontpage = FontPage(note, self.highpage) self.keyspage = self.create_page_keys() - self.genpage = self.create_page_general() + self.genpage = GenPage(note) self.extpage = self.create_page_extensions() - note.add(self.fontpage, text='Fonts/Tabs') - note.add(self.highpage, text='Highlights') - note.add(self.keyspage, text=' Keys ') - note.add(self.genpage, text=' General ') - note.add(self.extpage, text='Extensions') + note.add(self.fontpage, text='Fonts/Tabs', underline=0) + note.add(self.highpage, text='Highlights', underline=0) + note.add(self.keyspage, text=' Keys ', underline=1) + note.add(self.genpage, text=' General ', underline=1) + note.add(self.extpage, text='Extensions', underline=0) note.enable_traversal() note.pack(side=TOP, expand=TRUE, fill=BOTH) self.create_action_buttons().pack(side=BOTTOM) @@ -133,7 +133,7 @@ def load_configs(self): #self.load_tab_cfg() self.load_theme_cfg() self.load_key_cfg() - self.load_general_cfg() + # self.load_general_cfg() # note: extension page handled separately def create_action_buttons(self): @@ -1199,253 +1199,253 @@ def activate_config_changes(self): instance.reset_help_menu_entries() - def create_page_general(self): - """Return frame of widgets for General tab. - - Enable users to provisionally change general options. Function - load_general_cfg intializes tk variables and helplist using - idleConf. Radiobuttons startup_shell_on and startup_editor_on - set var startup_edit. Radiobuttons save_ask_on and save_auto_on - set var autosave. Entry boxes win_width_int and win_height_int - set var win_width and win_height. Setting var_name invokes the - default callback that adds option to changes. - - Helplist: load_general_cfg loads list user_helplist with - name, position pairs and copies names to listbox helplist. - Clicking a name invokes help_source selected. Clicking - button_helplist_name invokes helplist_item_name, which also - changes user_helplist. These functions all call - set_add_delete_state. All but load call update_help_changes to - rewrite changes['main']['HelpFiles']. - - Widget Structure: (*) widgets bound to self - frame - frame_run: LabelFrame - startup_title: Label - (*)startup_editor_on: Radiobutton - startup_edit - (*)startup_shell_on: Radiobutton - startup_edit - frame_save: LabelFrame - run_save_title: Label - (*)save_ask_on: Radiobutton - autosave - (*)save_auto_on: Radiobutton - autosave - frame_win_size: LabelFrame - win_size_title: Label - win_width_title: Label - (*)win_width_int: Entry - win_width - win_height_title: Label - (*)win_height_int: Entry - win_height - frame_help: LabelFrame - frame_helplist: Frame - frame_helplist_buttons: Frame - (*)button_helplist_edit - (*)button_helplist_add - (*)button_helplist_remove - (*)helplist: ListBox - scroll_helplist: Scrollbar - """ - parent = self.parent - self.startup_edit = tracers.add( - IntVar(parent), ('main', 'General', 'editor-on-startup')) - self.autosave = tracers.add( - IntVar(parent), ('main', 'General', 'autosave')) - self.win_width = tracers.add( - StringVar(parent), ('main', 'EditorWindow', 'width')) - self.win_height = tracers.add( - StringVar(parent), ('main', 'EditorWindow', 'height')) - - # Create widgets: - # body and section frames. - frame = Frame(self.note) - frame_run = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Startup Preferences ') - frame_save = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' autosave Preferences ') - frame_win_size = Frame(frame, borderwidth=2, relief=GROOVE) - frame_help = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Additional Help Sources ') - # frame_run. - startup_title = Label(frame_run, text='At Startup') - self.startup_editor_on = Radiobutton( - frame_run, variable=self.startup_edit, value=1, - text="Open Edit Window") - self.startup_shell_on = Radiobutton( - frame_run, variable=self.startup_edit, value=0, - text='Open Shell Window') - # frame_save. - run_save_title = Label(frame_save, text='At Start of Run (F5) ') - self.save_ask_on = Radiobutton( - frame_save, variable=self.autosave, value=0, - text="Prompt to Save") - self.save_auto_on = Radiobutton( - frame_save, variable=self.autosave, value=1, - text='No Prompt') - # frame_win_size. - win_size_title = Label( - frame_win_size, text='Initial Window Size (in characters)') - win_width_title = Label(frame_win_size, text='Width') - self.win_width_int = Entry( - frame_win_size, textvariable=self.win_width, width=3) - win_height_title = Label(frame_win_size, text='Height') - self.win_height_int = Entry( - frame_win_size, textvariable=self.win_height, width=3) - # frame_help. - frame_helplist = Frame(frame_help) - frame_helplist_buttons = Frame(frame_helplist) - self.helplist = Listbox( - frame_helplist, height=5, takefocus=True, - exportselection=FALSE) - scroll_helplist = Scrollbar(frame_helplist) - scroll_helplist['command'] = self.helplist.yview - self.helplist['yscrollcommand'] = scroll_helplist.set - self.helplist.bind('', self.help_source_selected) - self.button_helplist_edit = Button( - 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, - width=8, command=self.helplist_item_remove) - - # Pack widgets: - # body. - frame_run.pack(side=TOP, padx=5, pady=5, fill=X) - frame_save.pack(side=TOP, padx=5, pady=5, fill=X) - frame_win_size.pack(side=TOP, padx=5, pady=5, fill=X) - frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) - # frame_run. - startup_title.pack(side=LEFT, anchor=W, padx=5, pady=5) - self.startup_shell_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) - self.startup_editor_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) - # frame_save. - run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5) - self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) - self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) - # frame_win_size. - win_size_title.pack(side=LEFT, anchor=W, padx=5, pady=5) - self.win_height_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) - win_height_title.pack(side=RIGHT, anchor=E, pady=5) - self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) - win_width_title.pack(side=RIGHT, anchor=E, pady=5) - # frame_help. - frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y) - frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) - scroll_helplist.pack(side=RIGHT, anchor=W, fill=Y) - self.helplist.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) - self.button_helplist_edit.pack(side=TOP, anchor=W, pady=5) - self.button_helplist_add.pack(side=TOP, anchor=W) - self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5) - - return frame - - def load_general_cfg(self): - "Load current configuration settings for the general options." - # Set startup state. - self.startup_edit.set(idleConf.GetOption( - 'main', 'General', 'editor-on-startup', default=0, type='bool')) - # Set autosave state. - self.autosave.set(idleConf.GetOption( - 'main', 'General', 'autosave', default=0, type='bool')) - # Set initial window size. - self.win_width.set(idleConf.GetOption( - 'main', 'EditorWindow', 'width', type='int')) - self.win_height.set(idleConf.GetOption( - 'main', 'EditorWindow', 'height', type='int')) - # Set additional help sources. - self.user_helplist = idleConf.GetAllExtraHelpSourcesList() - self.helplist.delete(0, 'end') - for help_item in self.user_helplist: - self.helplist.insert(END, help_item[0]) - self.set_add_delete_state() - - def var_changed_startup_edit(self, *params): - "Store change to toggle for starting IDLE in the editor or shell." - value = self.startup_edit.get() - changes.add_option('main', 'General', 'editor-on-startup', value) - - def var_changed_autosave(self, *params): - "Store change to autosave." - value = self.autosave.get() - changes.add_option('main', 'General', 'autosave', value) - - def var_changed_win_width(self, *params): - "Store change to window width." - value = self.win_width.get() - changes.add_option('main', 'EditorWindow', 'width', value) - - def var_changed_win_height(self, *params): - "Store change to window height." - value = self.win_height.get() - changes.add_option('main', 'EditorWindow', 'height', value) - - def help_source_selected(self, event): - "Handle event for selecting additional help." - self.set_add_delete_state() - - 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 - else: # Some entries. - if self.helplist.curselection(): # There currently is a selection. - self.button_helplist_edit['state'] = NORMAL - self.button_helplist_remove['state'] = NORMAL - else: # There currently is not a selection. - self.button_helplist_edit['state'] = DISABLED - self.button_helplist_remove['state'] = DISABLED - - def helplist_item_add(self): - """Handle add button for the help list. - - Query for name and location of new help sources and add - them to the list. - """ - help_source = HelpSource(self, 'New Help Source').result - if help_source: - self.user_helplist.append(help_source) - self.helplist.insert(END, help_source[0]) - self.update_help_changes() - - def helplist_item_edit(self): - """Handle edit button for the help list. - - Query with existing help source information and update - config if the values are changed. - """ - item_index = self.helplist.index(ANCHOR) - help_source = self.user_helplist[item_index] - new_help_source = HelpSource( - self, 'Edit Help Source', - menuitem=help_source[0], - filepath=help_source[1], - ).result - if new_help_source and new_help_source != help_source: - self.user_helplist[item_index] = new_help_source - self.helplist.delete(item_index) - self.helplist.insert(item_index, new_help_source[0]) - self.update_help_changes() - self.set_add_delete_state() # Selected will be un-selected - - def helplist_item_remove(self): - """Handle remove button for the help list. - - Delete the help list item from config. - """ - item_index = self.helplist.index(ANCHOR) - del(self.user_helplist[item_index]) - self.helplist.delete(item_index) - self.update_help_changes() - self.set_add_delete_state() - - def update_help_changes(self): - "Clear and rebuild the HelpFiles section in changes" - changes['main']['HelpFiles'] = {} - for num in range(1, len(self.user_helplist) + 1): - changes.add_option( - 'main', 'HelpFiles', str(num), - ';'.join(self.user_helplist[num-1][:2])) +# def create_page_general(self): +# """Return frame of widgets for General tab. +# +# Enable users to provisionally change general options. Function +# load_general_cfg intializes tk variables and helplist using +# idleConf. Radiobuttons startup_shell_on and startup_editor_on +# set var startup_edit. Radiobuttons save_ask_on and save_auto_on +# set var autosave. Entry boxes win_width_int and win_height_int +# set var win_width and win_height. Setting var_name invokes the +# default callback that adds option to changes. +# +# Helplist: load_general_cfg loads list user_helplist with +# name, position pairs and copies names to listbox helplist. +# Clicking a name invokes help_source selected. Clicking +# button_helplist_name invokes helplist_item_name, which also +# changes user_helplist. These functions all call +# set_add_delete_state. All but load call update_help_changes to +# rewrite changes['main']['HelpFiles']. +# +# Widget Structure: (*) widgets bound to self +# frame +# frame_run: LabelFrame +# startup_title: Label +# (*)startup_editor_on: Radiobutton - startup_edit +# (*)startup_shell_on: Radiobutton - startup_edit +# frame_save: LabelFrame +# run_save_title: Label +# (*)save_ask_on: Radiobutton - autosave +# (*)save_auto_on: Radiobutton - autosave +# frame_win_size: LabelFrame +# win_size_title: Label +# win_width_title: Label +# (*)win_width_int: Entry - win_width +# win_height_title: Label +# (*)win_height_int: Entry - win_height +# frame_help: LabelFrame +# frame_helplist: Frame +# frame_helplist_buttons: Frame +# (*)button_helplist_edit +# (*)button_helplist_add +# (*)button_helplist_remove +# (*)helplist: ListBox +# scroll_helplist: Scrollbar +# """ +# parent = self.parent +# self.startup_edit = tracers.add( +# IntVar(parent), ('main', 'General', 'editor-on-startup')) +# self.autosave = tracers.add( +# IntVar(parent), ('main', 'General', 'autosave')) +# self.win_width = tracers.add( +# StringVar(parent), ('main', 'EditorWindow', 'width')) +# self.win_height = tracers.add( +# StringVar(parent), ('main', 'EditorWindow', 'height')) +# +# # Create widgets: +# # body and section frames. +# frame = Frame(self.note) +# frame_run = LabelFrame(frame, borderwidth=2, relief=GROOVE, +# text=' Startup Preferences ') +# frame_save = LabelFrame(frame, borderwidth=2, relief=GROOVE, +# text=' autosave Preferences ') +# frame_win_size = Frame(frame, borderwidth=2, relief=GROOVE) +# frame_help = LabelFrame(frame, borderwidth=2, relief=GROOVE, +# text=' Additional Help Sources ') +# # frame_run. +# startup_title = Label(frame_run, text='At Startup') +# self.startup_editor_on = Radiobutton( +# frame_run, variable=self.startup_edit, value=1, +# text="Open Edit Window") +# self.startup_shell_on = Radiobutton( +# frame_run, variable=self.startup_edit, value=0, +# text='Open Shell Window') +# # frame_save. +# run_save_title = Label(frame_save, text='At Start of Run (F5) ') +# self.save_ask_on = Radiobutton( +# frame_save, variable=self.autosave, value=0, +# text="Prompt to Save") +# self.save_auto_on = Radiobutton( +# frame_save, variable=self.autosave, value=1, +# text='No Prompt') +# # frame_win_size. +# win_size_title = Label( +# frame_win_size, text='Initial Window Size (in characters)') +# win_width_title = Label(frame_win_size, text='Width') +# self.win_width_int = Entry( +# frame_win_size, textvariable=self.win_width, width=3) +# win_height_title = Label(frame_win_size, text='Height') +# self.win_height_int = Entry( +# frame_win_size, textvariable=self.win_height, width=3) +# # frame_help. +# frame_helplist = Frame(frame_help) +# frame_helplist_buttons = Frame(frame_helplist) +# self.helplist = Listbox( +# frame_helplist, height=5, takefocus=True, +# exportselection=FALSE) +# scroll_helplist = Scrollbar(frame_helplist) +# scroll_helplist['command'] = self.helplist.yview +# self.helplist['yscrollcommand'] = scroll_helplist.set +# self.helplist.bind('', self.help_source_selected) +# self.button_helplist_edit = Button( +# 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, +# width=8, command=self.helplist_item_remove) +# +# # Pack widgets: +# # body. +# frame_run.pack(side=TOP, padx=5, pady=5, fill=X) +# frame_save.pack(side=TOP, padx=5, pady=5, fill=X) +# frame_win_size.pack(side=TOP, padx=5, pady=5, fill=X) +# frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) +# # frame_run. +# startup_title.pack(side=LEFT, anchor=W, padx=5, pady=5) +# self.startup_shell_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) +# self.startup_editor_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) +# # frame_save. +# run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5) +# self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) +# self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) +# # frame_win_size. +# win_size_title.pack(side=LEFT, anchor=W, padx=5, pady=5) +# self.win_height_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) +# win_height_title.pack(side=RIGHT, anchor=E, pady=5) +# self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) +# win_width_title.pack(side=RIGHT, anchor=E, pady=5) +# # frame_help. +# frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y) +# frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) +# scroll_helplist.pack(side=RIGHT, anchor=W, fill=Y) +# self.helplist.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) +# self.button_helplist_edit.pack(side=TOP, anchor=W, pady=5) +# self.button_helplist_add.pack(side=TOP, anchor=W) +# self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5) +# +# return frame +# +# def load_general_cfg(self): +# "Load current configuration settings for the general options." +# # Set startup state. +# self.startup_edit.set(idleConf.GetOption( +# 'main', 'General', 'editor-on-startup', default=0, type='bool')) +# # Set autosave state. +# self.autosave.set(idleConf.GetOption( +# 'main', 'General', 'autosave', default=0, type='bool')) +# # Set initial window size. +# self.win_width.set(idleConf.GetOption( +# 'main', 'EditorWindow', 'width', type='int')) +# self.win_height.set(idleConf.GetOption( +# 'main', 'EditorWindow', 'height', type='int')) +# # Set additional help sources. +# self.user_helplist = idleConf.GetAllExtraHelpSourcesList() +# self.helplist.delete(0, 'end') +# for help_item in self.user_helplist: +# self.helplist.insert(END, help_item[0]) +# self.set_add_delete_state() +# +# def var_changed_startup_edit(self, *params): +# "Store change to toggle for starting IDLE in the editor or shell." +# value = self.startup_edit.get() +# changes.add_option('main', 'General', 'editor-on-startup', value) +# +# def var_changed_autosave(self, *params): +# "Store change to autosave." +# value = self.autosave.get() +# changes.add_option('main', 'General', 'autosave', value) +# +# def var_changed_win_width(self, *params): +# "Store change to window width." +# value = self.win_width.get() +# changes.add_option('main', 'EditorWindow', 'width', value) +# +# def var_changed_win_height(self, *params): +# "Store change to window height." +# value = self.win_height.get() +# changes.add_option('main', 'EditorWindow', 'height', value) +# +# def help_source_selected(self, event): +# "Handle event for selecting additional help." +# self.set_add_delete_state() +# +# 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 +# else: # Some entries. +# if self.helplist.curselection(): # There currently is a selection. +# self.button_helplist_edit['state'] = NORMAL +# self.button_helplist_remove['state'] = NORMAL +# else: # There currently is not a selection. +# self.button_helplist_edit['state'] = DISABLED +# self.button_helplist_remove['state'] = DISABLED +# +# def helplist_item_add(self): +# """Handle add button for the help list. +# +# Query for name and location of new help sources and add +# them to the list. +# """ +# help_source = HelpSource(self, 'New Help Source').result +# if help_source: +# self.user_helplist.append(help_source) +# self.helplist.insert(END, help_source[0]) +# self.update_help_changes() +# +# def helplist_item_edit(self): +# """Handle edit button for the help list. +# +# Query with existing help source information and update +# config if the values are changed. +# """ +# item_index = self.helplist.index(ANCHOR) +# help_source = self.user_helplist[item_index] +# new_help_source = HelpSource( +# self, 'Edit Help Source', +# menuitem=help_source[0], +# filepath=help_source[1], +# ).result +# if new_help_source and new_help_source != help_source: +# self.user_helplist[item_index] = new_help_source +# self.helplist.delete(item_index) +# self.helplist.insert(item_index, new_help_source[0]) +# self.update_help_changes() +# self.set_add_delete_state() # Selected will be un-selected +# +# def helplist_item_remove(self): +# """Handle remove button for the help list. +# +# Delete the help list item from config. +# """ +# item_index = self.helplist.index(ANCHOR) +# del(self.user_helplist[item_index]) +# self.helplist.delete(item_index) +# self.update_help_changes() +# self.set_add_delete_state() +# +# def update_help_changes(self): +# "Clear and rebuild the HelpFiles section in changes" +# changes['main']['HelpFiles'] = {} +# for num in range(1, len(self.user_helplist) + 1): +# changes.add_option( +# 'main', 'HelpFiles', str(num), +# ';'.join(self.user_helplist[num-1][:2])) def create_page_extensions(self): @@ -1845,6 +1845,243 @@ def var_changed_space_num(self, *params): changes.add_option('main', 'Indent', 'num-spaces', value) +class GenPage(Frame): + + def __init__(self, parent): + super().__init__(parent) + self.parent = parent + self.create_page_general() + self.load_general_cfg() + + def create_page_general(self): + """Return frame of widgets for General tab. + + Enable users to provisionally change general options. Function + load_general_cfg intializes tk variables and helplist using + idleConf. Radiobuttons startup_shell_on and startup_editor_on + set var startup_edit. Radiobuttons save_ask_on and save_auto_on + set var autosave. Entry boxes win_width_int and win_height_int + set var win_width and win_height. Setting var_name invokes the + default callback that adds option to changes. + + Helplist: load_general_cfg loads list user_helplist with + name, position pairs and copies names to listbox helplist. + Clicking a name invokes help_source selected. Clicking + button_helplist_name invokes helplist_item_name, which also + changes user_helplist. These functions all call + set_add_delete_state. All but load call update_help_changes to + rewrite changes['main']['HelpFiles']. + + Widget Structure: (*) widgets bound to self + frame + frame_run: LabelFrame + startup_title: Label + (*)startup_editor_on: Radiobutton - startup_edit + (*)startup_shell_on: Radiobutton - startup_edit + frame_save: LabelFrame + run_save_title: Label + (*)save_ask_on: Radiobutton - autosave + (*)save_auto_on: Radiobutton - autosave + frame_win_size: LabelFrame + win_size_title: Label + win_width_title: Label + (*)win_width_int: Entry - win_width + win_height_title: Label + (*)win_height_int: Entry - win_height + frame_help: LabelFrame + frame_helplist: Frame + frame_helplist_buttons: Frame + (*)button_helplist_edit + (*)button_helplist_add + (*)button_helplist_remove + (*)helplist: ListBox + scroll_helplist: Scrollbar + """ + parent = self.parent + self.startup_edit = tracers.add( + IntVar(parent), ('main', 'General', 'editor-on-startup')) + self.autosave = tracers.add( + IntVar(parent), ('main', 'General', 'autosave')) + self.win_width = tracers.add( + StringVar(parent), ('main', 'EditorWindow', 'width')) + self.win_height = tracers.add( + StringVar(parent), ('main', 'EditorWindow', 'height')) + + # Create widgets: + # body and section frames. + frame = self + frame_run = LabelFrame(frame, borderwidth=2, relief=GROOVE, + text=' Startup Preferences ') + frame_save = LabelFrame(frame, borderwidth=2, relief=GROOVE, + text=' autosave Preferences ') + frame_win_size = Frame(frame, borderwidth=2, relief=GROOVE) + frame_help = LabelFrame(frame, borderwidth=2, relief=GROOVE, + text=' Additional Help Sources ') + # frame_run. + startup_title = Label(frame_run, text='At Startup') + self.startup_editor_on = Radiobutton( + frame_run, variable=self.startup_edit, value=1, + text="Open Edit Window") + self.startup_shell_on = Radiobutton( + frame_run, variable=self.startup_edit, value=0, + text='Open Shell Window') + # frame_save. + run_save_title = Label(frame_save, text='At Start of Run (F5) ') + self.save_ask_on = Radiobutton( + frame_save, variable=self.autosave, value=0, + text="Prompt to Save") + self.save_auto_on = Radiobutton( + frame_save, variable=self.autosave, value=1, + text='No Prompt') + # frame_win_size. + win_size_title = Label( + frame_win_size, text='Initial Window Size (in characters)') + win_width_title = Label(frame_win_size, text='Width') + self.win_width_int = Entry( + frame_win_size, textvariable=self.win_width, width=3) + win_height_title = Label(frame_win_size, text='Height') + self.win_height_int = Entry( + frame_win_size, textvariable=self.win_height, width=3) + # frame_help. + frame_helplist = Frame(frame_help) + frame_helplist_buttons = Frame(frame_helplist) + self.helplist = Listbox( + frame_helplist, height=5, takefocus=True, + exportselection=FALSE) + scroll_helplist = Scrollbar(frame_helplist) + scroll_helplist['command'] = self.helplist.yview + self.helplist['yscrollcommand'] = scroll_helplist.set + self.helplist.bind('', self.help_source_selected) + self.button_helplist_edit = Button( + 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, + width=8, command=self.helplist_item_remove) + + # Pack widgets: + # body. + frame_run.pack(side=TOP, padx=5, pady=5, fill=X) + frame_save.pack(side=TOP, padx=5, pady=5, fill=X) + frame_win_size.pack(side=TOP, padx=5, pady=5, fill=X) + frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) + # frame_run. + startup_title.pack(side=LEFT, anchor=W, padx=5, pady=5) + self.startup_shell_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.startup_editor_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) + # frame_save. + run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5) + self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) + # frame_win_size. + win_size_title.pack(side=LEFT, anchor=W, padx=5, pady=5) + self.win_height_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) + win_height_title.pack(side=RIGHT, anchor=E, pady=5) + self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) + win_width_title.pack(side=RIGHT, anchor=E, pady=5) + # frame_help. + frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y) + frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) + scroll_helplist.pack(side=RIGHT, anchor=W, fill=Y) + self.helplist.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) + self.button_helplist_edit.pack(side=TOP, anchor=W, pady=5) + self.button_helplist_add.pack(side=TOP, anchor=W) + self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5) + + return frame + + def load_general_cfg(self): + "Load current configuration settings for the general options." + # Set startup state. + self.startup_edit.set(idleConf.GetOption( + 'main', 'General', 'editor-on-startup', default=0, type='bool')) + # Set autosave state. + self.autosave.set(idleConf.GetOption( + 'main', 'General', 'autosave', default=0, type='bool')) + # Set initial window size. + self.win_width.set(idleConf.GetOption( + 'main', 'EditorWindow', 'width', type='int')) + self.win_height.set(idleConf.GetOption( + 'main', 'EditorWindow', 'height', type='int')) + # Set additional help sources. + self.user_helplist = idleConf.GetAllExtraHelpSourcesList() + self.helplist.delete(0, 'end') + for help_item in self.user_helplist: + self.helplist.insert(END, help_item[0]) + self.set_add_delete_state() + + def help_source_selected(self, event): + "Handle event for selecting additional help." + self.set_add_delete_state() + + 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 + else: # Some entries. + if self.helplist.curselection(): # There currently is a selection. + self.button_helplist_edit['state'] = NORMAL + self.button_helplist_remove['state'] = NORMAL + else: # There currently is not a selection. + self.button_helplist_edit['state'] = DISABLED + self.button_helplist_remove['state'] = DISABLED + + def helplist_item_add(self): + """Handle add button for the help list. + + Query for name and location of new help sources and add + them to the list. + """ + help_source = HelpSource(self, 'New Help Source').result + if help_source: + self.user_helplist.append(help_source) + self.helplist.insert(END, help_source[0]) + self.update_help_changes() + + def helplist_item_edit(self): + """Handle edit button for the help list. + + Query with existing help source information and update + config if the values are changed. + """ + item_index = self.helplist.index(ANCHOR) + help_source = self.user_helplist[item_index] + new_help_source = HelpSource( + self, 'Edit Help Source', + menuitem=help_source[0], + filepath=help_source[1], + ).result + if new_help_source and new_help_source != help_source: + self.user_helplist[item_index] = new_help_source + self.helplist.delete(item_index) + self.helplist.insert(item_index, new_help_source[0]) + self.update_help_changes() + self.set_add_delete_state() # Selected will be un-selected + + def helplist_item_remove(self): + """Handle remove button for the help list. + + Delete the help list item from config. + """ + item_index = self.helplist.index(ANCHOR) + del(self.user_helplist[item_index]) + self.helplist.delete(item_index) + self.update_help_changes() + self.set_add_delete_state() + + def update_help_changes(self): + "Clear and rebuild the HelpFiles section in changes" + changes['main']['HelpFiles'] = {} + for num in range(1, len(self.user_helplist) + 1): + changes.add_option( + 'main', 'HelpFiles', str(num), + ';'.join(self.user_helplist[num-1][:2])) + + class VarTrace: """Maintain Tk variables trace state.""" diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index 8da726b80c07737..38654fc7f59bf4b 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -237,7 +237,7 @@ def setUp(self): changes.clear() -class GeneralTest(unittest.TestCase): +class GenPageTest(unittest.TestCase): """Test that general tab widgets enable users to make changes. Test that widget actions set vars, that var changes add @@ -245,20 +245,17 @@ class GeneralTest(unittest.TestCase): """ @classmethod def setUpClass(cls): - d = dialog - # Select General tab so can force focus on helplist. - d.note.select(d.genpage) - # Mask instance methods used by help functions. - d.set = d.set_add_delete_state = Func() - d.upc = d.update_help_changes = Func() + page = cls.page = dialog.genpage + dialog.note.select(page) + page.set = page.set_add_delete_state = Func() + page.upc = page.update_help_changes = Func() @classmethod def tearDownClass(cls): - d = dialog - del d.set, d.set_add_delete_state - del d.upc, d.update_help_changes - d.helplist.delete(0, 'end') - d.user_helplist.clear() + del cls.page.set, cls.page.set_add_delete_state + del cls.page.upc, cls.page.update_help_changes + cls.page.helplist.delete(0, 'end') + cls.page.user_helplist.clear() def setUp(self): changes.clear() @@ -266,7 +263,7 @@ def setUp(self): def test_load_general_cfg(self): # Set to wrong values, load, check right values. eq = self.assertEqual - d = dialog + d = self.page d.startup_edit.set(1) d.autosave.set(1) d.win_width.set(1) @@ -283,29 +280,32 @@ def test_load_general_cfg(self): eq(d.user_helplist, [('name', 'file', '1')]) def test_startup(self): - dialog.startup_editor_on.invoke() + d = self.page + d.startup_editor_on.invoke() self.assertEqual(mainpage, {'General': {'editor-on-startup': '1'}}) changes.clear() - dialog.startup_shell_on.invoke() + d.startup_shell_on.invoke() self.assertEqual(mainpage, {'General': {'editor-on-startup': '0'}}) def test_autosave(self): - dialog.save_auto_on.invoke() + d = self.page + d.save_auto_on.invoke() self.assertEqual(mainpage, {'General': {'autosave': '1'}}) - dialog.save_ask_on.invoke() + d.save_ask_on.invoke() self.assertEqual(mainpage, {'General': {'autosave': '0'}}) def test_editor_size(self): - dialog.win_height_int.insert(0, '1') + d = self.page + d.win_height_int.insert(0, '1') self.assertEqual(mainpage, {'EditorWindow': {'height': '140'}}) changes.clear() - dialog.win_width_int.insert(0, '1') + d.win_width_int.insert(0, '1') self.assertEqual(mainpage, {'EditorWindow': {'width': '180'}}) def test_source_selected(self): - d = dialog + d = self.page d.set = d.set_add_delete_state d.upc = d.update_help_changes helplist = d.helplist @@ -331,7 +331,7 @@ def test_source_selected(self): def test_set_add_delete_state(self): # Call with 0 items, 1 unselected item, 1 selected item. eq = self.assertEqual - d = dialog + d = self.page del d.set_add_delete_state # Unmask method. sad = d.set_add_delete_state h = d.helplist @@ -358,7 +358,7 @@ def test_helplist_item_add(self): eq = self.assertEqual orig_helpsource = configdialog.HelpSource hs = configdialog.HelpSource = Func(return_self=True) - d = dialog + d = self.page d.helplist.delete(0, 'end') d.user_helplist.clear() d.set.called = d.upc.called = 0 @@ -385,7 +385,7 @@ def test_helplist_item_edit(self): eq = self.assertEqual orig_helpsource = configdialog.HelpSource hs = configdialog.HelpSource = Func(return_self=True) - d = dialog + d = self.page d.helplist.delete(0, 'end') d.helplist.insert(0, 'name1') d.helplist.selection_set(0) @@ -412,7 +412,7 @@ def test_helplist_item_edit(self): def test_helplist_item_remove(self): eq = self.assertEqual - d = dialog + d = self.page d.helplist.delete(0, 'end') d.helplist.insert(0, 'name1') d.helplist.selection_set(0) @@ -427,7 +427,7 @@ def test_helplist_item_remove(self): self.assertTrue(d.upc.called == d.set.called == 1) def test_update_help_changes(self): - d = dialog + d = self.page del d.update_help_changes d.user_helplist.clear() d.user_helplist.append(('name1', 'file1')) @@ -435,7 +435,7 @@ def test_update_help_changes(self): d.update_help_changes() self.assertEqual(mainpage['HelpFiles'], - {'1': 'name1;file1', '2': 'name2;file2'}) + {'1': 'name1;file1', '2': 'name2;file2'}) d.update_help_changes = Func() From 04d99b73a9adfda90d6c1ee89e31551905bd8fba Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 30 Jul 2017 17:52:12 -0400 Subject: [PATCH 2/2] Changes per Terry's requests --- Lib/idlelib/configdialog.py | 283 +----------------- Lib/idlelib/idle_test/test_configdialog.py | 9 +- .../2017-07-30-17-39-59.bpo-31050.AXR3kP.rst | 2 + 3 files changed, 21 insertions(+), 273 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2017-07-30-17-39-59.bpo-31050.AXR3kP.rst diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index 4bdc59c1cd69482..28070a51709dd28 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -107,11 +107,11 @@ def create_widgets(self): self.keyspage = self.create_page_keys() self.genpage = GenPage(note) self.extpage = self.create_page_extensions() - note.add(self.fontpage, text='Fonts/Tabs', underline=0) - note.add(self.highpage, text='Highlights', underline=0) - note.add(self.keyspage, text=' Keys ', underline=1) - note.add(self.genpage, text=' General ', underline=1) - note.add(self.extpage, text='Extensions', underline=0) + note.add(self.fontpage, text='Fonts/Tabs') + note.add(self.highpage, text='Highlights') + note.add(self.keyspage, text=' Keys ') + note.add(self.genpage, text=' General ') + note.add(self.extpage, text='Extensions') note.enable_traversal() note.pack(side=TOP, expand=TRUE, fill=BOTH) self.create_action_buttons().pack(side=BOTTOM) @@ -1198,256 +1198,6 @@ def activate_config_changes(self): instance.ApplyKeybindings() instance.reset_help_menu_entries() - -# def create_page_general(self): -# """Return frame of widgets for General tab. -# -# Enable users to provisionally change general options. Function -# load_general_cfg intializes tk variables and helplist using -# idleConf. Radiobuttons startup_shell_on and startup_editor_on -# set var startup_edit. Radiobuttons save_ask_on and save_auto_on -# set var autosave. Entry boxes win_width_int and win_height_int -# set var win_width and win_height. Setting var_name invokes the -# default callback that adds option to changes. -# -# Helplist: load_general_cfg loads list user_helplist with -# name, position pairs and copies names to listbox helplist. -# Clicking a name invokes help_source selected. Clicking -# button_helplist_name invokes helplist_item_name, which also -# changes user_helplist. These functions all call -# set_add_delete_state. All but load call update_help_changes to -# rewrite changes['main']['HelpFiles']. -# -# Widget Structure: (*) widgets bound to self -# frame -# frame_run: LabelFrame -# startup_title: Label -# (*)startup_editor_on: Radiobutton - startup_edit -# (*)startup_shell_on: Radiobutton - startup_edit -# frame_save: LabelFrame -# run_save_title: Label -# (*)save_ask_on: Radiobutton - autosave -# (*)save_auto_on: Radiobutton - autosave -# frame_win_size: LabelFrame -# win_size_title: Label -# win_width_title: Label -# (*)win_width_int: Entry - win_width -# win_height_title: Label -# (*)win_height_int: Entry - win_height -# frame_help: LabelFrame -# frame_helplist: Frame -# frame_helplist_buttons: Frame -# (*)button_helplist_edit -# (*)button_helplist_add -# (*)button_helplist_remove -# (*)helplist: ListBox -# scroll_helplist: Scrollbar -# """ -# parent = self.parent -# self.startup_edit = tracers.add( -# IntVar(parent), ('main', 'General', 'editor-on-startup')) -# self.autosave = tracers.add( -# IntVar(parent), ('main', 'General', 'autosave')) -# self.win_width = tracers.add( -# StringVar(parent), ('main', 'EditorWindow', 'width')) -# self.win_height = tracers.add( -# StringVar(parent), ('main', 'EditorWindow', 'height')) -# -# # Create widgets: -# # body and section frames. -# frame = Frame(self.note) -# frame_run = LabelFrame(frame, borderwidth=2, relief=GROOVE, -# text=' Startup Preferences ') -# frame_save = LabelFrame(frame, borderwidth=2, relief=GROOVE, -# text=' autosave Preferences ') -# frame_win_size = Frame(frame, borderwidth=2, relief=GROOVE) -# frame_help = LabelFrame(frame, borderwidth=2, relief=GROOVE, -# text=' Additional Help Sources ') -# # frame_run. -# startup_title = Label(frame_run, text='At Startup') -# self.startup_editor_on = Radiobutton( -# frame_run, variable=self.startup_edit, value=1, -# text="Open Edit Window") -# self.startup_shell_on = Radiobutton( -# frame_run, variable=self.startup_edit, value=0, -# text='Open Shell Window') -# # frame_save. -# run_save_title = Label(frame_save, text='At Start of Run (F5) ') -# self.save_ask_on = Radiobutton( -# frame_save, variable=self.autosave, value=0, -# text="Prompt to Save") -# self.save_auto_on = Radiobutton( -# frame_save, variable=self.autosave, value=1, -# text='No Prompt') -# # frame_win_size. -# win_size_title = Label( -# frame_win_size, text='Initial Window Size (in characters)') -# win_width_title = Label(frame_win_size, text='Width') -# self.win_width_int = Entry( -# frame_win_size, textvariable=self.win_width, width=3) -# win_height_title = Label(frame_win_size, text='Height') -# self.win_height_int = Entry( -# frame_win_size, textvariable=self.win_height, width=3) -# # frame_help. -# frame_helplist = Frame(frame_help) -# frame_helplist_buttons = Frame(frame_helplist) -# self.helplist = Listbox( -# frame_helplist, height=5, takefocus=True, -# exportselection=FALSE) -# scroll_helplist = Scrollbar(frame_helplist) -# scroll_helplist['command'] = self.helplist.yview -# self.helplist['yscrollcommand'] = scroll_helplist.set -# self.helplist.bind('', self.help_source_selected) -# self.button_helplist_edit = Button( -# 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, -# width=8, command=self.helplist_item_remove) -# -# # Pack widgets: -# # body. -# frame_run.pack(side=TOP, padx=5, pady=5, fill=X) -# frame_save.pack(side=TOP, padx=5, pady=5, fill=X) -# frame_win_size.pack(side=TOP, padx=5, pady=5, fill=X) -# frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) -# # frame_run. -# startup_title.pack(side=LEFT, anchor=W, padx=5, pady=5) -# self.startup_shell_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) -# self.startup_editor_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) -# # frame_save. -# run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5) -# self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) -# self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5) -# # frame_win_size. -# win_size_title.pack(side=LEFT, anchor=W, padx=5, pady=5) -# self.win_height_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) -# win_height_title.pack(side=RIGHT, anchor=E, pady=5) -# self.win_width_int.pack(side=RIGHT, anchor=E, padx=10, pady=5) -# win_width_title.pack(side=RIGHT, anchor=E, pady=5) -# # frame_help. -# frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y) -# frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) -# scroll_helplist.pack(side=RIGHT, anchor=W, fill=Y) -# self.helplist.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) -# self.button_helplist_edit.pack(side=TOP, anchor=W, pady=5) -# self.button_helplist_add.pack(side=TOP, anchor=W) -# self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5) -# -# return frame -# -# def load_general_cfg(self): -# "Load current configuration settings for the general options." -# # Set startup state. -# self.startup_edit.set(idleConf.GetOption( -# 'main', 'General', 'editor-on-startup', default=0, type='bool')) -# # Set autosave state. -# self.autosave.set(idleConf.GetOption( -# 'main', 'General', 'autosave', default=0, type='bool')) -# # Set initial window size. -# self.win_width.set(idleConf.GetOption( -# 'main', 'EditorWindow', 'width', type='int')) -# self.win_height.set(idleConf.GetOption( -# 'main', 'EditorWindow', 'height', type='int')) -# # Set additional help sources. -# self.user_helplist = idleConf.GetAllExtraHelpSourcesList() -# self.helplist.delete(0, 'end') -# for help_item in self.user_helplist: -# self.helplist.insert(END, help_item[0]) -# self.set_add_delete_state() -# -# def var_changed_startup_edit(self, *params): -# "Store change to toggle for starting IDLE in the editor or shell." -# value = self.startup_edit.get() -# changes.add_option('main', 'General', 'editor-on-startup', value) -# -# def var_changed_autosave(self, *params): -# "Store change to autosave." -# value = self.autosave.get() -# changes.add_option('main', 'General', 'autosave', value) -# -# def var_changed_win_width(self, *params): -# "Store change to window width." -# value = self.win_width.get() -# changes.add_option('main', 'EditorWindow', 'width', value) -# -# def var_changed_win_height(self, *params): -# "Store change to window height." -# value = self.win_height.get() -# changes.add_option('main', 'EditorWindow', 'height', value) -# -# def help_source_selected(self, event): -# "Handle event for selecting additional help." -# self.set_add_delete_state() -# -# 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 -# else: # Some entries. -# if self.helplist.curselection(): # There currently is a selection. -# self.button_helplist_edit['state'] = NORMAL -# self.button_helplist_remove['state'] = NORMAL -# else: # There currently is not a selection. -# self.button_helplist_edit['state'] = DISABLED -# self.button_helplist_remove['state'] = DISABLED -# -# def helplist_item_add(self): -# """Handle add button for the help list. -# -# Query for name and location of new help sources and add -# them to the list. -# """ -# help_source = HelpSource(self, 'New Help Source').result -# if help_source: -# self.user_helplist.append(help_source) -# self.helplist.insert(END, help_source[0]) -# self.update_help_changes() -# -# def helplist_item_edit(self): -# """Handle edit button for the help list. -# -# Query with existing help source information and update -# config if the values are changed. -# """ -# item_index = self.helplist.index(ANCHOR) -# help_source = self.user_helplist[item_index] -# new_help_source = HelpSource( -# self, 'Edit Help Source', -# menuitem=help_source[0], -# filepath=help_source[1], -# ).result -# if new_help_source and new_help_source != help_source: -# self.user_helplist[item_index] = new_help_source -# self.helplist.delete(item_index) -# self.helplist.insert(item_index, new_help_source[0]) -# self.update_help_changes() -# self.set_add_delete_state() # Selected will be un-selected -# -# def helplist_item_remove(self): -# """Handle remove button for the help list. -# -# Delete the help list item from config. -# """ -# item_index = self.helplist.index(ANCHOR) -# del(self.user_helplist[item_index]) -# self.helplist.delete(item_index) -# self.update_help_changes() -# self.set_add_delete_state() -# -# def update_help_changes(self): -# "Clear and rebuild the HelpFiles section in changes" -# changes['main']['HelpFiles'] = {} -# for num in range(1, len(self.user_helplist) + 1): -# changes.add_option( -# 'main', 'HelpFiles', str(num), -# ';'.join(self.user_helplist[num-1][:2])) - - def create_page_extensions(self): """Part of the config dialog used for configuring IDLE extensions. @@ -1849,7 +1599,6 @@ class GenPage(Frame): def __init__(self, parent): super().__init__(parent) - self.parent = parent self.create_page_general() self.load_general_cfg() @@ -1897,25 +1646,23 @@ def create_page_general(self): (*)helplist: ListBox scroll_helplist: Scrollbar """ - parent = self.parent self.startup_edit = tracers.add( - IntVar(parent), ('main', 'General', 'editor-on-startup')) + IntVar(self), ('main', 'General', 'editor-on-startup')) self.autosave = tracers.add( - IntVar(parent), ('main', 'General', 'autosave')) + IntVar(self), ('main', 'General', 'autosave')) self.win_width = tracers.add( - StringVar(parent), ('main', 'EditorWindow', 'width')) + StringVar(self), ('main', 'EditorWindow', 'width')) self.win_height = tracers.add( - StringVar(parent), ('main', 'EditorWindow', 'height')) + StringVar(self), ('main', 'EditorWindow', 'height')) # Create widgets: - # body and section frames. - frame = self - frame_run = LabelFrame(frame, borderwidth=2, relief=GROOVE, + # Section frames. + frame_run = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Startup Preferences ') - frame_save = LabelFrame(frame, borderwidth=2, relief=GROOVE, + frame_save = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' autosave Preferences ') - frame_win_size = Frame(frame, borderwidth=2, relief=GROOVE) - frame_help = LabelFrame(frame, borderwidth=2, relief=GROOVE, + frame_win_size = Frame(self, borderwidth=2, relief=GROOVE) + frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE, text=' Additional Help Sources ') # frame_run. startup_title = Label(frame_run, text='At Startup') @@ -1991,8 +1738,6 @@ def create_page_general(self): self.button_helplist_add.pack(side=TOP, anchor=W) self.button_helplist_remove.pack(side=TOP, anchor=W, pady=5) - return frame - def load_general_cfg(self): "Load current configuration settings for the general options." # Set startup state. diff --git a/Lib/idlelib/idle_test/test_configdialog.py b/Lib/idlelib/idle_test/test_configdialog.py index 38654fc7f59bf4b..caeb2b5678778d8 100644 --- a/Lib/idlelib/idle_test/test_configdialog.py +++ b/Lib/idlelib/idle_test/test_configdialog.py @@ -252,10 +252,11 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - del cls.page.set, cls.page.set_add_delete_state - del cls.page.upc, cls.page.update_help_changes - cls.page.helplist.delete(0, 'end') - cls.page.user_helplist.clear() + page = cls.page + del page.set, page.set_add_delete_state + del page.upc, page.update_help_changes + page.helplist.delete(0, 'end') + page.user_helplist.clear() def setUp(self): changes.clear() diff --git a/Misc/NEWS.d/next/IDLE/2017-07-30-17-39-59.bpo-31050.AXR3kP.rst b/Misc/NEWS.d/next/IDLE/2017-07-30-17-39-59.bpo-31050.AXR3kP.rst new file mode 100644 index 000000000000000..e33b2e231d67333 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2017-07-30-17-39-59.bpo-31050.AXR3kP.rst @@ -0,0 +1,2 @@ +Factor GenPage(Frame) class from ConfigDialog. The slightly modified tests +continue to pass. Patch by Cheryl Sabella.