bpo-31004: IDLE: Factor out FontPage class from configdialog (step 1) (#2905)
The slightly modified tests continue to pass. The General test broken by the switch to Notebook is fixed. Patch mostly by Cheryl Sabella.
This commit is contained in:
parent
c3aa47f655
commit
9397e2a87e
|
@ -69,7 +69,7 @@ class ConfigDialog(Toplevel):
|
||||||
self.resizable(height=FALSE, width=FALSE)
|
self.resizable(height=FALSE, width=FALSE)
|
||||||
self.transient(parent)
|
self.transient(parent)
|
||||||
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
self.protocol("WM_DELETE_WINDOW", self.cancel)
|
||||||
self.fontlist.focus_set()
|
self.fontpage.fontlist.focus_set()
|
||||||
# XXX Decide whether to keep or delete these key bindings.
|
# XXX Decide whether to keep or delete these key bindings.
|
||||||
# Key bindings for this dialog.
|
# Key bindings for this dialog.
|
||||||
# self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
|
# self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
|
||||||
|
@ -102,16 +102,16 @@ class ConfigDialog(Toplevel):
|
||||||
activate_config_changes: Tell editors to reload.
|
activate_config_changes: Tell editors to reload.
|
||||||
"""
|
"""
|
||||||
self.note = note = Notebook(self, width=450, height=450)
|
self.note = note = Notebook(self, width=450, height=450)
|
||||||
fontpage = self.create_page_font_tab()
|
self.highpage = self.create_page_highlight()
|
||||||
highpage = self.create_page_highlight()
|
self.fontpage = FontPage(note, self.highpage)
|
||||||
keyspage = self.create_page_keys()
|
self.keyspage = self.create_page_keys()
|
||||||
genpage = self.create_page_general()
|
self.genpage = self.create_page_general()
|
||||||
extpage = self.create_page_extensions()
|
self.extpage = self.create_page_extensions()
|
||||||
note.add(fontpage, text='Fonts/Tabs')
|
note.add(self.fontpage, text='Fonts/Tabs')
|
||||||
note.add(highpage, text='Highlights')
|
note.add(self.highpage, text='Highlights')
|
||||||
note.add(keyspage, text=' Keys ')
|
note.add(self.keyspage, text=' Keys ')
|
||||||
note.add(genpage, text=' General ')
|
note.add(self.genpage, text=' General ')
|
||||||
note.add(extpage, text='Extensions')
|
note.add(self.extpage, text='Extensions')
|
||||||
note.enable_traversal()
|
note.enable_traversal()
|
||||||
note.pack(side=TOP, expand=TRUE, fill=BOTH)
|
note.pack(side=TOP, expand=TRUE, fill=BOTH)
|
||||||
self.create_action_buttons().pack(side=BOTTOM)
|
self.create_action_buttons().pack(side=BOTTOM)
|
||||||
|
@ -129,8 +129,8 @@ class ConfigDialog(Toplevel):
|
||||||
load_key_cfg
|
load_key_cfg
|
||||||
load_general_cfg
|
load_general_cfg
|
||||||
"""
|
"""
|
||||||
self.load_font_cfg()
|
#self.load_font_cfg()
|
||||||
self.load_tab_cfg()
|
#self.load_tab_cfg()
|
||||||
self.load_theme_cfg()
|
self.load_theme_cfg()
|
||||||
self.load_key_cfg()
|
self.load_key_cfg()
|
||||||
self.load_general_cfg()
|
self.load_general_cfg()
|
||||||
|
@ -219,203 +219,6 @@ class ConfigDialog(Toplevel):
|
||||||
text=help_common+help_pages.get(page, ''))
|
text=help_common+help_pages.get(page, ''))
|
||||||
|
|
||||||
|
|
||||||
def create_page_font_tab(self):
|
|
||||||
"""Return frame of widgets for Font/Tabs tab.
|
|
||||||
|
|
||||||
Fonts: Enable users to provisionally change font face, size, or
|
|
||||||
boldness and to see the consequence of proposed choices. Each
|
|
||||||
action set 3 options in changes structuree and changes the
|
|
||||||
corresponding aspect of the font sample on this page and
|
|
||||||
highlight sample on highlight page.
|
|
||||||
|
|
||||||
Funtion load_font_cfg initializes font vars and widgets from
|
|
||||||
idleConf entries and tk.
|
|
||||||
|
|
||||||
Fontlist: mouse button 1 click or up or down key invoke
|
|
||||||
on_fontlist_select(), which sets var font_name.
|
|
||||||
|
|
||||||
Sizelist: clicking the menubutton opens the dropdown menu. A
|
|
||||||
mouse button 1 click or return key sets var font_size.
|
|
||||||
|
|
||||||
Bold_toggle: clicking the box toggles var font_bold.
|
|
||||||
|
|
||||||
Changing any of the font vars invokes var_changed_font, which
|
|
||||||
adds all 3 font options to changes and calls set_samples.
|
|
||||||
Set_samples applies a new font constructed from the font vars to
|
|
||||||
font_sample and to highlight_sample on the hightlight page.
|
|
||||||
|
|
||||||
Tabs: Enable users to change spaces entered for indent tabs.
|
|
||||||
Changing indent_scale value with the mouse sets Var space_num,
|
|
||||||
which invokes the default callback to add an entry to
|
|
||||||
changes. Load_tab_cfg initializes space_num to default.
|
|
||||||
|
|
||||||
Widget Structure: (*) widgets bound to self
|
|
||||||
frame (of tab_pages)
|
|
||||||
frame_font: LabelFrame
|
|
||||||
frame_font_name: Frame
|
|
||||||
font_name_title: Label
|
|
||||||
(*)fontlist: ListBox - font_name
|
|
||||||
scroll_font: Scrollbar
|
|
||||||
frame_font_param: Frame
|
|
||||||
font_size_title: Label
|
|
||||||
(*)sizelist: DynOptionMenu - font_size
|
|
||||||
(*)bold_toggle: Checkbutton - font_bold
|
|
||||||
frame_font_sample: Frame
|
|
||||||
(*)font_sample: Label
|
|
||||||
frame_indent: LabelFrame
|
|
||||||
indent_title: Label
|
|
||||||
(*)indent_scale: Scale - space_num
|
|
||||||
"""
|
|
||||||
parent = self.parent
|
|
||||||
self.font_name = tracers.add(StringVar(parent), self.var_changed_font)
|
|
||||||
self.font_size = tracers.add(StringVar(parent), self.var_changed_font)
|
|
||||||
self.font_bold = tracers.add(BooleanVar(parent), self.var_changed_font)
|
|
||||||
self.space_num = tracers.add(IntVar(parent), ('main', 'Indent', 'num-spaces'))
|
|
||||||
|
|
||||||
# Create widgets:
|
|
||||||
# body and body section frames.
|
|
||||||
frame = Frame(self.note)
|
|
||||||
frame_font = LabelFrame(
|
|
||||||
frame, borderwidth=2, relief=GROOVE, text=' Base Editor Font ')
|
|
||||||
frame_indent = LabelFrame(
|
|
||||||
frame, borderwidth=2, relief=GROOVE, text=' Indentation Width ')
|
|
||||||
# frame_font.
|
|
||||||
frame_font_name = Frame(frame_font)
|
|
||||||
frame_font_param = Frame(frame_font)
|
|
||||||
font_name_title = Label(
|
|
||||||
frame_font_name, justify=LEFT, text='Font Face :')
|
|
||||||
self.fontlist = Listbox(frame_font_name, height=5,
|
|
||||||
takefocus=True, exportselection=FALSE)
|
|
||||||
self.fontlist.bind('<ButtonRelease-1>', self.on_fontlist_select)
|
|
||||||
self.fontlist.bind('<KeyRelease-Up>', self.on_fontlist_select)
|
|
||||||
self.fontlist.bind('<KeyRelease-Down>', self.on_fontlist_select)
|
|
||||||
scroll_font = Scrollbar(frame_font_name)
|
|
||||||
scroll_font.config(command=self.fontlist.yview)
|
|
||||||
self.fontlist.config(yscrollcommand=scroll_font.set)
|
|
||||||
font_size_title = Label(frame_font_param, text='Size :')
|
|
||||||
self.sizelist = DynOptionMenu(frame_font_param, self.font_size, None)
|
|
||||||
self.bold_toggle = Checkbutton(
|
|
||||||
frame_font_param, variable=self.font_bold,
|
|
||||||
onvalue=1, offvalue=0, text='Bold')
|
|
||||||
frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)
|
|
||||||
temp_font = tkFont.Font(parent, ('courier', 10, 'normal'))
|
|
||||||
self.font_sample = Label(
|
|
||||||
frame_font_sample, justify=LEFT, font=temp_font,
|
|
||||||
text='AaBbCcDdEe\nFfGgHhIiJj\n1234567890\n#:+=(){}[]')
|
|
||||||
# frame_indent.
|
|
||||||
indent_title = Label(
|
|
||||||
frame_indent, justify=LEFT,
|
|
||||||
text='Python Standard: 4 Spaces!')
|
|
||||||
self.indent_scale = Scale(
|
|
||||||
frame_indent, variable=self.space_num,
|
|
||||||
orient='horizontal', tickinterval=2, from_=2, to=16)
|
|
||||||
|
|
||||||
# Pack widgets:
|
|
||||||
# body.
|
|
||||||
frame_font.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
||||||
frame_indent.pack(side=LEFT, padx=5, pady=5, fill=Y)
|
|
||||||
# frame_font.
|
|
||||||
frame_font_name.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
||||||
frame_font_param.pack(side=TOP, padx=5, pady=5, fill=X)
|
|
||||||
font_name_title.pack(side=TOP, anchor=W)
|
|
||||||
self.fontlist.pack(side=LEFT, expand=TRUE, fill=X)
|
|
||||||
scroll_font.pack(side=LEFT, fill=Y)
|
|
||||||
font_size_title.pack(side=LEFT, anchor=W)
|
|
||||||
self.sizelist.pack(side=LEFT, anchor=W)
|
|
||||||
self.bold_toggle.pack(side=LEFT, anchor=W, padx=20)
|
|
||||||
frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
|
||||||
self.font_sample.pack(expand=TRUE, fill=BOTH)
|
|
||||||
# frame_indent.
|
|
||||||
frame_indent.pack(side=TOP, fill=X)
|
|
||||||
indent_title.pack(side=TOP, anchor=W, padx=5)
|
|
||||||
self.indent_scale.pack(side=TOP, padx=5, fill=X)
|
|
||||||
|
|
||||||
return frame
|
|
||||||
|
|
||||||
def load_font_cfg(self):
|
|
||||||
"""Load current configuration settings for the font options.
|
|
||||||
|
|
||||||
Retrieve current font with idleConf.GetFont and font families
|
|
||||||
from tk. Setup fontlist and set font_name. Setup sizelist,
|
|
||||||
which sets font_size. Set font_bold. Setting font variables
|
|
||||||
calls set_samples (thrice).
|
|
||||||
"""
|
|
||||||
configured_font = idleConf.GetFont(self, 'main', 'EditorWindow')
|
|
||||||
font_name = configured_font[0].lower()
|
|
||||||
font_size = configured_font[1]
|
|
||||||
font_bold = configured_font[2]=='bold'
|
|
||||||
|
|
||||||
# Set editor font selection list and font_name.
|
|
||||||
fonts = list(tkFont.families(self))
|
|
||||||
fonts.sort()
|
|
||||||
for font in fonts:
|
|
||||||
self.fontlist.insert(END, font)
|
|
||||||
self.font_name.set(font_name)
|
|
||||||
lc_fonts = [s.lower() for s in fonts]
|
|
||||||
try:
|
|
||||||
current_font_index = lc_fonts.index(font_name)
|
|
||||||
self.fontlist.see(current_font_index)
|
|
||||||
self.fontlist.select_set(current_font_index)
|
|
||||||
self.fontlist.select_anchor(current_font_index)
|
|
||||||
self.fontlist.activate(current_font_index)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
# Set font size dropdown.
|
|
||||||
self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14',
|
|
||||||
'16', '18', '20', '22', '25', '29', '34', '40'),
|
|
||||||
font_size)
|
|
||||||
# Set font weight.
|
|
||||||
self.font_bold.set(font_bold)
|
|
||||||
|
|
||||||
def var_changed_font(self, *params):
|
|
||||||
"""Store changes to font attributes.
|
|
||||||
|
|
||||||
When one font attribute changes, save them all, as they are
|
|
||||||
not independent from each other. In particular, when we are
|
|
||||||
overriding the default font, we need to write out everything.
|
|
||||||
"""
|
|
||||||
value = self.font_name.get()
|
|
||||||
changes.add_option('main', 'EditorWindow', 'font', value)
|
|
||||||
value = self.font_size.get()
|
|
||||||
changes.add_option('main', 'EditorWindow', 'font-size', value)
|
|
||||||
value = self.font_bold.get()
|
|
||||||
changes.add_option('main', 'EditorWindow', 'font-bold', value)
|
|
||||||
self.set_samples()
|
|
||||||
|
|
||||||
def on_fontlist_select(self, event):
|
|
||||||
"""Handle selecting a font from the list.
|
|
||||||
|
|
||||||
Event can result from either mouse click or Up or Down key.
|
|
||||||
Set font_name and example displays to selection.
|
|
||||||
"""
|
|
||||||
font = self.fontlist.get(
|
|
||||||
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
|
|
||||||
self.font_name.set(font.lower())
|
|
||||||
|
|
||||||
def set_samples(self, event=None):
|
|
||||||
"""Update update both screen samples with the font settings.
|
|
||||||
|
|
||||||
Called on font initialization and change events.
|
|
||||||
Accesses font_name, font_size, and font_bold Variables.
|
|
||||||
Updates font_sample and hightlight page highlight_sample.
|
|
||||||
"""
|
|
||||||
font_name = self.font_name.get()
|
|
||||||
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
|
|
||||||
new_font = (font_name, self.font_size.get(), font_weight)
|
|
||||||
self.font_sample['font'] = new_font
|
|
||||||
self.highlight_sample['font'] = new_font
|
|
||||||
|
|
||||||
def load_tab_cfg(self):
|
|
||||||
"""Load current configuration settings for the tab options.
|
|
||||||
|
|
||||||
Attributes updated:
|
|
||||||
space_num: Set to value from idleConf.
|
|
||||||
"""
|
|
||||||
# Set indent sizes.
|
|
||||||
space_num = idleConf.GetOption(
|
|
||||||
'main', 'Indent', 'num-spaces', default=4, type='int')
|
|
||||||
self.space_num.set(space_num)
|
|
||||||
|
|
||||||
def create_page_highlight(self):
|
def create_page_highlight(self):
|
||||||
"""Return frame of widgets for Highlighting tab.
|
"""Return frame of widgets for Highlighting tab.
|
||||||
|
|
||||||
|
@ -505,7 +308,7 @@ 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.highlight_sample=Text(
|
text = self.highlight_sample = frame.highlight_sample = Text(
|
||||||
frame_custom, relief=SOLID, borderwidth=1,
|
frame_custom, relief=SOLID, borderwidth=1,
|
||||||
font=('courier', 12, ''), cursor='hand2', width=21, height=13,
|
font=('courier', 12, ''), cursor='hand2', width=21, height=13,
|
||||||
takefocus=FALSE, highlightthickness=0, wrap=NONE)
|
takefocus=FALSE, highlightthickness=0, wrap=NONE)
|
||||||
|
@ -1829,6 +1632,219 @@ class ConfigDialog(Toplevel):
|
||||||
self.ext_userCfg.Save()
|
self.ext_userCfg.Save()
|
||||||
|
|
||||||
|
|
||||||
|
class FontPage(Frame):
|
||||||
|
|
||||||
|
def __init__(self, parent, highpage):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.parent = parent
|
||||||
|
self.highlight_sample = highpage.highlight_sample
|
||||||
|
self.create_page_font_tab()
|
||||||
|
self.load_font_cfg()
|
||||||
|
self.load_tab_cfg()
|
||||||
|
|
||||||
|
def create_page_font_tab(self):
|
||||||
|
"""Return frame of widgets for Font/Tabs tab.
|
||||||
|
|
||||||
|
Fonts: Enable users to provisionally change font face, size, or
|
||||||
|
boldness and to see the consequence of proposed choices. Each
|
||||||
|
action set 3 options in changes structuree and changes the
|
||||||
|
corresponding aspect of the font sample on this page and
|
||||||
|
highlight sample on highlight page.
|
||||||
|
|
||||||
|
Function load_font_cfg initializes font vars and widgets from
|
||||||
|
idleConf entries and tk.
|
||||||
|
|
||||||
|
Fontlist: mouse button 1 click or up or down key invoke
|
||||||
|
on_fontlist_select(), which sets var font_name.
|
||||||
|
|
||||||
|
Sizelist: clicking the menubutton opens the dropdown menu. A
|
||||||
|
mouse button 1 click or return key sets var font_size.
|
||||||
|
|
||||||
|
Bold_toggle: clicking the box toggles var font_bold.
|
||||||
|
|
||||||
|
Changing any of the font vars invokes var_changed_font, which
|
||||||
|
adds all 3 font options to changes and calls set_samples.
|
||||||
|
Set_samples applies a new font constructed from the font vars to
|
||||||
|
font_sample and to highlight_sample on the hightlight page.
|
||||||
|
|
||||||
|
Tabs: Enable users to change spaces entered for indent tabs.
|
||||||
|
Changing indent_scale value with the mouse sets Var space_num,
|
||||||
|
which invokes the default callback to add an entry to
|
||||||
|
changes. Load_tab_cfg initializes space_num to default.
|
||||||
|
|
||||||
|
Widget Structure: (*) widgets bound to self
|
||||||
|
frame (of tab_pages)
|
||||||
|
frame_font: LabelFrame
|
||||||
|
frame_font_name: Frame
|
||||||
|
font_name_title: Label
|
||||||
|
(*)fontlist: ListBox - font_name
|
||||||
|
scroll_font: Scrollbar
|
||||||
|
frame_font_param: Frame
|
||||||
|
font_size_title: Label
|
||||||
|
(*)sizelist: DynOptionMenu - font_size
|
||||||
|
(*)bold_toggle: Checkbutton - font_bold
|
||||||
|
frame_font_sample: Frame
|
||||||
|
(*)font_sample: Label
|
||||||
|
frame_indent: LabelFrame
|
||||||
|
indent_title: Label
|
||||||
|
(*)indent_scale: Scale - space_num
|
||||||
|
"""
|
||||||
|
parent = self.parent
|
||||||
|
self.font_name = tracers.add(StringVar(parent), self.var_changed_font)
|
||||||
|
self.font_size = tracers.add(StringVar(parent), self.var_changed_font)
|
||||||
|
self.font_bold = tracers.add(BooleanVar(parent), self.var_changed_font)
|
||||||
|
self.space_num = tracers.add(IntVar(self), ('main', 'Indent', 'num-spaces'))
|
||||||
|
|
||||||
|
# Create widgets:
|
||||||
|
# body and body section frames.
|
||||||
|
frame = self
|
||||||
|
frame_font = LabelFrame(
|
||||||
|
frame, borderwidth=2, relief=GROOVE, text=' Base Editor Font ')
|
||||||
|
frame_indent = LabelFrame(
|
||||||
|
frame, borderwidth=2, relief=GROOVE, text=' Indentation Width ')
|
||||||
|
# frame_font.
|
||||||
|
frame_font_name = Frame(frame_font)
|
||||||
|
frame_font_param = Frame(frame_font)
|
||||||
|
font_name_title = Label(
|
||||||
|
frame_font_name, justify=LEFT, text='Font Face :')
|
||||||
|
self.fontlist = Listbox(frame_font_name, height=5,
|
||||||
|
takefocus=True, exportselection=FALSE)
|
||||||
|
self.fontlist.bind('<ButtonRelease-1>', self.on_fontlist_select)
|
||||||
|
self.fontlist.bind('<KeyRelease-Up>', self.on_fontlist_select)
|
||||||
|
self.fontlist.bind('<KeyRelease-Down>', self.on_fontlist_select)
|
||||||
|
scroll_font = Scrollbar(frame_font_name)
|
||||||
|
scroll_font.config(command=self.fontlist.yview)
|
||||||
|
self.fontlist.config(yscrollcommand=scroll_font.set)
|
||||||
|
font_size_title = Label(frame_font_param, text='Size :')
|
||||||
|
self.sizelist = DynOptionMenu(frame_font_param, self.font_size, None)
|
||||||
|
self.bold_toggle = Checkbutton(
|
||||||
|
frame_font_param, variable=self.font_bold,
|
||||||
|
onvalue=1, offvalue=0, text='Bold')
|
||||||
|
frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)
|
||||||
|
temp_font = tkFont.Font(parent, ('courier', 10, 'normal'))
|
||||||
|
self.font_sample = Label(
|
||||||
|
frame_font_sample, justify=LEFT, font=temp_font,
|
||||||
|
text='AaBbCcDdEe\nFfGgHhIiJj\n1234567890\n#:+=(){}[]')
|
||||||
|
# frame_indent.
|
||||||
|
indent_title = Label(
|
||||||
|
frame_indent, justify=LEFT,
|
||||||
|
text='Python Standard: 4 Spaces!')
|
||||||
|
self.indent_scale = Scale(
|
||||||
|
frame_indent, variable=self.space_num,
|
||||||
|
orient='horizontal', tickinterval=2, from_=2, to=16)
|
||||||
|
|
||||||
|
# Pack widgets:
|
||||||
|
# body.
|
||||||
|
frame_font.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
||||||
|
frame_indent.pack(side=LEFT, padx=5, pady=5, fill=Y)
|
||||||
|
# frame_font.
|
||||||
|
frame_font_name.pack(side=TOP, padx=5, pady=5, fill=X)
|
||||||
|
frame_font_param.pack(side=TOP, padx=5, pady=5, fill=X)
|
||||||
|
font_name_title.pack(side=TOP, anchor=W)
|
||||||
|
self.fontlist.pack(side=LEFT, expand=TRUE, fill=X)
|
||||||
|
scroll_font.pack(side=LEFT, fill=Y)
|
||||||
|
font_size_title.pack(side=LEFT, anchor=W)
|
||||||
|
self.sizelist.pack(side=LEFT, anchor=W)
|
||||||
|
self.bold_toggle.pack(side=LEFT, anchor=W, padx=20)
|
||||||
|
frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)
|
||||||
|
self.font_sample.pack(expand=TRUE, fill=BOTH)
|
||||||
|
# frame_indent.
|
||||||
|
frame_indent.pack(side=TOP, fill=X)
|
||||||
|
indent_title.pack(side=TOP, anchor=W, padx=5)
|
||||||
|
self.indent_scale.pack(side=TOP, padx=5, fill=X)
|
||||||
|
|
||||||
|
return frame
|
||||||
|
|
||||||
|
def load_font_cfg(self):
|
||||||
|
"""Load current configuration settings for the font options.
|
||||||
|
|
||||||
|
Retrieve current font with idleConf.GetFont and font families
|
||||||
|
from tk. Setup fontlist and set font_name. Setup sizelist,
|
||||||
|
which sets font_size. Set font_bold. Call set_samples.
|
||||||
|
"""
|
||||||
|
configured_font = idleConf.GetFont(self, 'main', 'EditorWindow')
|
||||||
|
font_name = configured_font[0].lower()
|
||||||
|
font_size = configured_font[1]
|
||||||
|
font_bold = configured_font[2]=='bold'
|
||||||
|
|
||||||
|
# Set editor font selection list and font_name.
|
||||||
|
fonts = list(tkFont.families(self))
|
||||||
|
fonts.sort()
|
||||||
|
for font in fonts:
|
||||||
|
self.fontlist.insert(END, font)
|
||||||
|
self.font_name.set(font_name)
|
||||||
|
lc_fonts = [s.lower() for s in fonts]
|
||||||
|
try:
|
||||||
|
current_font_index = lc_fonts.index(font_name)
|
||||||
|
self.fontlist.see(current_font_index)
|
||||||
|
self.fontlist.select_set(current_font_index)
|
||||||
|
self.fontlist.select_anchor(current_font_index)
|
||||||
|
self.fontlist.activate(current_font_index)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
# Set font size dropdown.
|
||||||
|
self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14',
|
||||||
|
'16', '18', '20', '22', '25', '29', '34', '40'),
|
||||||
|
font_size)
|
||||||
|
# Set font weight.
|
||||||
|
self.font_bold.set(font_bold)
|
||||||
|
self.set_samples()
|
||||||
|
|
||||||
|
def var_changed_font(self, *params):
|
||||||
|
"""Store changes to font attributes.
|
||||||
|
|
||||||
|
When one font attribute changes, save them all, as they are
|
||||||
|
not independent from each other. In particular, when we are
|
||||||
|
overriding the default font, we need to write out everything.
|
||||||
|
"""
|
||||||
|
value = self.font_name.get()
|
||||||
|
changes.add_option('main', 'EditorWindow', 'font', value)
|
||||||
|
value = self.font_size.get()
|
||||||
|
changes.add_option('main', 'EditorWindow', 'font-size', value)
|
||||||
|
value = self.font_bold.get()
|
||||||
|
changes.add_option('main', 'EditorWindow', 'font-bold', value)
|
||||||
|
self.set_samples()
|
||||||
|
|
||||||
|
def on_fontlist_select(self, event):
|
||||||
|
"""Handle selecting a font from the list.
|
||||||
|
|
||||||
|
Event can result from either mouse click or Up or Down key.
|
||||||
|
Set font_name and example displays to selection.
|
||||||
|
"""
|
||||||
|
font = self.fontlist.get(
|
||||||
|
ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)
|
||||||
|
self.font_name.set(font.lower())
|
||||||
|
|
||||||
|
def set_samples(self, event=None):
|
||||||
|
"""Update update both screen samples with the font settings.
|
||||||
|
|
||||||
|
Called on font initialization and change events.
|
||||||
|
Accesses font_name, font_size, and font_bold Variables.
|
||||||
|
Updates font_sample and hightlight page highlight_sample.
|
||||||
|
"""
|
||||||
|
font_name = self.font_name.get()
|
||||||
|
font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL
|
||||||
|
new_font = (font_name, self.font_size.get(), font_weight)
|
||||||
|
self.font_sample['font'] = new_font
|
||||||
|
self.highlight_sample['font'] = new_font
|
||||||
|
|
||||||
|
def load_tab_cfg(self):
|
||||||
|
"""Load current configuration settings for the tab options.
|
||||||
|
|
||||||
|
Attributes updated:
|
||||||
|
space_num: Set to value from idleConf.
|
||||||
|
"""
|
||||||
|
# Set indent sizes.
|
||||||
|
space_num = idleConf.GetOption(
|
||||||
|
'main', 'Indent', 'num-spaces', default=4, type='int')
|
||||||
|
self.space_num.set(space_num)
|
||||||
|
|
||||||
|
def var_changed_space_num(self, *params):
|
||||||
|
"Store change to indentation size."
|
||||||
|
value = self.space_num.get()
|
||||||
|
changes.add_option('main', 'Indent', 'num-spaces', value)
|
||||||
|
|
||||||
|
|
||||||
class VarTrace:
|
class VarTrace:
|
||||||
"""Maintain Tk variables trace state."""
|
"""Maintain Tk variables trace state."""
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ requires('gui')
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from idlelib.idle_test.mock_idle import Func
|
from idlelib.idle_test.mock_idle import Func
|
||||||
from tkinter import Tk, IntVar, BooleanVar, DISABLED, NORMAL
|
from tkinter import Tk, Frame, IntVar, BooleanVar, DISABLED, NORMAL
|
||||||
from idlelib import config
|
from idlelib import config
|
||||||
from idlelib.configdialog import idleConf, changes, tracers
|
from idlelib.configdialog import idleConf, changes, tracers
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def tearDownModule():
|
||||||
del root
|
del root
|
||||||
|
|
||||||
|
|
||||||
class FontTest(unittest.TestCase):
|
class FontPageTest(unittest.TestCase):
|
||||||
"""Test that font widgets enable users to make font changes.
|
"""Test that font widgets enable users to make font changes.
|
||||||
|
|
||||||
Test that widget actions set vars, that var changes add three
|
Test that widget actions set vars, that var changes add three
|
||||||
|
@ -56,11 +56,15 @@ class FontTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
dialog.set_samples = Func() # Mask instance method.
|
page = cls.page = dialog.fontpage
|
||||||
|
#dialog.note.insert(0, page, text='copy')
|
||||||
|
#dialog.note.add(page, text='copyfgfg')
|
||||||
|
dialog.note.select(page)
|
||||||
|
page.set_samples = Func() # Mask instance method.
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
del dialog.set_samples # Unmask instance method.
|
del cls.page.set_samples # Unmask instance method.
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
changes.clear()
|
changes.clear()
|
||||||
|
@ -68,7 +72,8 @@ class FontTest(unittest.TestCase):
|
||||||
def test_load_font_cfg(self):
|
def test_load_font_cfg(self):
|
||||||
# Leave widget load test to human visual check.
|
# Leave widget load test to human visual check.
|
||||||
# TODO Improve checks when add IdleConf.get_font_values.
|
# TODO Improve checks when add IdleConf.get_font_values.
|
||||||
d = dialog
|
tracers.detach()
|
||||||
|
d = self.page
|
||||||
d.font_name.set('Fake')
|
d.font_name.set('Fake')
|
||||||
d.font_size.set('1')
|
d.font_size.set('1')
|
||||||
d.font_bold.set(True)
|
d.font_bold.set(True)
|
||||||
|
@ -77,16 +82,17 @@ class FontTest(unittest.TestCase):
|
||||||
self.assertNotEqual(d.font_name.get(), 'Fake')
|
self.assertNotEqual(d.font_name.get(), 'Fake')
|
||||||
self.assertNotEqual(d.font_size.get(), '1')
|
self.assertNotEqual(d.font_size.get(), '1')
|
||||||
self.assertFalse(d.font_bold.get())
|
self.assertFalse(d.font_bold.get())
|
||||||
self.assertEqual(d.set_samples.called, 3)
|
self.assertEqual(d.set_samples.called, 1)
|
||||||
|
tracers.attach()
|
||||||
|
|
||||||
def test_fontlist_key(self):
|
def test_fontlist_key(self):
|
||||||
# Up and Down keys should select a new font.
|
# Up and Down keys should select a new font.
|
||||||
|
d = self.page
|
||||||
if dialog.fontlist.size() < 2:
|
if d.fontlist.size() < 2:
|
||||||
cls.skipTest('need at least 2 fonts')
|
self.skipTest('need at least 2 fonts')
|
||||||
fontlist = dialog.fontlist
|
fontlist = d.fontlist
|
||||||
fontlist.activate(0)
|
fontlist.activate(0)
|
||||||
font = dialog.fontlist.get('active')
|
font = d.fontlist.get('active')
|
||||||
|
|
||||||
# Test Down key.
|
# Test Down key.
|
||||||
fontlist.focus_force()
|
fontlist.focus_force()
|
||||||
|
@ -96,7 +102,7 @@ class FontTest(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(d.font_name.get(), down_font.lower())
|
||||||
|
|
||||||
# Test Up key.
|
# Test Up key.
|
||||||
fontlist.focus_force()
|
fontlist.focus_force()
|
||||||
|
@ -106,14 +112,14 @@ class FontTest(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(d.font_name.get(), up_font.lower())
|
||||||
|
|
||||||
def test_fontlist_mouse(self):
|
def test_fontlist_mouse(self):
|
||||||
# Click on item should select that item.
|
# Click on item should select that item.
|
||||||
|
d = self.page
|
||||||
if dialog.fontlist.size() < 2:
|
if d.fontlist.size() < 2:
|
||||||
cls.skipTest('need at least 2 fonts')
|
cls.skipTest('need at least 2 fonts')
|
||||||
fontlist = dialog.fontlist
|
fontlist = d.fontlist
|
||||||
fontlist.activate(0)
|
fontlist.activate(0)
|
||||||
|
|
||||||
# Select next item in listbox
|
# Select next item in listbox
|
||||||
|
@ -129,17 +135,17 @@ class FontTest(unittest.TestCase):
|
||||||
font1 = fontlist.get(1)
|
font1 = fontlist.get(1)
|
||||||
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(d.font_name.get(), font1.lower())
|
||||||
|
|
||||||
def test_sizelist(self):
|
def test_sizelist(self):
|
||||||
# Click on number shouod select that number
|
# Click on number shouod select that number
|
||||||
d = dialog
|
d = self.page
|
||||||
d.sizelist.variable.set(40)
|
d.sizelist.variable.set(40)
|
||||||
self.assertEqual(d.font_size.get(), '40')
|
self.assertEqual(d.font_size.get(), '40')
|
||||||
|
|
||||||
def test_bold_toggle(self):
|
def test_bold_toggle(self):
|
||||||
# Click on checkbutton should invert it.
|
# Click on checkbutton should invert it.
|
||||||
d = dialog
|
d = self.page
|
||||||
d.font_bold.set(False)
|
d.font_bold.set(False)
|
||||||
d.bold_toggle.invoke()
|
d.bold_toggle.invoke()
|
||||||
self.assertTrue(d.font_bold.get())
|
self.assertTrue(d.font_bold.get())
|
||||||
|
@ -154,7 +160,7 @@ class FontTest(unittest.TestCase):
|
||||||
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])
|
||||||
default_bold = default_font[2] == 'bold'
|
default_bold = default_font[2] == 'bold'
|
||||||
d = dialog
|
d = self.page
|
||||||
d.font_size.set(default_size)
|
d.font_size.set(default_size)
|
||||||
d.font_bold.set(default_bold)
|
d.font_bold.set(default_bold)
|
||||||
d.set_samples.called = 0
|
d.set_samples.called = 0
|
||||||
|
@ -183,7 +189,7 @@ class FontTest(unittest.TestCase):
|
||||||
self.assertEqual(d.set_samples.called, 3)
|
self.assertEqual(d.set_samples.called, 3)
|
||||||
|
|
||||||
def test_set_samples(self):
|
def test_set_samples(self):
|
||||||
d = dialog
|
d = self.page
|
||||||
del d.set_samples # Unmask method for test
|
del d.set_samples # Unmask method for test
|
||||||
d.font_sample, d.highlight_sample = {}, {}
|
d.font_sample, d.highlight_sample = {}, {}
|
||||||
d.font_name.set('test')
|
d.font_name.set('test')
|
||||||
|
@ -201,16 +207,21 @@ class FontTest(unittest.TestCase):
|
||||||
|
|
||||||
class IndentTest(unittest.TestCase):
|
class IndentTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
cls.page = dialog.fontpage
|
||||||
|
|
||||||
def test_load_tab_cfg(self):
|
def test_load_tab_cfg(self):
|
||||||
d = dialog
|
d = self.page
|
||||||
d.space_num.set(16)
|
d.space_num.set(16)
|
||||||
d.load_tab_cfg()
|
d.load_tab_cfg()
|
||||||
self.assertEqual(d.space_num.get(), 4)
|
self.assertEqual(d.space_num.get(), 4)
|
||||||
|
|
||||||
def test_indent_scale(self):
|
def test_indent_scale(self):
|
||||||
|
d = self.page
|
||||||
changes.clear()
|
changes.clear()
|
||||||
dialog.indent_scale.set(26)
|
d.indent_scale.set(20)
|
||||||
self.assertEqual(dialog.space_num.get(), 16)
|
self.assertEqual(d.space_num.get(), 16)
|
||||||
self.assertEqual(mainpage, {'Indent': {'num-spaces': '16'}})
|
self.assertEqual(mainpage, {'Indent': {'num-spaces': '16'}})
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,8 +245,10 @@ class GeneralTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
# Mask instance methods used by help functions.
|
|
||||||
d = dialog
|
d = dialog
|
||||||
|
# Select General tab so can force focus on helplist.
|
||||||
|
d.note.select(d.genpage)
|
||||||
|
# Mask instance methods used by help functions.
|
||||||
d.set = d.set_add_delete_state = Func()
|
d.set = d.set_add_delete_state = Func()
|
||||||
d.upc = d.update_help_changes = Func()
|
d.upc = d.update_help_changes = Func()
|
||||||
|
|
||||||
|
@ -311,9 +324,8 @@ class GeneralTest(unittest.TestCase):
|
||||||
helplist.event_generate('<Motion>', x=x, y=y)
|
helplist.event_generate('<Motion>', x=x, y=y)
|
||||||
helplist.event_generate('<Button-1>', x=x, y=y)
|
helplist.event_generate('<Button-1>', x=x, y=y)
|
||||||
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
helplist.event_generate('<ButtonRelease-1>', x=x, y=y)
|
||||||
# The following fail after the switch to
|
self.assertEqual(helplist.get('anchor'), 'source')
|
||||||
# self.assertEqual(helplist.get('anchor'), 'source')
|
self.assertTrue(d.set.called)
|
||||||
# self.assertTrue(d.set.called)
|
|
||||||
self.assertFalse(d.upc.called)
|
self.assertFalse(d.upc.called)
|
||||||
|
|
||||||
def test_set_add_delete_state(self):
|
def test_set_add_delete_state(self):
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
IDLE - Factor FontPage(Frame) class from ConfigDialog.
|
||||||
|
|
||||||
|
Slightly modified tests continue to pass. Fix General tests. Patch mostly by
|
||||||
|
Cheryl Sabella.
|
Loading…
Reference in New Issue