Commit d0969d69 authored by Terry Jan Reedy's avatar Terry Jan Reedy Committed by GitHub

bpo-30981: IDLE -- Add more configdialog font page tests. (#2794)

parent a54a8f18
...@@ -154,9 +154,9 @@ class ConfigDialog(Toplevel): ...@@ -154,9 +154,9 @@ class ConfigDialog(Toplevel):
"""Return frame of widgets for Font/Tabs tab. """Return frame of widgets for Font/Tabs tab.
Tk Variables: Tk Variables:
font_name: Font face.
font_size: Font size. font_size: Font size.
font_bold: Select font bold or not. font_bold: Select font bold or not.
font_name: Font face.
Note: these 3 share var_changed_font callback. Note: these 3 share var_changed_font callback.
space_num: Indentation width. space_num: Indentation width.
...@@ -167,8 +167,7 @@ class ConfigDialog(Toplevel): ...@@ -167,8 +167,7 @@ class ConfigDialog(Toplevel):
load_font_cfg: Set vars and fontlist. load_font_cfg: Set vars and fontlist.
on_fontlist_select: Bound to fontlist button release on_fontlist_select: Bound to fontlist button release
or key release. or key release.
set_font_sample: Command for opt_menu_font_size and set_samples: Notify both samples of any font change.
check_font_bold.
load_tab_cfg: Get current. load_tab_cfg: Get current.
Widget Structure: (*) widgets bound to self Widget Structure: (*) widgets bound to self
...@@ -181,7 +180,7 @@ class ConfigDialog(Toplevel): ...@@ -181,7 +180,7 @@ class ConfigDialog(Toplevel):
frame_font_param: Frame frame_font_param: Frame
font_size_title: Label font_size_title: Label
(*)opt_menu_font_size: DynOptionMenu - font_size (*)opt_menu_font_size: DynOptionMenu - font_size
check_font_bold: Checkbutton - font_bold bold_toggle: Checkbutton - font_bold
frame_font_sample: Frame frame_font_sample: Frame
(*)font_sample: Label (*)font_sample: Label
frame_indent: LabelFrame frame_indent: LabelFrame
...@@ -190,9 +189,9 @@ class ConfigDialog(Toplevel): ...@@ -190,9 +189,9 @@ class ConfigDialog(Toplevel):
(*)scale_indent_size: Scale - space_num (*)scale_indent_size: Scale - space_num
""" """
parent = self.parent parent = self.parent
self.font_name = StringVar(parent)
self.font_size = StringVar(parent) self.font_size = StringVar(parent)
self.font_bold = BooleanVar(parent) self.font_bold = BooleanVar(parent)
self.font_name = StringVar(parent)
self.space_num = IntVar(parent) self.space_num = IntVar(parent)
self.edit_font = tkFont.Font(parent, ('courier', 10, 'normal')) self.edit_font = tkFont.Font(parent, ('courier', 10, 'normal'))
...@@ -218,10 +217,10 @@ class ConfigDialog(Toplevel): ...@@ -218,10 +217,10 @@ class ConfigDialog(Toplevel):
self.fontlist.config(yscrollcommand=scroll_font.set) self.fontlist.config(yscrollcommand=scroll_font.set)
font_size_title = Label(frame_font_param, text='Size :') font_size_title = Label(frame_font_param, text='Size :')
self.opt_menu_font_size = DynOptionMenu( self.opt_menu_font_size = DynOptionMenu(
frame_font_param, self.font_size, None, command=self.set_font_sample) frame_font_param, self.font_size, None, command=self.set_samples)
check_font_bold = Checkbutton( bold_toggle = Checkbutton(
frame_font_param, variable=self.font_bold, onvalue=1, frame_font_param, variable=self.font_bold, onvalue=1,
offvalue=0, text='Bold', command=self.set_font_sample) offvalue=0, text='Bold', command=self.set_samples)
frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1) frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)
self.font_sample = Label( self.font_sample = Label(
frame_font_sample, justify=LEFT, font=self.edit_font, frame_font_sample, justify=LEFT, font=self.edit_font,
...@@ -247,7 +246,7 @@ class ConfigDialog(Toplevel): ...@@ -247,7 +246,7 @@ class ConfigDialog(Toplevel):
scroll_font.pack(side=LEFT, fill=Y) scroll_font.pack(side=LEFT, fill=Y)
font_size_title.pack(side=LEFT, anchor=W) font_size_title.pack(side=LEFT, anchor=W)
self.opt_menu_font_size.pack(side=LEFT, anchor=W) self.opt_menu_font_size.pack(side=LEFT, anchor=W)
check_font_bold.pack(side=LEFT, anchor=W, padx=20) bold_toggle.pack(side=LEFT, anchor=W, padx=20)
frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
self.font_sample.pack(expand=TRUE, fill=BOTH) self.font_sample.pack(expand=TRUE, fill=BOTH)
# frame_indent # frame_indent
...@@ -292,7 +291,7 @@ class ConfigDialog(Toplevel): ...@@ -292,7 +291,7 @@ class ConfigDialog(Toplevel):
Widget Structure: (*) widgets bound to self Widget Structure: (*) widgets bound to self
frame frame
frame_custom: LabelFrame frame_custom: LabelFrame
(*)text_highlight_sample: Text (*)highlight_sample: Text
(*)frame_color_set: Frame (*)frame_color_set: Frame
button_set_color: Button button_set_color: Button
(*)opt_menu_highlight_target: DynOptionMenu - highlight_target (*)opt_menu_highlight_target: DynOptionMenu - highlight_target
...@@ -342,11 +341,11 @@ class ConfigDialog(Toplevel): ...@@ -342,11 +341,11 @@ class ConfigDialog(Toplevel):
frame_theme = LabelFrame(frame, borderwidth=2, relief=GROOVE, frame_theme = LabelFrame(frame, borderwidth=2, relief=GROOVE,
text=' Highlighting Theme ') text=' Highlighting Theme ')
#frame_custom #frame_custom
self.text_highlight_sample=Text( self.highlight_sample=Text(
frame_custom, relief=SOLID, borderwidth=1, frame_custom, relief=SOLID, borderwidth=1,
font=('courier', 12, ''), cursor='hand2', width=21, height=11, font=('courier', 12, ''), cursor='hand2', width=21, height=11,
takefocus=FALSE, highlightthickness=0, wrap=NONE) takefocus=FALSE, highlightthickness=0, wrap=NONE)
text=self.text_highlight_sample text=self.highlight_sample
text.bind('<Double-Button-1>', lambda e: 'break') text.bind('<Double-Button-1>', lambda e: 'break')
text.bind('<B1-Motion>', lambda e: 'break') text.bind('<B1-Motion>', lambda e: 'break')
text_and_tags=( text_and_tags=(
...@@ -416,7 +415,7 @@ class ConfigDialog(Toplevel): ...@@ -416,7 +415,7 @@ class ConfigDialog(Toplevel):
#frame_custom #frame_custom
self.frame_color_set.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X) self.frame_color_set.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X)
frame_fg_bg_toggle.pack(side=TOP, padx=5, pady=0) frame_fg_bg_toggle.pack(side=TOP, padx=5, pady=0)
self.text_highlight_sample.pack( self.highlight_sample.pack(
side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
button_set_color.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4) button_set_color.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4)
self.opt_menu_highlight_target.pack( self.opt_menu_highlight_target.pack(
...@@ -1142,7 +1141,7 @@ class ConfigDialog(Toplevel): ...@@ -1142,7 +1141,7 @@ class ConfigDialog(Toplevel):
self.frame_color_set.config(bg=new_color) # Set sample. self.frame_color_set.config(bg=new_color) # Set sample.
plane ='foreground' if self.fg_bg_toggle.get() else 'background' plane ='foreground' if self.fg_bg_toggle.get() else 'background'
sample_element = self.theme_elements[self.highlight_target.get()][0] sample_element = self.theme_elements[self.highlight_target.get()][0]
self.text_highlight_sample.tag_config(sample_element, **{plane:new_color}) self.highlight_sample.tag_config(sample_element, **{plane:new_color})
theme = self.custom_theme.get() theme = self.custom_theme.get()
theme_element = sample_element + '-' + plane theme_element = sample_element + '-' + plane
changes.add_option('highlight', theme, theme_element, new_color) changes.add_option('highlight', theme, theme_element, new_color)
...@@ -1210,41 +1209,25 @@ class ConfigDialog(Toplevel): ...@@ -1210,41 +1209,25 @@ class ConfigDialog(Toplevel):
"""Handle selecting a font from the list. """Handle selecting a font from the list.
Event can result from either mouse click or Up or Down key. Event can result from either mouse click or Up or Down key.
Set font_name and example display to selection. Set font_name and example displays to selection.
Attributes updated:
font_name: Set to name selected from fontlist.
Methods:
set_font_sample
""" """
font = self.fontlist.get( font = self.fontlist.get(
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR) ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
self.font_name.set(font.lower()) self.font_name.set(font.lower())
self.set_font_sample() self.set_samples()
def set_font_sample(self, event=None):
"""Update the screen samples with the font settings from the dialog.
Attributes accessed: def set_samples(self, event=None):
font_name """Update update both screen samples with the font settings.
font_bold
font_size
Attributes updated: Called on font initialization and change events.
font_sample: Set to selected font name, size, and weight. Accesses font_name, font_size, and font_bold Variables.
text_highlight_sample: Set to selected font name, size, and weight. Updates font_sample and hightlight page highlight_sample.
Called from:
handler for opt_menu_font_size and check_font_bold
on_fontlist_select
load_font_cfg
""" """
font_name = self.font_name.get() font_name = self.font_name.get()
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
new_font = (font_name, self.font_size.get(), font_weight) new_font = (font_name, self.font_size.get(), font_weight)
self.font_sample.config(font=new_font) self.font_sample['font'] = new_font
self.text_highlight_sample.configure(font=new_font) self.highlight_sample['font'] = new_font
def set_highlight_target(self): def set_highlight_target(self):
"""Set fg/bg toggle and color based on highlight tag target. """Set fg/bg toggle and color based on highlight tag target.
...@@ -1289,7 +1272,7 @@ class ConfigDialog(Toplevel): ...@@ -1289,7 +1272,7 @@ class ConfigDialog(Toplevel):
theme_elements theme_elements
highlight_target highlight_target
fg_bg_toggle fg_bg_toggle
text_highlight_sample highlight_sample
Attributes updated: Attributes updated:
frame_color_set frame_color_set
...@@ -1297,7 +1280,7 @@ class ConfigDialog(Toplevel): ...@@ -1297,7 +1280,7 @@ class ConfigDialog(Toplevel):
# Set the color sample area. # Set the color sample area.
tag = self.theme_elements[self.highlight_target.get()][0] tag = self.theme_elements[self.highlight_target.get()][0]
plane = 'foreground' if self.fg_bg_toggle.get() else 'background' plane = 'foreground' if self.fg_bg_toggle.get() else 'background'
color = self.text_highlight_sample.tag_cget(tag, plane) color = self.highlight_sample.tag_cget(tag, plane)
self.frame_color_set.config(bg=color) self.frame_color_set.config(bg=color)
def paint_theme_sample(self): def paint_theme_sample(self):
...@@ -1310,7 +1293,7 @@ class ConfigDialog(Toplevel): ...@@ -1310,7 +1293,7 @@ class ConfigDialog(Toplevel):
custom_theme custom_theme
Attributes updated: Attributes updated:
text_highlight_sample: Set the tag elements to the theme. highlight_sample: Set the tag elements to the theme.
Methods: Methods:
set_color_sample set_color_sample
...@@ -1337,7 +1320,7 @@ class ConfigDialog(Toplevel): ...@@ -1337,7 +1320,7 @@ class ConfigDialog(Toplevel):
colors['foreground'] = theme_dict[element + '-foreground'] colors['foreground'] = theme_dict[element + '-foreground']
if element + '-background' in theme_dict: if element + '-background' in theme_dict:
colors['background'] = theme_dict[element + '-background'] colors['background'] = theme_dict[element + '-background']
self.text_highlight_sample.tag_config(element, **colors) self.highlight_sample.tag_config(element, **colors)
self.set_color_sample() self.set_color_sample()
def help_source_selected(self, event): def help_source_selected(self, event):
...@@ -1424,7 +1407,7 @@ class ConfigDialog(Toplevel): ...@@ -1424,7 +1407,7 @@ class ConfigDialog(Toplevel):
font_bold: Set to current font weight. font_bold: Set to current font weight.
Methods: Methods:
set_font_sample set_samples
""" """
# Set base editor font selection list. # Set base editor font selection list.
fonts = list(tkFont.families(self)) fonts = list(tkFont.families(self))
...@@ -1452,7 +1435,7 @@ class ConfigDialog(Toplevel): ...@@ -1452,7 +1435,7 @@ class ConfigDialog(Toplevel):
# Set font weight. # Set font weight.
self.font_bold.set(font_bold) self.font_bold.set(font_bold)
# Set font sample. # Set font sample.
self.set_font_sample() self.set_samples()
def load_tab_cfg(self): def load_tab_cfg(self):
"""Load current configuration settings for the tab options. """Load current configuration settings for the tab options.
......
...@@ -28,18 +28,12 @@ mainpage = changes['main'] ...@@ -28,18 +28,12 @@ mainpage = changes['main']
highpage = changes['highlight'] highpage = changes['highlight']
keyspage = changes['keys'] keyspage = changes['keys']
class TestDialog(ConfigDialog):
pass # Delete?
def setUpModule(): def setUpModule():
global root, dialog global root, dialog
idleConf.userCfg = testcfg idleConf.userCfg = testcfg
root = Tk() root = Tk()
# root.withdraw() # Comment out, see issue 30870 # root.withdraw() # Comment out, see issue 30870
dialog = TestDialog(root, 'Test', _utest=True) dialog = ConfigDialog(root, 'Test', _utest=True)
def tearDownModule(): def tearDownModule():
global root, dialog global root, dialog
...@@ -56,7 +50,7 @@ class FontTabTest(unittest.TestCase): ...@@ -56,7 +50,7 @@ class FontTabTest(unittest.TestCase):
def setUp(self): def setUp(self):
changes.clear() changes.clear()
def test_font(self): def test_font_set(self):
# Set values guaranteed not to be defaults. # Set values guaranteed not to be defaults.
default_font = idleConf.GetFont(root, 'main', 'EditorWindow') default_font = idleConf.GetFont(root, 'main', 'EditorWindow')
default_size = str(default_font[1]) default_size = str(default_font[1])
...@@ -79,9 +73,22 @@ class FontTabTest(unittest.TestCase): ...@@ -79,9 +73,22 @@ class FontTabTest(unittest.TestCase):
'font-bold': str(not default_bold)}} 'font-bold': str(not default_bold)}}
self.assertEqual(mainpage, expected) self.assertEqual(mainpage, expected)
def test_set_sample(self): def test_bold_toggle(self):
# Set_font_sample also sets highlight_sample. d = dialog
pass d.set_samples = Func()
d.bold_toggle.toggle()
self.assertEqual(d.set_samples.called, 1)
def test_set_samples(self):
d = dialog
d.font_sample, d.highlight_sample = {}, {}
d.font_name.set('test')
d.font_size.set('5')
d.font_bold.set(1)
d.set_samples()
expected = {'font': ('test', '5', 'bold')}
self.assertTrue(d.font_sample == d.highlight_sample == expected)
del d.font_sample, d.highlight_sample
def test_tabspace(self): def test_tabspace(self):
dialog.space_num.set(6) dialog.space_num.set(6)
...@@ -90,7 +97,7 @@ class FontTabTest(unittest.TestCase): ...@@ -90,7 +97,7 @@ class FontTabTest(unittest.TestCase):
class FontSelectTest(unittest.TestCase): class FontSelectTest(unittest.TestCase):
# These two functions test that selecting a new font in the # These two functions test that selecting a new font in the
# list of fonts changes font_name and calls set_font_sample. # list of fonts changes font_name and calls set_samples.
# The fontlist widget and on_fontlist_select event handler # The fontlist widget and on_fontlist_select event handler
# are tested here together. # are tested here together.
...@@ -98,14 +105,14 @@ class FontSelectTest(unittest.TestCase): ...@@ -98,14 +105,14 @@ class FontSelectTest(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
if dialog.fontlist.size() < 2: if dialog.fontlist.size() < 2:
cls.skipTest('need at least 2 fonts') cls.skipTest('need at least 2 fonts')
dialog.set_font_sample = Func() # Mask instance method. dialog.set_samples = Func() # Mask instance method.
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
del dialog.set_font_sample # Unmask instance method. del dialog.set_samples # Unmask instance method.
def setUp(self): def setUp(self):
dialog.set_font_sample.called = 0 dialog.set_samples.called = 0
changes.clear() changes.clear()
def test_select_font_key(self): def test_select_font_key(self):
...@@ -124,7 +131,7 @@ class FontSelectTest(unittest.TestCase): ...@@ -124,7 +131,7 @@ class FontSelectTest(unittest.TestCase):
down_font = fontlist.get('active') down_font = fontlist.get('active')
self.assertNotEqual(down_font, font) self.assertNotEqual(down_font, font)
self.assertIn(dialog.font_name.get(), down_font.lower()) self.assertIn(dialog.font_name.get(), down_font.lower())
self.assertEqual(dialog.set_font_sample.called, 1) self.assertEqual(dialog.set_samples.called, 1)
# Test Up key. # Test Up key.
fontlist.focus_force() fontlist.focus_force()
...@@ -135,7 +142,7 @@ class FontSelectTest(unittest.TestCase): ...@@ -135,7 +142,7 @@ class FontSelectTest(unittest.TestCase):
up_font = fontlist.get('active') up_font = fontlist.get('active')
self.assertEqual(up_font, font) self.assertEqual(up_font, font)
self.assertIn(dialog.font_name.get(), up_font.lower()) self.assertIn(dialog.font_name.get(), up_font.lower())
self.assertEqual(dialog.set_font_sample.called, 2) self.assertEqual(dialog.set_samples.called, 2)
def test_select_font_mouse(self): def test_select_font_mouse(self):
# Click on item should select that item. # Click on item should select that item.
...@@ -157,7 +164,7 @@ class FontSelectTest(unittest.TestCase): ...@@ -157,7 +164,7 @@ class FontSelectTest(unittest.TestCase):
select_font = fontlist.get('anchor') select_font = fontlist.get('anchor')
self.assertEqual(select_font, font1) self.assertEqual(select_font, font1)
self.assertIn(dialog.font_name.get(), font1.lower()) self.assertIn(dialog.font_name.get(), font1.lower())
self.assertEqual(dialog.set_font_sample.called, 1) self.assertEqual(dialog.set_samples.called, 1)
class HighlightTest(unittest.TestCase): class HighlightTest(unittest.TestCase):
......
IDLE -- Add more configdialog font page tests.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment