Skip to content

Commit e8e7fe6

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

File tree

3 files changed

+198
-138
lines changed

3 files changed

+198
-138
lines changed

Lib/idlelib/configdialog.py

Lines changed: 149 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def create_widgets(self):
101101
highpage: HighPage
102102
fontpage: FontPage
103103
keyspage: KeysPage
104+
editpage: EditPage
104105
genpage: GenPage
105106
extpage: self.create_page_extensions
106107
@@ -113,11 +114,13 @@ def create_widgets(self):
113114
self.highpage = HighPage(note)
114115
self.fontpage = FontPage(note, self.highpage)
115116
self.keyspage = KeysPage(note)
117+
self.editpage = EditPage(note)
116118
self.genpage = GenPage(note)
117119
self.extpage = self.create_page_extensions()
118120
note.add(self.fontpage, text='Fonts/Tabs')
119121
note.add(self.highpage, text='Highlights')
120122
note.add(self.keyspage, text=' Keys ')
123+
note.add(self.editpage, text=' Editor ')
121124
note.add(self.genpage, text=' General ')
122125
note.add(self.extpage, text='Extensions')
123126
note.enable_traversal()
@@ -1774,6 +1777,151 @@ def delete_custom_keys(self):
17741777
self.set_keys_type()
17751778

17761779

