bpo-30993: IDLE - Improve configdialog font page and tests. (#2831) · python/cpython@77e97ca (original) (raw)
`@@ -150,6 +150,7 @@ def create_action_buttons(self):
`
150
150
`buttons.pack(side=BOTTOM)
`
151
151
`return outer
`
152
152
``
``
153
+
153
154
`def create_page_font_tab(self):
`
154
155
`"""Return frame of widgets for Font/Tabs tab.
`
155
156
``
`@@ -159,29 +160,26 @@ def create_page_font_tab(self):
`
159
160
` corresponding aspect of the font sample on this page and
`
160
161
` highlight sample on highlight page.
`
161
162
``
``
163
`+
Load_font_cfg initializes font vars and widgets from
`
``
164
`+
idleConf entries and tk.
`
``
165
+
162
166
` Fontlist: mouse button 1 click or up or down key invoke
`
163
``
`-
on_fontlist_select(), which sets Var font_name and calls
`
164
``
`-
set_samples.
`
``
167
`+
on_fontlist_select(), which sets var font_name.
`
165
168
``
166
169
` Sizelist: clicking the menubutton opens the dropdown menu. A
`
167
``
`-
mouse button 1 click or return key invokes an internal command
`
168
``
`-
which sets Var font_size and calls set_samples.
`
``
170
`+
mouse button 1 click or return key sets var font_size.
`
169
171
``
170
``
`-
Bold_toggle, clicking the box toggles font_bold and calls
`
171
``
`-
set_samples.
`
``
172
`+
Bold_toggle: clicking the box toggles var font_bold.
`
172
173
``
173
``
`-
Setting any of the font vars invokes var_changed_font, which
`
174
``
`-
adds all 3 font options to changes. Set_samples applies a new
`
175
``
`-
font constructed from the font vars to font_sample and
`
176
``
`-
highlight_sample on the hightlight page.
`
``
174
`+
Changing any of the font vars invokes var_changed_font, which
`
``
175
`+
adds all 3 font options to changes and calls set_samples.
`
``
176
`+
Set_samples applies a new font constructed from the font vars to
`
``
177
`+
font_sample and to highlight_sample on the hightlight page.
`
177
178
``
178
179
` Tabs: Enable users to change spaces entered for indent tabs.
`
179
180
` Changing indent_scale value with the mouse sets Var space_num,
`
180
181
` which invokes var_changed_space_num, which adds an entry to
`
181
``
`-
changes.
`
182
``
-
183
``
`-
Load_font_cfg and load_tab_cfg initialize vars and widgets from
`
184
``
`-
idleConf entries.
`
``
182
`+
changes. Load_tab_cfg initializes space_num to default.
`
185
183
``
186
184
` Widget Structure: (*) widgets bound to self
`
187
185
` frame (of tab_pages)
`
`@@ -227,11 +225,10 @@ def create_page_font_tab(self):
`
227
225
`scroll_font.config(command=self.fontlist.yview)
`
228
226
`self.fontlist.config(yscrollcommand=scroll_font.set)
`
229
227
`font_size_title = Label(frame_font_param, text='Size :')
`
230
``
`-
self.sizelist = DynOptionMenu(frame_font_param, self.font_size,
`
231
``
`-
None, command=self.set_samples)
`
``
228
`+
self.sizelist = DynOptionMenu(frame_font_param, self.font_size, None)
`
232
229
`self.bold_toggle = Checkbutton(
`
233
``
`-
frame_font_param, variable=self.font_bold, onvalue=1,
`
234
``
`-
offvalue=0, text='Bold', command=self.set_samples)
`
``
230
`+
frame_font_param, variable=self.font_bold,
`
``
231
`+
onvalue=1, offvalue=0, text='Bold')
`
235
232
`frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)
`
236
233
`temp_font = tkFont.Font(parent, ('courier', 10, 'normal'))
`
237
234
`self.font_sample = Label(
`
`@@ -267,6 +264,96 @@ def create_page_font_tab(self):
`
267
264
``
268
265
`return frame
`
269
266
``
``
267
`+
def load_font_cfg(self):
`
``
268
`+
"""Load current configuration settings for the font options.
`
``
269
+
``
270
`+
Retrieve current font with idleConf.GetFont and font families
`
``
271
`+
from tk. Setup fontlist and set font_name. Setup sizelist,
`
``
272
`+
which sets font_size. Set font_bold. Setting font variables
`
``
273
`+
calls set_samples (thrice).
`
``
274
`+
"""
`
``
275
`+
configured_font = idleConf.GetFont(self, 'main', 'EditorWindow')
`
``
276
`+
font_name = configured_font[0].lower()
`
``
277
`+
font_size = configured_font[1]
`
``
278
`+
font_bold = configured_font[2]=='bold'
`
``
279
+
``
280
`+
Set editor font selection list and font_name.
`
``
281
`+
fonts = list(tkFont.families(self))
`
``
282
`+
fonts.sort()
`
``
283
`+
for font in fonts:
`
``
284
`+
self.fontlist.insert(END, font)
`
``
285
`+
self.font_name.set(font_name)
`
``
286
`+
lc_fonts = [s.lower() for s in fonts]
`
``
287
`+
try:
`
``
288
`+
current_font_index = lc_fonts.index(font_name)
`
``
289
`+
self.fontlist.see(current_font_index)
`
``
290
`+
self.fontlist.select_set(current_font_index)
`
``
291
`+
self.fontlist.select_anchor(current_font_index)
`
``
292
`+
self.fontlist.activate(current_font_index)
`
``
293
`+
except ValueError:
`
``
294
`+
pass
`
``
295
`+
Set font size dropdown.
`
``
296
`+
self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14',
`
``
297
`+
'16', '18', '20', '22', '25', '29', '34', '40'),
`
``
298
`+
font_size)
`
``
299
`+
Set font weight.
`
``
300
`+
self.font_bold.set(font_bold)
`
``
301
+
``
302
`+
def on_fontlist_select(self, event):
`
``
303
`+
"""Handle selecting a font from the list.
`
``
304
+
``
305
`+
Event can result from either mouse click or Up or Down key.
`
``
306
`+
Set font_name and example displays to selection.
`
``
307
`+
"""
`
``
308
`+
font = self.fontlist.get(
`
``
309
`+
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
`
``
310
`+
self.font_name.set(font.lower())
`
``
311
+
``
312
`+
def var_changed_font(self, *params):
`
``
313
`+
"""Store changes to font attributes.
`
``
314
+
``
315
`+
When one font attribute changes, save them all, as they are
`
``
316
`+
not independent from each other. In particular, when we are
`
``
317
`+
overriding the default font, we need to write out everything.
`
``
318
`+
"""
`
``
319
`+
value = self.font_name.get()
`
``
320
`+
changes.add_option('main', 'EditorWindow', 'font', value)
`
``
321
`+
value = self.font_size.get()
`
``
322
`+
changes.add_option('main', 'EditorWindow', 'font-size', value)
`
``
323
`+
value = self.font_bold.get()
`
``
324
`+
changes.add_option('main', 'EditorWindow', 'font-bold', value)
`
``
325
`+
self.set_samples()
`
``
326
+
``
327
`+
def set_samples(self, event=None):
`
``
328
`+
"""Update update both screen samples with the font settings.
`
``
329
+
``
330
`+
Called on font initialization and change events.
`
``
331
`+
Accesses font_name, font_size, and font_bold Variables.
`
``
332
`+
Updates font_sample and hightlight page highlight_sample.
`
``
333
`+
"""
`
``
334
`+
font_name = self.font_name.get()
`
``
335
`+
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
`
``
336
`+
new_font = (font_name, self.font_size.get(), font_weight)
`
``
337
`+
self.font_sample['font'] = new_font
`
``
338
`+
self.highlight_sample['font'] = new_font
`
``
339
+
``
340
`+
def load_tab_cfg(self):
`
``
341
`+
"""Load current configuration settings for the tab options.
`
``
342
+
``
343
`+
Attributes updated:
`
``
344
`+
space_num: Set to value from idleConf.
`
``
345
`+
"""
`
``
346
`+
Set indent sizes.
`
``
347
`+
space_num = idleConf.GetOption(
`
``
348
`+
'main', 'Indent', 'num-spaces', default=4, type='int')
`
``
349
`+
self.space_num.set(space_num)
`
``
350
+
``
351
`+
def var_changed_space_num(self, *params):
`
``
352
`+
"Store change to indentation size."
`
``
353
`+
value = self.space_num.get()
`
``
354
`+
changes.add_option('main', 'Indent', 'num-spaces', value)
`
``
355
+
``
356
+
270
357
`def create_page_highlight(self):
`
271
358
`"""Return frame of widgets for Highlighting tab.
`
272
359
``
`@@ -729,25 +816,6 @@ def remove_var_callbacks(self):
`
729
816
`self.startup_edit, self.autosave,):
`
730
817
`var.trace_remove('write', var.trace_info()[0][1])
`
731
818
``
732
``
`-
def var_changed_font(self, *params):
`
733
``
`-
"""Store changes to font attributes.
`
734
``
-
735
``
`-
When one font attribute changes, save them all, as they are
`
736
``
`-
not independent from each other. In particular, when we are
`
737
``
`-
overriding the default font, we need to write out everything.
`
738
``
`-
"""
`
739
``
`-
value = self.font_name.get()
`
740
``
`-
changes.add_option('main', 'EditorWindow', 'font', value)
`
741
``
`-
value = self.font_size.get()
`
742
``
`-
changes.add_option('main', 'EditorWindow', 'font-size', value)
`
743
``
`-
value = self.font_bold.get()
`
744
``
`-
changes.add_option('main', 'EditorWindow', 'font-bold', value)
`
745
``
-
746
``
`-
def var_changed_space_num(self, *params):
`
747
``
`-
"Store change to indentation size."
`
748
``
`-
value = self.space_num.get()
`
749
``
`-
changes.add_option('main', 'Indent', 'num-spaces', value)
`
750
``
-
751
819
`def var_changed_color(self, *params):
`
752
820
`"Process change to color choice."
`
753
821
`self.on_new_color_set()
`
`@@ -1216,30 +1284,6 @@ def create_new_theme(self, new_theme_name):
`
1216
1284
`self.is_builtin_theme.set(0)
`
1217
1285
`self.set_theme_type()
`
1218
1286
``
1219
``
`-
def on_fontlist_select(self, event):
`
1220
``
`-
"""Handle selecting a font from the list.
`
1221
``
-
1222
``
`-
Event can result from either mouse click or Up or Down key.
`
1223
``
`-
Set font_name and example displays to selection.
`
1224
``
`-
"""
`
1225
``
`-
font = self.fontlist.get(
`
1226
``
`-
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
`
1227
``
`-
self.font_name.set(font.lower())
`
1228
``
`-
self.set_samples()
`
1229
``
-
1230
``
`-
def set_samples(self, event=None):
`
1231
``
`-
"""Update update both screen samples with the font settings.
`
1232
``
-
1233
``
`-
Called on font initialization and change events.
`
1234
``
`-
Accesses font_name, font_size, and font_bold Variables.
`
1235
``
`-
Updates font_sample and hightlight page highlight_sample.
`
1236
``
`-
"""
`
1237
``
`-
font_name = self.font_name.get()
`
1238
``
`-
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
`
1239
``
`-
new_font = (font_name, self.font_size.get(), font_weight)
`
1240
``
`-
self.font_sample['font'] = new_font
`
1241
``
`-
self.highlight_sample['font'] = new_font
`
1242
``
-
1243
1287
`def set_highlight_target(self):
`
1244
1288
`"""Set fg/bg toggle and color based on highlight tag target.
`
1245
1289
``
`@@ -1404,61 +1448,6 @@ def update_user_help_changed_items(self):
`
1404
1448
`'main', 'HelpFiles', str(num),
`
1405
1449
`';'.join(self.user_helplist[num-1][:2]))
`
1406
1450
``
1407
``
`-
def load_font_cfg(self):
`
1408
``
`-
"""Load current configuration settings for the font options.
`
1409
``
-
1410
``
`-
Retrieve current font values from idleConf.GetFont to set
`
1411
``
`-
as initial values for font widgets.
`
1412
``
-
1413
``
`-
Attributes updated:
`
1414
``
`-
fontlist: Populate with fonts from tkinter.font.
`
1415
``
`-
font_name: Set to current font.
`
1416
``
`-
sizelist: Populate valid options tuple and set
`
1417
``
`-
to current size.
`
1418
``
`-
font_bold: Set to current font weight.
`
1419
``
-
1420
``
`-
Methods:
`
1421
``
`-
set_samples
`
1422
``
`-
"""
`
1423
``
`-
Set base editor font selection list.
`
1424
``
`-
fonts = list(tkFont.families(self))
`
1425
``
`-
fonts.sort()
`
1426
``
`-
for font in fonts:
`
1427
``
`-
self.fontlist.insert(END, font)
`
1428
``
`-
configured_font = idleConf.GetFont(self, 'main', 'EditorWindow')
`
1429
``
`-
font_name = configured_font[0].lower()
`
1430
``
`-
font_size = configured_font[1]
`
1431
``
`-
font_bold = configured_font[2]=='bold'
`
1432
``
`-
self.font_name.set(font_name)
`
1433
``
`-
lc_fonts = [s.lower() for s in fonts]
`
1434
``
`-
try:
`
1435
``
`-
current_font_index = lc_fonts.index(font_name)
`
1436
``
`-
self.fontlist.see(current_font_index)
`
1437
``
`-
self.fontlist.select_set(current_font_index)
`
1438
``
`-
self.fontlist.select_anchor(current_font_index)
`
1439
``
`-
self.fontlist.activate(current_font_index)
`
1440
``
`-
except ValueError:
`
1441
``
`-
pass
`
1442
``
`-
Set font size dropdown.
`
1443
``
`-
self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14',
`
1444
``
`-
'16', '18', '20', '22', '25', '29', '34', '40'),
`
1445
``
`-
font_size)
`
1446
``
`-
Set font weight.
`
1447
``
`-
self.font_bold.set(font_bold)
`
1448
``
`-
Set font sample.
`
1449
``
`-
self.set_samples()
`
1450
``
-
1451
``
`-
def load_tab_cfg(self):
`
1452
``
`-
"""Load current configuration settings for the tab options.
`
1453
``
-
1454
``
`-
Attributes updated:
`
1455
``
`-
space_num: Set to value from idleConf.
`
1456
``
`-
"""
`
1457
``
`-
Set indent sizes.
`
1458
``
`-
space_num = idleConf.GetOption(
`
1459
``
`-
'main', 'Indent', 'num-spaces', default=4, type='int')
`
1460
``
`-
self.space_num.set(space_num)
`
1461
``
-
1462
1451
`def load_theme_cfg(self):
`
1463
1452
`"""Load current configuration settings for the theme options.
`
1464
1453
``