Skip to content

Commit

Permalink
bpo-31206: IDLE: Factor HighPage class from ConfigDialog (python#3156)
Browse files Browse the repository at this point in the history
Patch 2 of 3, to avoid horrendous diff.  Create highlights page from new HighPage class instead of old ConfigDialog methods and change tests to match.
  • Loading branch information
csabella authored and GadgetSteve committed Sep 10, 2017
1 parent ec5b014 commit dfc12a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
20 changes: 9 additions & 11 deletions Lib/idlelib/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,20 @@ def __init__(self, parent, title='', _htest=False, _utest=False):
# self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
# self.bind('<Alt-a>', self.Apply) #apply changes, save
# self.bind('<F1>', self.Help) #context help
self.load_configs()
# Avoid callbacks during load_configs.
# Attach callbacks after loading config to avoid calling them.
tracers.attach()

if not _utest:
self.grab_set()
self.wm_deiconify()
self.wait_window()


def create_widgets(self):
"""Create and place widgets for tabbed dialog.
Widgets Bound to self:
note: Notebook
highpage: self.create_page_highlight
highpage: HighPage
fontpage: FontPage
keyspage: KeysPage
genpage: GenPage
Expand All @@ -102,7 +100,7 @@ def create_widgets(self):
activate_config_changes: Tell editors to reload.
"""
self.note = note = Notebook(self, width=450, height=450)
self.highpage = self.create_page_highlight()
self.highpage = HighPage(note)
self.fontpage = FontPage(note, self.highpage)
self.keyspage = KeysPage(note)
self.genpage = GenPage(note)
Expand Down Expand Up @@ -131,11 +129,10 @@ def load_configs(self):
"""
#self.load_font_cfg()
#self.load_tab_cfg()
self.load_theme_cfg()
# self.load_theme_cfg()
# self.load_key_cfg()
# self.load_general_cfg()
# note: extension page handled separately

def create_action_buttons(self):
"""Return frame of action buttons for dialog.
Expand Down Expand Up @@ -1477,7 +1474,8 @@ def create_page_highlight(self):
text.insert(END, texttag[0], texttag[1])
for element in self.theme_elements:
def tem(event, elem=element):
event.widget.winfo_toplevel().highlight_target.set(elem)
# event.widget.winfo_top_level().highlight_target.set(elem)
self.highlight_target.set(elem)
text.tag_bind(
self.theme_elements[element][0], '<ButtonPress-1>', tem)
text['state'] = DISABLED
Expand Down Expand Up @@ -1912,7 +1910,7 @@ def delete_custom(self):
if not tkMessageBox.askyesno(
'Delete Theme', delmsg % theme_name, parent=self):
return
cd.deactivate_current_config()
self.cd.deactivate_current_config()
# Remove theme from changes, config, and file.
changes.delete_section('highlight', theme_name)
# Reload user theme list.
Expand All @@ -1928,8 +1926,8 @@ def delete_custom(self):
self.builtin_name.set(idleConf.defaultCfg['main'].Get('Theme', 'name'))
# User can't back out of these changes, they must be applied now.
changes.save_all()
cd.save_all_changed_extensions()
cd.activate_config_changes()
self.cd.save_all_changed_extensions()
self.cd.activate_config_changes()
self.set_theme_type()


Expand Down
56 changes: 28 additions & 28 deletions Lib/idlelib/idle_test/test_configdialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test idlelib.configdialog.
Half the class creates dialog, half works with user customizations.
Coverage: 81%.
Coverage: 95%.
"""
from idlelib import configdialog
from test.support import requires
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_indent_scale(self):
self.assertEqual(mainpage, {'Indent': {'num-spaces': '16'}})


class HighlightTest(unittest.TestCase):
class HighPageTest(unittest.TestCase):
"""Test that highlight tab widgets enable users to make changes.
Test that widget actions set vars, that var changes add
Expand All @@ -235,21 +235,21 @@ class HighlightTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
d = dialog
dialog.note.select(d.highpage)
d.set_theme_type = Func()
d.paint_theme_sample = Func()
d.set_highlight_target = Func()
d.set_color_sample = Func()
page = cls.page = dialog.highpage
dialog.note.select(page)
page.set_theme_type = Func()
page.paint_theme_sample = Func()
page.set_highlight_target = Func()
page.set_color_sample = Func()

@classmethod
def tearDownClass(cls):
d = dialog
d = cls.page
del d.set_theme_type, d.paint_theme_sample
del d.set_highlight_target, d.set_color_sample

def setUp(self):
d = dialog
d = self.page
# The following is needed for test_load_key_cfg, _delete_custom_keys.
# This may indicate a defect in some test or function.
for section in idleConf.GetSectionList('user', 'highlight'):
Expand All @@ -262,7 +262,7 @@ def setUp(self):

def test_load_theme_cfg(self):
tracers.detach()
d = dialog
d = self.page
eq = self.assertEqual

# Use builtin theme with no user themes created.
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_load_theme_cfg(self):

def test_theme_source(self):
eq = self.assertEqual
d = dialog
d = self.page
# Test these separately.
d.var_changed_builtin_name = Func()
d.var_changed_custom_name = Func()
Expand All @@ -324,7 +324,7 @@ def test_theme_source(self):

def test_builtin_name(self):
eq = self.assertEqual
d = dialog
d = self.page
item_list = ['IDLE Classic', 'IDLE Dark', 'IDLE New']

# Not in old_themes, defaults name to first item.
Expand All @@ -351,7 +351,7 @@ def test_builtin_name(self):
eq(d.paint_theme_sample.called, 3)

def test_custom_name(self):
d = dialog
d = self.page

# If no selections, doesn't get added.
d.customlist.SetMenu([], '- no custom themes -')
Expand All @@ -365,7 +365,7 @@ def test_custom_name(self):
self.assertEqual(d.paint_theme_sample.called, 1)

def test_color(self):
d = dialog
d = self.page
d.on_new_color_set = Func()
# self.color is only set in get_color through ColorChooser.
d.color.set('green')
Expand All @@ -375,7 +375,7 @@ def test_color(self):
def test_highlight_target_list_mouse(self):
# Set highlight_target through targetlist.
eq = self.assertEqual
d = dialog
d = self.page

d.targetlist.SetMenu(['a', 'b', 'c'], 'c')
eq(d.highlight_target.get(), 'c')
Expand All @@ -384,7 +384,7 @@ def test_highlight_target_list_mouse(self):
def test_highlight_target_text_mouse(self):
# Set highlight_target through clicking highlight_sample.
eq = self.assertEqual
d = dialog
d = self.page

elem = {}
count = 0
Expand Down Expand Up @@ -420,7 +420,7 @@ def click_it(start):

def test_set_theme_type(self):
eq = self.assertEqual
d = dialog
d = self.page
del d.set_theme_type

# Builtin theme selected.
Expand All @@ -441,7 +441,7 @@ def test_set_theme_type(self):

def test_get_color(self):
eq = self.assertEqual
d = dialog
d = self.page
orig_chooser = configdialog.tkColorChooser.askcolor
chooser = configdialog.tkColorChooser.askcolor = Func()
gntn = d.get_new_theme_name = Func()
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_get_color(self):
configdialog.tkColorChooser.askcolor = orig_chooser

def test_on_new_color_set(self):
d = dialog
d = self.page
color = '#3f7cae'
d.custom_name.set('Python')
d.highlight_target.set('Selected Text')
Expand All @@ -502,15 +502,15 @@ def test_on_new_color_set(self):
def test_get_new_theme_name(self):
orig_sectionname = configdialog.SectionName
sn = configdialog.SectionName = Func(return_self=True)
d = dialog
d = self.page

sn.result = 'New Theme'
self.assertEqual(d.get_new_theme_name(''), 'New Theme')

configdialog.SectionName = orig_sectionname

def test_save_as_new_theme(self):
d = dialog
d = self.page
gntn = d.get_new_theme_name = Func()
d.theme_source.set(True)

Expand All @@ -530,7 +530,7 @@ def test_save_as_new_theme(self):

def test_create_new_and_save_new(self):
eq = self.assertEqual
d = dialog
d = self.page

# Use default as previously active theme.
d.theme_source.set(True)
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_create_new_and_save_new(self):

def test_set_highlight_target(self):
eq = self.assertEqual
d = dialog
d = self.page
del d.set_highlight_target

# Target is cursor.
Expand All @@ -582,7 +582,7 @@ def test_set_highlight_target(self):
d.set_highlight_target = Func()

def test_set_color_sample_binding(self):
d = dialog
d = self.page
scs = d.set_color_sample

d.fg_on.invoke()
Expand All @@ -592,7 +592,7 @@ def test_set_color_sample_binding(self):
self.assertEqual(scs.called, 2)

def test_set_color_sample(self):
d = dialog
d = self.page
del d.set_color_sample
d.highlight_target.set('Selected Text')
d.fg_bg_toggle.set(True)
Expand All @@ -603,7 +603,7 @@ def test_set_color_sample(self):

def test_paint_theme_sample(self):
eq = self.assertEqual
d = dialog
d = self.page
del d.paint_theme_sample
hs_tag = d.highlight_sample.tag_cget
gh = idleConf.GetHighlight
Expand Down Expand Up @@ -640,7 +640,7 @@ def test_paint_theme_sample(self):

def test_delete_custom(self):
eq = self.assertEqual
d = dialog
d = self.page
d.button_delete_custom['state'] = NORMAL
yesno = configdialog.tkMessageBox.askyesno = Func()
dialog.deactivate_current_config = Func()
Expand Down

0 comments on commit dfc12a3

Please sign in to comment.