Skip to content

Commit c529cd5

Browse files
committed
bpo-33051: IDLE: Separate editor options from the general tab in configdialog
1 parent b609e68 commit c529cd5

File tree

3 files changed

+145
-86
lines changed

3 files changed

+145
-86
lines changed

Lib/idlelib/configdialog.py

Lines changed: 96 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def create_widgets(self):
9696
highpage: HighPage
9797
fontpage: FontPage
9898
keyspage: KeysPage
99+
editpage: EditPage
99100
genpage: GenPage
100101
extpage: self.create_page_extensions
101102
@@ -108,11 +109,13 @@ def create_widgets(self):
108109
self.highpage = HighPage(note)
109110
self.fontpage = FontPage(note, self.highpage)
110111
self.keyspage = KeysPage(note)
112+
self.editpage = EditPage(note)
111113
self.genpage = GenPage(note)
112114
self.extpage = self.create_page_extensions()
113115
note.add(self.fontpage, text='Fonts/Tabs')
114116
note.add(self.highpage, text='Highlights')
115117
note.add(self.keyspage, text=' Keys ')
118+
note.add(self.editpage, text=' Editor ')
116119
note.add(self.genpage, text=' General ')
117120
note.add(self.extpage, text='Extensions')
118121
note.enable_traversal()
@@ -1756,6 +1759,98 @@ def delete_custom_keys(self):
17561759
self.set_keys_type()
17571760

17581761

1762+
class EditPage(Frame):
1763+
1764+
def __init__(self, master):
1765+
super().__init__(master)
1766+
self.create_page_editor()
1767+
self.load_editor_cfg()
1768+
1769+
def create_page_editor(self):
1770+
"""Return frame of widgets for Editor tab.
1771+
1772+
Enable users to provisionally change editor options. Function
1773+
load_editor_cfg intializes tk variables using idleConf.
1774+
Radiobuttons save_ask_on and save_auto_on set var autosave.
1775+
Entry boxes format_width_int and context_int set var
1776+
format_width and context_lines. Setting var_name invokes
1777+
the default callback that adds option to changes.
1778+
1779+
Widgets for EditPage(Frame): (*) widgets bound to self
1780+
frame_editor: LabelFrame
1781+
frame_save: Frame
1782+
run_save_title: Label
1783+
(*)save_ask_on: Radiobutton - autosave
1784+
(*)save_auto_on: Radiobutton - autosave
1785+
frame_format: Frame
1786+
format_width_title: Label
1787+
(*)format_width_int: Entry - format_width
1788+
frame_context: Frame
1789+
context_title: Label
1790+
(*)context_int: Entry - context_lines
1791+
"""
1792+
self.autosave = tracers.add(
1793+
IntVar(self), ('main', 'General', 'autosave'))
1794+
self.format_width = tracers.add(
1795+
StringVar(self), ('extensions', 'FormatParagraph', 'max-width'))
1796+
self.context_lines = tracers.add(
1797+
StringVar(self), ('extensions', 'CodeContext', 'maxlines'))
1798+
1799+
# Create widgets:
1800+
# Section frames.
1801+
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
1802+
text=' Editor Preferences')
1803+
1804+
# Frame_editor.
1805+
frame_save = Frame(frame_editor, borderwidth=0)
1806+
run_save_title = Label(frame_save, text='At Start of Run (F5) ')
1807+
self.save_ask_on = Radiobutton(
1808+
frame_save, variable=self.autosave, value=0,
1809+
text="Prompt to Save")
1810+
self.save_auto_on = Radiobutton(
1811+
frame_save, variable=self.autosave, value=1,
1812+
text='No Prompt')
1813+
1814+
frame_format = Frame(frame_editor, borderwidth=0)
1815+
format_width_title = Label(frame_format,
1816+
text='Format Paragraph Max Width')
1817+
self.format_width_int = Entry(
1818+
frame_format, textvariable=self.format_width, width=4)
1819+
1820+
frame_context = Frame(frame_editor, borderwidth=0)
1821+
context_title = Label(frame_context, text='Max Context Lines :')
1822+
self.context_int = Entry(
1823+
frame_context, textvariable=self.context_lines, width=3)
1824+
1825+
# Pack widgets:
1826+
# Body.
1827+
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
1828+
1829+
# frame_save.
1830+
frame_save.pack(side=TOP, padx=5, pady=0, fill=X)
1831+
run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1832+
self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1833+
self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1834+
# frame_format.
1835+
frame_format.pack(side=TOP, padx=5, pady=0, fill=X)
1836+
format_width_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1837+
self.format_width_int.pack(side=TOP, padx=10, pady=5)
1838+
# frame_context.
1839+
frame_context.pack(side=TOP, padx=5, pady=0, fill=X)
1840+
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1841+
self.context_int.pack(side=TOP, padx=5, pady=5)
1842+
1843+
def load_editor_cfg(self):
1844+
"Load current configuration settings for the editor options."
1845+
# Set variables for editor windows.
1846+
self.autosave.set(idleConf.GetOption(
1847+
'main', 'General', 'autosave', default=0, type='bool'))
1848+
self.format_width.set(idleConf.GetOption(
1849+
'extensions', 'FormatParagraph', 'max-width', type='int'))
1850+
self.context_lines.set(idleConf.GetOption(
1851+
'extensions', 'CodeContext', 'maxlines', type='int'))
1852+
1853+
17591854
class GenPage(Frame):
17601855

17611856
def __init__(self, master):
@@ -1769,8 +1864,7 @@ def create_page_general(self):
17691864
Enable users to provisionally change general options. Function
17701865
load_general_cfg intializes tk variables and helplist using
17711866
idleConf. Radiobuttons startup_shell_on and startup_editor_on
1772-
set var startup_edit. Radiobuttons save_ask_on and save_auto_on
1773-
set var autosave. Entry boxes win_width_int and win_height_int
1867+
set var startup_edit. Entry boxes win_width_int and win_height_int
17741868
set var win_width and win_height. Setting var_name invokes the
17751869
default callback that adds option to changes.
17761870
@@ -1804,17 +1898,6 @@ def create_page_general(self):
18041898
paren_time_title: Label
18051899
(*)paren_flash_time: Entry - flash_delay
18061900
(*)bell_on: Checkbutton - paren_bell
1807-
frame_editor: LabelFrame
1808-
frame_save: Frame
1809-
run_save_title: Label
1810-
(*)save_ask_on: Radiobutton - autosave
1811-
(*)save_auto_on: Radiobutton - autosave
1812-
frame_format: Frame
1813-
format_width_title: Label
1814-
(*)format_width_int: Entry - format_width
1815-
frame_context: Frame
1816-
context_title: Label
1817-
(*)context_int: Entry - context_lines
18181901
frame_help: LabelFrame
18191902
frame_helplist: Frame
18201903
frame_helplist_buttons: Frame
@@ -1840,19 +1923,10 @@ def create_page_general(self):
18401923
self.paren_bell = tracers.add(
18411924
BooleanVar(self), ('extensions', 'ParenMatch', 'bell'))
18421925

1843-
self.autosave = tracers.add(
1844-
IntVar(self), ('main', 'General', 'autosave'))
1845-
self.format_width = tracers.add(
1846-
StringVar(self), ('extensions', 'FormatParagraph', 'max-width'))
1847-
self.context_lines = tracers.add(
1848-
StringVar(self), ('extensions', 'CodeContext', 'maxlines'))
1849-
18501926
# Create widgets:
18511927
# Section frames.
18521928
frame_window = LabelFrame(self, borderwidth=2, relief=GROOVE,
18531929
text=' Window Preferences')
1854-
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
1855-
text=' Editor Preferences')
18561930
frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE,
18571931
text=' Additional Help Sources ')
18581932
# Frame_window.
@@ -1895,28 +1969,6 @@ def create_page_general(self):
18951969
self.bell_on = Checkbutton(
18961970
frame_paren2, text="Bell on Mismatch", variable=self.paren_bell)
18971971

1898-
# Frame_editor.
1899-
frame_save = Frame(frame_editor, borderwidth=0)
1900-
run_save_title = Label(frame_save, text='At Start of Run (F5) ')
1901-
self.save_ask_on = Radiobutton(
1902-
frame_save, variable=self.autosave, value=0,
1903-
text="Prompt to Save")
1904-
self.save_auto_on = Radiobutton(
1905-
frame_save, variable=self.autosave, value=1,
1906-
text='No Prompt')
1907-
1908-
frame_format = Frame(frame_editor, borderwidth=0)
1909-
format_width_title = Label(frame_format,
1910-
text='Format Paragraph Max Width')
1911-
self.format_width_int = Entry(
1912-
frame_format, textvariable=self.format_width, width=4)
1913-
1914-
frame_context = Frame(frame_editor, borderwidth=0)
1915-
context_title = Label(frame_context, text='Max Context Lines :')
1916-
self.context_int = Entry(
1917-
frame_context, textvariable=self.context_lines, width=3)
1918-
1919-
19201972
# frame_help.
19211973
frame_helplist = Frame(frame_help)
19221974
frame_helplist_buttons = Frame(frame_helplist)
@@ -1940,7 +1992,6 @@ def create_page_general(self):
19401992
# Pack widgets:
19411993
# Body.
19421994
frame_window.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
1943-
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
19441995
frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
19451996
# frame_run.
19461997
frame_run.pack(side=TOP, padx=5, pady=0, fill=X)
@@ -1967,20 +2018,6 @@ def create_page_general(self):
19672018
self.bell_on.pack(side=RIGHT, anchor=E, padx=15, pady=5)
19682019
self.paren_flash_time.pack(side=TOP, anchor=W, padx=15, pady=5)
19692020

1970-
# frame_save.
1971-
frame_save.pack(side=TOP, padx=5, pady=0, fill=X)
1972-
run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1973-
self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1974-
self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1975-
# frame_format.
1976-
frame_format.pack(side=TOP, padx=5, pady=0, fill=X)
1977-
format_width_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1978-
self.format_width_int.pack(side=TOP, padx=10, pady=5)
1979-
# frame_context.
1980-
frame_context.pack(side=TOP, padx=5, pady=0, fill=X)
1981-
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1982-
self.context_int.pack(side=TOP, padx=5, pady=5)
1983-
19842021
# frame_help.
19852022
frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
19862023
frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
@@ -2008,14 +2045,6 @@ def load_general_cfg(self):
20082045
self.paren_bell.set(idleConf.GetOption(
20092046
'extensions', 'ParenMatch', 'bell'))
20102047

