Skip to content

Commit 04864b4

Browse files
authored
[3.6] bpo-30981: IDLE -- Add more configdialog font page tests. (GH-… (#2796)
Verify that clicking the bold checkbutton and calling its command, set_samples, changes the bold setting of both samples. Simplify some names in configdialog. (cherry picked from commit d0969d6) (Incorporates changes and fixes from PRs 2798, 7c5798e, and 2810, 616ecf1) * Fix broken test with PR2798 and PR2810 changes.
1 parent 64b9a15 commit 04864b4

File tree

3 files changed

+76
-65
lines changed

3 files changed

+76
-65
lines changed

Lib/idlelib/configdialog.py

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,29 @@ def create_action_buttons(self):
153153
def create_page_font_tab(self):
154154
"""Return frame of widgets for Font/Tabs tab.
155155
156+
Enable users to provisionally change font face, size, or
157+
boldness and to see the consequence of proposed choices. Each
158+
action set 3 options in changes structuree and changes the
159+
corresponding aspect of the font sample on this page and
160+
highlight sample on highlight page.
161+
162+
Enable users to change spaces entered for indent tabs.
163+
156164
Tk Variables:
165+
font_name: Font face.
157166
font_size: Font size.
158167
font_bold: Select font bold or not.
159-
font_name: Font face.
160168
Note: these 3 share var_changed_font callback.
161169
space_num: Indentation width.
162170
163171
Data Attribute:
164-
edit_font: Font widget with default font name, size, and weight.
172+
edit_font: Font with default font name, size, and weight.
165173
166174
Methods:
167175
load_font_cfg: Set vars and fontlist.
168176
on_fontlist_select: Bound to fontlist button release
169177
or key release.
170-
set_font_sample: Command for opt_menu_font_size and
171-
check_font_bold.
178+
set_samples: Notify both samples of any font change.
172179
load_tab_cfg: Get current.
173180
174181
Widget Structure: (*) widgets bound to self
@@ -181,7 +188,7 @@ def create_page_font_tab(self):
181188
frame_font_param: Frame
182189
font_size_title: Label
183190
(*)opt_menu_font_size: DynOptionMenu - font_size
184-
check_font_bold: Checkbutton - font_bold
191+
(*)bold_toggle: Checkbutton - font_bold
185192
frame_font_sample: Frame
186193
(*)font_sample: Label
187194
frame_indent: LabelFrame
@@ -190,9 +197,9 @@ def create_page_font_tab(self):
190197
(*)scale_indent_size: Scale - space_num
191198
"""
192199
parent = self.parent
200+
self.font_name = StringVar(parent)
193201
self.font_size = StringVar(parent)
194202
self.font_bold = BooleanVar(parent)
195-
self.font_name = StringVar(parent)
196203
self.space_num = IntVar(parent)
197204
self.edit_font = tkFont.Font(parent, ('courier', 10, 'normal'))
198205

@@ -218,10 +225,10 @@ def create_page_font_tab(self):
218225
self.fontlist.config(yscrollcommand=scroll_font.set)
219226
font_size_title = Label(frame_font_param, text='Size :')
220227
self.opt_menu_font_size = DynOptionMenu(
221-
frame_font_param, self.font_size, None, command=self.set_font_sample)
222-
check_font_bold = Checkbutton(
228+
frame_font_param, self.font_size, None, command=self.set_samples)
229+
self.bold_toggle = Checkbutton(
223230
frame_font_param, variable=self.font_bold, onvalue=1,
224-
offvalue=0, text='Bold', command=self.set_font_sample)
231+
offvalue=0, text='Bold', command=self.set_samples)
225232
frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)
226233
self.font_sample = Label(
227234
frame_font_sample, justify=LEFT, font=self.edit_font,
@@ -247,7 +254,7 @@ def create_page_font_tab(self):
247254
scroll_font.pack(side=LEFT, fill=Y)
248255
font_size_title.pack(side=LEFT, anchor=W)
249256
self.opt_menu_font_size.pack(side=LEFT, anchor=W)
250-
check_font_bold.pack(side=LEFT, anchor=W, padx=20)
257+
self.bold_toggle.pack(side=LEFT, anchor=W, padx=20)
251258
frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
252259
self.font_sample.pack(expand=TRUE, fill=BOTH)
253260
# frame_indent
@@ -292,7 +299,7 @@ def create_page_highlight(self):
292299
Widget Structure: (*) widgets bound to self
293300
frame
294301
frame_custom: LabelFrame
295-
(*)text_highlight_sample: Text
302+
(*)highlight_sample: Text
296303
(*)frame_color_set: Frame
297304
button_set_color: Button
298305
(*)opt_menu_highlight_target: DynOptionMenu - highlight_target
@@ -342,11 +349,11 @@ def create_page_highlight(self):
342349
frame_theme = LabelFrame(frame, borderwidth=2, relief=GROOVE,
343350
text=' Highlighting Theme ')
344351
#frame_custom
345-
self.text_highlight_sample=Text(
352+
self.highlight_sample=Text(
346353
frame_custom, relief=SOLID, borderwidth=1,
347354
font=('courier', 12, ''), cursor='hand2', width=21, height=11,
348355
takefocus=FALSE, highlightthickness=0, wrap=NONE)
349-
text=self.text_highlight_sample
356+
text=self.highlight_sample
350357
text.bind('<Double-Button-1>', lambda e: 'break')
351358
text.bind('<B1-Motion>', lambda e: 'break')
352359
text_and_tags=(
@@ -416,7 +423,7 @@ def tem(event, elem=element):
416423
#frame_custom
417424
self.frame_color_set.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X)
418425
frame_fg_bg_toggle.pack(side=TOP, padx=5, pady=0)
419-
self.text_highlight_sample.pack(
426+
self.highlight_sample.pack(
420427
side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
421428
button_set_color.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4)
422429
self.opt_menu_highlight_target.pack(
@@ -1142,7 +1149,7 @@ def on_new_color_set(self):
11421149
self.frame_color_set.config(bg=new_color) # Set sample.
11431150
plane ='foreground' if self.fg_bg_toggle.get() else 'background'
11441151
sample_element = self.theme_elements[self.highlight_target.get()][0]
1145-
self.text_highlight_sample.tag_config(sample_element, **{plane:new_color})
1152+
self.highlight_sample.tag_config(sample_element, **{plane:new_color})
11461153
theme = self.custom_theme.get()
11471154
theme_element = sample_element + '-' + plane
11481155
changes.add_option('highlight', theme, theme_element, new_color)
@@ -1210,41 +1217,25 @@ def on_fontlist_select(self, event):
12101217
"""Handle selecting a font from the list.
12111218
12121219
Event can result from either mouse click or Up or Down key.
1213-
Set font_name and example display to selection.
1214-
1215-
Attributes updated:
1216-
font_name: Set to name selected from fontlist.
1217-
1218-
Methods:
1219-
set_font_sample
1220+
Set font_name and example displays to selection.
12201221
"""
12211222
font = self.fontlist.get(
12221223
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
12231224
self.font_name.set(font.lower())
1224-
self.set_font_sample()
1225-
1226-
def set_font_sample(self, event=None):
1227-
"""Update the screen samples with the font settings from the dialog.
1228-
1229-
Attributes accessed:
1230-
font_name
1231-
font_bold
1232-
font_size
1225+
self.set_samples()
12331226

1234-
Attributes updated:
1235-
font_sample: Set to selected font name, size, and weight.
1236-
text_highlight_sample: Set to selected font name, size, and weight.
1227+
def set_samples(self, event=None):
1228+
"""Update update both screen samples with the font settings.
12371229
1238-
Called from:
1239-
handler for opt_menu_font_size and check_font_bold
1240-
on_fontlist_select
1241-
load_font_cfg
1230+
Called on font initialization and change events.
1231+
Accesses font_name, font_size, and font_bold Variables.
1232+
Updates font_sample and hightlight page highlight_sample.
12421233
"""
12431234
font_name = self.font_name.get()
12441235
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
12451236
new_font = (font_name, self.font_size.get(), font_weight)
1246-
self.font_sample.config(font=new_font)
1247-
self.text_highlight_sample.configure(font=new_font)
1237+
self.font_sample['font'] = new_font
1238+
self.highlight_sample['font'] = new_font
12481239

12491240
def set_highlight_target(self):
12501241
"""Set fg/bg toggle and color based on highlight tag target.
@@ -1289,15 +1280,15 @@ def set_color_sample(self):
12891280
theme_elements
12901281
highlight_target
12911282
fg_bg_toggle
1292-
text_highlight_sample
1283+
highlight_sample
12931284
12941285
Attributes updated:
12951286
frame_color_set
12961287
"""
12971288
# Set the color sample area.
12981289
tag = self.theme_elements[self.highlight_target.get()][0]
12991290
plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
1300-
color = self.text_highlight_sample.tag_cget(tag, plane)
1291+
color = self.highlight_sample.tag_cget(tag, plane)
13011292
self.frame_color_set.config(bg=color)
13021293

13031294
def paint_theme_sample(self):
@@ -1310,7 +1301,7 @@ def paint_theme_sample(self):
13101301
custom_theme
13111302
13121303
Attributes updated:
1313-
text_highlight_sample: Set the tag elements to the theme.
1304+
highlight_sample: Set the tag elements to the theme.
13141305
13151306
Methods:
13161307
set_color_sample
@@ -1337,7 +1328,7 @@ def paint_theme_sample(self):
13371328
colors['foreground'] = theme_dict[element + '-foreground']
13381329
if element + '-background' in theme_dict:
13391330
colors['background'] = theme_dict[element + '-background']
1340-
self.text_highlight_sample.tag_config(element, **colors)
1331+
self.highlight_sample.tag_config(element, **colors)
13411332
self.set_color_sample()
13421333

13431334
def help_source_selected(self, event):
@@ -1424,7 +1415,7 @@ def load_font_cfg(self):
14241415
font_bold: Set to current font weight.
14251416
14261417
Methods:
1427-
set_font_sample
1418+
set_samples
14281419
"""
14291420
# Set base editor font selection list.
14301421
fonts = list(tkFont.families(self))
@@ -1452,7 +1443,7 @@ def load_font_cfg(self):
14521443
# Set font weight.
14531444
self.font_bold.set(font_bold)
14541445
# Set font sample.
1455-
self.set_font_sample()
1446+
self.set_samples()
14561447

14571448
def load_tab_cfg(self):
14581449
"""Load current configuration settings for the tab options.

Lib/idlelib/idle_test/test_configdialog.py

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@
2828
highpage = changes['highlight']
2929
keyspage = changes['keys']
3030

31-
32-
class TestDialog(ConfigDialog):
33-
pass # Delete?
34-
35-
3631
def setUpModule():
3732
global root, dialog
3833
idleConf.userCfg = testcfg
3934
root = Tk()
4035
# root.withdraw() # Comment out, see issue 30870
41-
dialog = TestDialog(root, 'Test', _utest=True)
42-
36+
dialog = ConfigDialog(root, 'Test', _utest=True)
4337

4438
def tearDownModule():
4539
global root, dialog
@@ -52,12 +46,16 @@ def tearDownModule():
5246

5347

5448
class FontTabTest(unittest.TestCase):
49+
"Test that font widget enable users to make font changes."
50+
5551

5652
def setUp(self):
5753
changes.clear()
5854

59-
def test_font(self):
60-
# Set values guaranteed not to be defaults.
55+
def test_font_set(self):
56+
# Test that setting a font Variable results in 3 provisional
57+
# change entries. Use values sure to not be defaults.
58+
# Other font tests verify that user actions set Variables.
6159
default_font = idleConf.GetFont(root, 'main', 'EditorWindow')
6260
default_size = str(default_font[1])
6361
default_bold = default_font[2] == 'bold'
@@ -79,9 +77,30 @@ def test_font(self):
7977
'font-bold': str(not default_bold)}}
8078
self.assertEqual(mainpage, expected)
8179

82-
def test_set_sample(self):
83-
# Set_font_sample also sets highlight_sample.
84-
pass
80+
def test_set_samples_bold_toggle(self):
81+
# Set up.
82+
d = dialog
83+
d.font_sample, d.highlight_sample = {}, {} # Must undo this.
84+
d.font_name.set('test')
85+
d.font_size.set('5')
86+
d.font_bold.set(1)
87+
expected0 = {'font': ('test', '5', 'normal')}
88+
expected1 = {'font': ('test', '5', 'bold')}
89+
90+
# Test set_samples.
91+
d.set_samples()
92+
self.assertTrue(d.font_sample == d.highlight_sample == expected1)
93+
94+
# Test bold_toggle.
95+
d.bold_toggle.invoke()
96+
self.assertFalse(d.font_bold.get())
97+
self.assertTrue(d.font_sample == d.highlight_sample == expected0)
98+
d.bold_toggle.invoke()
99+
self.assertTrue(d.font_bold.get())
100+
self.assertTrue(d.font_sample == d.highlight_sample == expected1)
101+
102+
# Clean up.
103+
del d.font_sample, d.highlight_sample
85104

86105
def test_tabspace(self):
87106
dialog.space_num.set(6)
@@ -90,22 +109,22 @@ def test_tabspace(self):
90109

91110
class FontSelectTest(unittest.TestCase):
92111
# These two functions test that selecting a new font in the
93-
# list of fonts changes font_name and calls set_font_sample.
112+
# list of fonts changes font_name and calls set_samples.
94113
# The fontlist widget and on_fontlist_select event handler
95114
# are tested here together.
96115

97116
@classmethod
98117
def setUpClass(cls):
99118
if dialog.fontlist.size() < 2:
100119
cls.skipTest('need at least 2 fonts')
101-
dialog.set_font_sample = Func() # Mask instance method.
120+
dialog.set_samples = Func() # Mask instance method.
102121

103122
@classmethod
104123
def tearDownClass(cls):
105-
del dialog.set_font_sample # Unmask instance method.
124+
del dialog.set_samples # Unmask instance method.
106125

107126
def setUp(self):
108-
dialog.set_font_sample.called = 0
127+
dialog.set_samples.called = 0
109128
changes.clear()
110129

111130
def test_select_font_key(self):
@@ -124,7 +143,7 @@ def test_select_font_key(self):
124143
down_font = fontlist.get('active')
125144
self.assertNotEqual(down_font, font)
126145
self.assertIn(dialog.font_name.get(), down_font.lower())
127-
self.assertEqual(dialog.set_font_sample.called, 1)
146+
self.assertEqual(dialog.set_samples.called, 1)
128147

129148
# Test Up key.
130149
fontlist.focus_force()
@@ -135,7 +154,7 @@ def test_select_font_key(self):
135154
up_font = fontlist.get('active')
136155
self.assertEqual(up_font, font)
137156
self.assertIn(dialog.font_name.get(), up_font.lower())
138-
self.assertEqual(dialog.set_font_sample.called, 2)
157+
self.assertEqual(dialog.set_samples.called, 2)
139158

140159
def test_select_font_mouse(self):
141160
# Click on item should select that item.
@@ -157,7 +176,7 @@ def test_select_font_mouse(self):
157176
select_font = fontlist.get('anchor')
158177
self.assertEqual(select_font, font1)
159178
self.assertIn(dialog.font_name.get(), font1.lower())
160-
self.assertEqual(dialog.set_font_sample.called, 1)
179+
self.assertEqual(dialog.set_samples.called, 1)
161180

162181

163182
class HighlightTest(unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IDLE -- Add more configdialog font page tests.

0 commit comments

Comments
 (0)