1780+
class EditPage(Frame):
1781+
1782+
def __init__(self, master):
1783+
super().__init__(master)
1784+
self.create_page_editor()
1785+
self.load_editor_cfg()
1786+
1787+
def create_page_editor(self):
1788+
"""Return frame of widgets for Editor tab.
1789+
1790+
Enable users to provisionally change editor options. Function
1791+
load_editor_cfg intializes tk variables using idleConf.
1792+
Radiobuttons save_ask_on and save_auto_on set var autosave.
1793+
Entry boxes format_width_int and context_int set var
1794+
format_width and context_lines. Setting var_name invokes
1795+
the default callback that adds option to changes.
1796+
1797+
Widgets for EditPage(Frame): (*) widgets bound to self
1798+
frame_editor: LabelFrame
1799+
frame_save: Frame
1800+
run_save_title: Label
1801+
(*)save_ask_on: Radiobutton - autosave
1802+
(*)save_auto_on: Radiobutton - autosave
1803+
frame_format: Frame
1804+
format_width_title: Label
1805+
(*)format_width_int: Entry - format_width
1806+
frame_line_numbers_default: Frame
1807+
line_numbers_default_title: Label
1808+
(*)line_numbers_default_bool: Checkbutton - line_numbers_default
1809+
frame_context: Frame
1810+
context_title: Label
1811+
(*)context_int: Entry - context_lines
1812+
frame_shell: LabelFrame
1813+
frame_auto_squeeze_min_lines: Frame
1814+
auto_squeeze_min_lines_title: Label
1815+
(*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines
1816+
"""
1817+
self.auto_squeeze_min_lines = tracers.add(
1818+
StringVar(self), ('main', 'PyShell', 'auto-squeeze-min-lines'))
1819+
1820+
self.autosave = tracers.add(
1821+
IntVar(self), ('main', 'General', 'autosave'))
1822+
self.format_width = tracers.add(
1823+
StringVar(self), ('extensions', 'FormatParagraph', 'max-width'))
1824+
self.line_numbers_default = tracers.add(
1825+
BooleanVar(self),
1826+
('main', 'EditorWindow', 'line-numbers-default'))
1827+
self.context_lines = tracers.add(
1828+
StringVar(self), ('extensions', 'CodeContext', 'maxlines'))
1829+
1830+
# Create widgets:
1831+
# Section frames.
1832+
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
1833+
text=' Editor Preferences')
1834+
frame_shell = LabelFrame(self, borderwidth=2, relief=GROOVE,
1835+
text=' Shell Preferences')
1836+
1837+
# Frame_editor.
1838+
frame_save = Frame(frame_editor, borderwidth=0)
1839+
run_save_title = Label(frame_save, text='At Start of Run (F5) ')
1840+
self.save_ask_on = Radiobutton(
1841+
frame_save, variable=self.autosave, value=0,
1842+
text="Prompt to Save")
1843+
self.save_auto_on = Radiobutton(
1844+
frame_save, variable=self.autosave, value=1,
1845+
text='No Prompt')
1846+
1847+
frame_format = Frame(frame_editor, borderwidth=0)
1848+
format_width_title = Label(frame_format,
1849+
text='Format Paragraph Max Width')
1850+
self.format_width_int = Entry(
1851+
frame_format, textvariable=self.format_width, width=4,
1852+
validatecommand=self.digits_only, validate='key',
1853+
)
1854+
1855+
frame_line_numbers_default = Frame(frame_editor, borderwidth=0)
1856+
line_numbers_default_title = Label(
1857+
frame_line_numbers_default, text='Show line numbers in new windows')
1858+
self.line_numbers_default_bool = Checkbutton(
1859+
frame_line_numbers_default,
1860+
variable=self.line_numbers_default,
1861+
width=1)
1862+
1863+
frame_context = Frame(frame_editor, borderwidth=0)
1864+
context_title = Label(frame_context, text='Max Context Lines :')
1865+
self.context_int = Entry(
1866+
frame_context, textvariable=self.context_lines, width=3,
1867+
validatecommand=self.digits_only, validate='key',
1868+
)
1869+
1870+
# Frame_shell.
1871+
frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
1872+
auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
1873+
text='Auto-Squeeze Min. Lines:')
1874+
self.auto_squeeze_min_lines_int = Entry(
1875+
frame_auto_squeeze_min_lines, width=4,
1876+
textvariable=self.auto_squeeze_min_lines,
1877+
validatecommand=self.digits_only, validate='key',
1878+
)
1879+
1880+
# Pack widgets:
1881+
# Body.
1882+
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
1883+
frame_shell.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
1884+
1885+
# frame_save.
1886+
frame_save.pack(side=TOP, padx=5, pady=0, fill=X)
1887+
run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1888+
self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1889+
self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
1890+
# frame_format.
1891+
frame_format.pack(side=TOP, padx=5, pady=0, fill=X)
1892+
format_width_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1893+
self.format_width_int.pack(side=TOP, padx=10, pady=5)
1894+
# frame_line_numbers_default.
1895+
frame_line_numbers_default.pack(side=TOP, padx=5, pady=0, fill=X)
1896+
line_numbers_default_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1897+
self.line_numbers_default_bool.pack(side=LEFT, padx=5, pady=5)
1898+
# frame_context.
1899+
frame_context.pack(side=TOP, padx=5, pady=0, fill=X)
1900+
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1901+
self.context_int.pack(side=TOP, padx=5, pady=5)
1902+
1903+
# frame_auto_squeeze_min_lines
1904+
frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X)
1905+
auto_squeeze_min_lines_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
1906+
self.auto_squeeze_min_lines_int.pack(side=TOP, padx=5, pady=5)
1907+
1908+
def load_editor_cfg(self):
1909+
"Load current configuration settings for the editor options."
1910+
# Set variables for editor windows.
1911+
self.autosave.set(idleConf.GetOption(
1912+
'main', 'General', 'autosave', default=0, type='bool'))
1913+
self.format_width.set(idleConf.GetOption(
1914+
'extensions', 'FormatParagraph', 'max-width', type='int'))
1915+
self.line_numbers_default.set(idleConf.GetOption(
1916+
'main', 'EditorWindow', 'line-numbers-default', type='bool'))
1917+
self.context_lines.set(idleConf.GetOption(
1918+
'extensions', 'CodeContext', 'maxlines', type='int'))
1919+
1920+
# Set variables for shell windows.
1921+
self.auto_squeeze_min_lines.set(idleConf.GetOption(
1922+
'main', 'PyShell', 'auto-squeeze-min-lines', type='int'))
1923+
1924+
17771925
class GenPage(Frame):
17781926

17791927
def __init__(self, master):
@@ -1796,8 +1944,7 @@ def create_page_general(self):
17961944
Enable users to provisionally change general options. Function
17971945
load_general_cfg initializes tk variables and helplist using
17981946
idleConf. Radiobuttons startup_shell_on and startup_editor_on
1799-
set var startup_edit. Radiobuttons save_ask_on and save_auto_on
1800-
set var autosave. Entry boxes win_width_int and win_height_int
1947+
set var startup_edit. Entry boxes win_width_int and win_height_int
18011948
set var win_width and win_height. Setting var_name invokes the
18021949
default callback that adds option to changes.
18031950
@@ -1834,24 +1981,6 @@ def create_page_general(self):
18341981
paren_time_title: Label
18351982
(*)paren_flash_time: Entry - flash_delay
18361983
(*)bell_on: Checkbutton - paren_bell
1837-
frame_editor: LabelFrame
1838-
frame_save: Frame
1839-
run_save_title: Label
1840-
(*)save_ask_on: Radiobutton - autosave
1841-
(*)save_auto_on: Radiobutton - autosave
1842-
frame_format: Frame
1843-
format_width_title: Label
1844-
(*)format_width_int: Entry - format_width
1845-
frame_line_numbers_default: Frame
1846-
line_numbers_default_title: Label
1847-
(*)line_numbers_default_bool: Checkbutton - line_numbers_default
1848-
frame_context: Frame
1849-
context_title: Label
1850-
(*)context_int: Entry - context_lines
1851-
frame_shell: LabelFrame
1852-
frame_auto_squeeze_min_lines: Frame
1853-
auto_squeeze_min_lines_title: Label
1854-
(*)auto_squeeze_min_lines_int: Entry - auto_squeeze_min_lines
18551984
frame_help: LabelFrame
18561985
frame_helplist: Frame
18571986
frame_helplist_buttons: Frame
@@ -1879,27 +2008,10 @@ def create_page_general(self):
18792008
self.paren_bell = tracers.add(
18802009
BooleanVar(self), ('extensions', 'ParenMatch', 'bell'))
18812010

1882-
self.auto_squeeze_min_lines = tracers.add(
1883-
StringVar(self), ('main', 'PyShell', 'auto-squeeze-min-lines'))
1884-
1885-
self.autosave = tracers.add(
1886-
IntVar(self), ('main', 'General', 'autosave'))
1887-
self.format_width = tracers.add(
1888-
StringVar(self), ('extensions', 'FormatParagraph', 'max-width'))
1889-
self.line_numbers_default = tracers.add(
1890-
BooleanVar(self),
1891-
('main', 'EditorWindow', 'line-numbers-default'))
1892-
self.context_lines = tracers.add(
1893-
StringVar(self), ('extensions', 'CodeContext', 'maxlines'))
1894-
18952011
# Create widgets:
18962012
# Section frames.
18972013
frame_window = LabelFrame(self, borderwidth=2, relief=GROOVE,
18982014
text=' Window Preferences')
1899-
frame_editor = LabelFrame(self, borderwidth=2, relief=GROOVE,
1900-
text=' Editor Preferences')
1901-
frame_shell = LabelFrame(self, borderwidth=2, relief=GROOVE,
1902-
text=' Shell Preferences')
19032015
frame_help = LabelFrame(self, borderwidth=2, relief=GROOVE,
19042016
text=' Additional Help Sources ')
19052017
# Frame_window.
@@ -1954,49 +2066,6 @@ def create_page_general(self):
19542066
self.bell_on = Checkbutton(
19552067
frame_paren2, text="Bell on Mismatch", variable=self.paren_bell)
19562068