2011-
# Set variables for editor windows.
2012-
self.autosave.set(idleConf.GetOption(
2013-
'main', 'General', 'autosave', default=0, type='bool'))
2014-
self.format_width.set(idleConf.GetOption(
2015-
'extensions', 'FormatParagraph', 'max-width', type='int'))
2016-
self.context_lines.set(idleConf.GetOption(
2017-
'extensions', 'CodeContext', 'maxlines', type='int'))
2018-
20192048
# Set additional help sources.
20202049
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
20212050
self.helplist.delete(0, 'end')

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,54 @@ def test_delete_custom_keys(self):
10741074
del d.askyesno
10751075

10761076

1077+
class EditPageTest(unittest.TestCase):
1078+
"""Test that edtior tab widgets enable users to make changes.
1079+
1080+
Test that widget actions set vars, that var changes add
1081+
options to changes and that helplist works correctly.
1082+
"""
1083+
@classmethod
1084+
def setUpClass(cls):
1085+
page = cls.page = dialog.editpage
1086+
dialog.note.select(page)
1087+
1088+
@classmethod
1089+
def tearDownClass(cls):
1090+
page = cls.page
1091+
1092+
def setUp(self):
1093+
changes.clear()
1094+
1095+
def test_load_editor_cfg(self):
1096+
# Set to wrong values, load, check right values.
1097+
eq = self.assertEqual
1098+
d = self.page
1099+
d.autosave.set(1)
1100+
d.format_width.set(1)
1101+
d.context_lines.set(1)
1102+
d.load_editor_cfg()
1103+
eq(d.autosave.get(), 0)
1104+
eq(d.format_width.get(), '72')
1105+
eq(d.context_lines.get(), '15')
1106+
1107+
def test_autosave(self):
1108+
d = self.page
1109+
d.save_auto_on.invoke()
1110+
self.assertEqual(mainpage, {'General': {'autosave': '1'}})
1111+
d.save_ask_on.invoke()
1112+
self.assertEqual(mainpage, {'General': {'autosave': '0'}})
1113+
1114+
def test_paragraph(self):
1115+
self.page.format_width_int.delete(0, 'end')
1116+
self.page.format_width_int.insert(0, '11')
1117+
self.assertEqual(extpage, {'FormatParagraph': {'max-width': '11'}})
1118+
1119+
def test_context(self):
1120+
self.page.context_int.delete(0, 'end')
1121+
self.page.context_int.insert(0, '1')
1122+
self.assertEqual(extpage, {'CodeContext': {'maxlines': '1'}})
1123+
1124+
10771125
class GenPageTest(unittest.TestCase):
10781126
"""Test that general tab widgets enable users to make changes.
10791127
@@ -1103,15 +1151,13 @@ def test_load_general_cfg(self):
11031151
eq = self.assertEqual
11041152
d = self.page
11051153
d.startup_edit.set(1)
1106-
d.autosave.set(1)
11071154
d.win_width.set(1)
11081155
d.win_height.set(1)
11091156
d.helplist.insert('end', 'bad')
11101157
d.user_helplist = ['bad', 'worse']
11111158
idleConf.SetOption('main', 'HelpFiles', '1', 'name;file')
11121159
d.load_general_cfg()
11131160
eq(d.startup_edit.get(), 0)
1114-
eq(d.autosave.get(), 0)
11151161
eq(d.win_width.get(), '80')
11161162
eq(d.win_height.get(), '40')
11171163
eq(d.helplist.get(0, 'end'), ('name',))
@@ -1155,23 +1201,6 @@ def test_parenmatch(self):
11551201
d.bell_on.invoke()
11561202
eq(extpage, {'ParenMatch': {'bell': 'False'}})
11571203

1158-
def test_autosave(self):
1159-
d = self.page
1160-
d.save_auto_on.invoke()
1161-
self.assertEqual(mainpage, {'General': {'autosave': '1'}})
1162-
d.save_ask_on.invoke()
1163-
self.assertEqual(mainpage, {'General': {'autosave': '0'}})
1164-
1165-
def test_paragraph(self):
1166-
self.page.format_width_int.delete(0, 'end')
1167-
self.page.format_width_int.insert(0, '11')
1168-
self.assertEqual(extpage, {'FormatParagraph': {'max-width': '11'}})
1169-
1170-
def test_context(self):
1171-
self.page.context_int.delete(0, 'end')
1172-
self.page.context_int.insert(0, '1')
1173-
self.assertEqual(extpage, {'CodeContext': {'maxlines': '1'}})
1174-
11751204
def test_source_selected(self):
11761205
d = self.page
11771206
d.set = d.set_add_delete_state
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Separate editor options from the general tab in config dialog.

0 commit comments

Comments
 (0)