1957-
# Frame_editor.
1958-
frame_save = Frame(frame_editor, borderwidth=0)
1959-
run_save_title = Label(frame_save, text='At Start of Run (F5) ')
1960-
self.save_ask_on = Radiobutton(
1961-
frame_save, variable=self.autosave, value=0,
1962-
text="Prompt to Save")
1963-
self.save_auto_on = Radiobutton(
1964-
frame_save, variable=self.autosave, value=1,
1965-
text='No Prompt')
1966-
1967-
frame_format = Frame(frame_editor, borderwidth=0)
1968-
format_width_title = Label(frame_format,
1969-
text='Format Paragraph Max Width')
1970-
self.format_width_int = Entry(
1971-
frame_format, textvariable=self.format_width, width=4,
1972-
validatecommand=self.digits_only, validate='key',
1973-
)
1974-
1975-
frame_line_numbers_default = Frame(frame_editor, borderwidth=0)
1976-
line_numbers_default_title = Label(
1977-
frame_line_numbers_default, text='Show line numbers in new windows')
1978-
self.line_numbers_default_bool = Checkbutton(
1979-
frame_line_numbers_default,
1980-
variable=self.line_numbers_default,
1981-
width=1)
1982-
1983-
frame_context = Frame(frame_editor, borderwidth=0)
1984-
context_title = Label(frame_context, text='Max Context Lines :')
1985-
self.context_int = Entry(
1986-
frame_context, textvariable=self.context_lines, width=3,
1987-
validatecommand=self.digits_only, validate='key',
1988-
)
1989-
1990-
# Frame_shell.
1991-
frame_auto_squeeze_min_lines = Frame(frame_shell, borderwidth=0)
1992-
auto_squeeze_min_lines_title = Label(frame_auto_squeeze_min_lines,
1993-
text='Auto-Squeeze Min. Lines:')
1994-
self.auto_squeeze_min_lines_int = Entry(
1995-
frame_auto_squeeze_min_lines, width=4,
1996-
textvariable=self.auto_squeeze_min_lines,
1997-
validatecommand=self.digits_only, validate='key',
1998-
)
1999-
20002069
# frame_help.
20012070
frame_helplist = Frame(frame_help)
20022071
frame_helplist_buttons = Frame(frame_helplist)
@@ -2020,8 +2089,6 @@ def create_page_general(self):
20202089
# Pack widgets:
20212090
# Body.
20222091
frame_window.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
2023-
frame_editor.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
2024-
frame_shell.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
20252092
frame_help.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
20262093
# frame_run.
20272094
frame_run.pack(side=TOP, padx=5, pady=0, fill=X)
@@ -2052,29 +2119,6 @@ def create_page_general(self):
20522119
self.bell_on.pack(side=RIGHT, anchor=E, padx=15, pady=5)
20532120
self.paren_flash_time.pack(side=TOP, anchor=W, padx=15, pady=5)
20542121

2055-
# frame_save.
2056-
frame_save.pack(side=TOP, padx=5, pady=0, fill=X)
2057-
run_save_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2058-
self.save_auto_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
2059-
self.save_ask_on.pack(side=RIGHT, anchor=W, padx=5, pady=5)
2060-
# frame_format.
2061-
frame_format.pack(side=TOP, padx=5, pady=0, fill=X)
2062-
format_width_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2063-
self.format_width_int.pack(side=TOP, padx=10, pady=5)
2064-
# frame_line_numbers_default.
2065-
frame_line_numbers_default.pack(side=TOP, padx=5, pady=0, fill=X)
2066-
line_numbers_default_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2067-
self.line_numbers_default_bool.pack(side=LEFT, padx=5, pady=5)
2068-
# frame_context.
2069-
frame_context.pack(side=TOP, padx=5, pady=0, fill=X)
2070-
context_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2071-
self.context_int.pack(side=TOP, padx=5, pady=5)
2072-
2073-
# frame_auto_squeeze_min_lines
2074-
frame_auto_squeeze_min_lines.pack(side=TOP, padx=5, pady=0, fill=X)
2075-
auto_squeeze_min_lines_title.pack(side=LEFT, anchor=W, padx=5, pady=5)
2076-
self.auto_squeeze_min_lines_int.pack(side=TOP, padx=5, pady=5)
2077-
20782122
# frame_help.
20792123
frame_helplist_buttons.pack(side=RIGHT, padx=5, pady=5, fill=Y)
20802124
frame_helplist.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
@@ -2104,20 +2148,6 @@ def load_general_cfg(self):
21042148
self.paren_bell.set(idleConf.GetOption(
21052149
'extensions', 'ParenMatch', 'bell'))
21062150

2107-
# Set variables for editor windows.
2108-
self.autosave.set(idleConf.GetOption(
2109-
'main', 'General', 'autosave', default=0, type='bool'))
2110-
self.format_width.set(idleConf.GetOption(
2111-
'extensions', 'FormatParagraph', 'max-width', type='int'))
2112-
self.line_numbers_default.set(idleConf.GetOption(
2113-
'main', 'EditorWindow', 'line-numbers-default', type='bool'))
2114-
self.context_lines.set(idleConf.GetOption(
2115-
'extensions', 'CodeContext', 'maxlines', type='int'))
2116-
2117-
# Set variables for shell windows.
2118-
self.auto_squeeze_min_lines.set(idleConf.GetOption(
2119-
'main', 'PyShell', 'auto-squeeze-min-lines', type='int'))
2120-
21212151
# Set additional help sources.
21222152
self.user_helplist = idleConf.GetAllExtraHelpSourcesList()
21232153
self.helplist.delete(0, 'end')

0 commit comments

Comments
 (0)