bpo-17642: Add hotkeys to resize IDLE's font

This commit is contained in:
Zackery Spytz 2019-11-10 23:56:22 -07:00
parent af46450bb9
commit 8bf7f5f9f7
3 changed files with 47 additions and 5 deletions

View File

@ -576,6 +576,10 @@ class IdleConf:
""" """
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys() return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
def GetFontSizes(self):
return ('7', '8', '9', '10', '11', '12', '13', '14',
'16', '18', '20', '22', '25', '29', '34', '40')
# TODO make keyBindins a file or class attribute used for test above # TODO make keyBindins a file or class attribute used for test above
# and copied in function below. # and copied in function below.

View File

@ -619,9 +619,7 @@ class FontPage(Frame):
except ValueError: except ValueError:
pass pass
# Set font size dropdown. # Set font size dropdown.
self.sizelist.SetMenu(('7', '8', '9', '10', '11', '12', '13', '14', self.sizelist.SetMenu(idleConf.GetFontSizes(), font_size)
'16', '18', '20', '22', '25', '29', '34', '40'),
font_size)
# Set font weight. # Set font weight.
self.font_bold.set(font_bold) self.font_bold.set(font_bold)
self.set_samples() self.set_samples()

View File

@ -193,6 +193,17 @@ class EditorWindow(object):
text.bind("<<del-word-left>>", self.del_word_left) text.bind("<<del-word-left>>", self.del_word_left)
text.bind("<<del-word-right>>", self.del_word_right) text.bind("<<del-word-right>>", self.del_word_right)
text.bind("<<beginning-of-line>>", self.home_callback) text.bind("<<beginning-of-line>>", self.home_callback)
if darwin:
shortcut = "Command"
else:
shortcut = "Control"
text.bind(f"<{shortcut}-minus>", self.decrease_font_size)
text.bind(f"<{shortcut}-underscore>", self.decrease_font_size)
text.bind(f"<{shortcut}-equal>", self.increase_font_size)
text.bind(f"<{shortcut}-plus>", self.increase_font_size)
text.bind("<Control-MouseWheel>", self.update_mousewheel)
text.bind("<Control-Button-4>", self.increase_font_size)
text.bind("<Control-Button-5>", self.decrease_font_size)
if flist: if flist:
flist.inversedict[self] = key flist.inversedict[self] = key
@ -211,7 +222,9 @@ class EditorWindow(object):
vbar['command'] = self.handle_yview vbar['command'] = self.handle_yview
vbar.grid(row=1, column=2, sticky=NSEW) vbar.grid(row=1, column=2, sticky=NSEW)
text['yscrollcommand'] = vbar.set text['yscrollcommand'] = vbar.set
text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow') text['font'] = self.font = idleConf.GetFont(
self.root, 'main', 'EditorWindow')
self.font_sizes = [int(i) for i in idleConf.GetFontSizes()]
text.grid(row=1, column=1, sticky=NSEW) text.grid(row=1, column=1, sticky=NSEW)
text.focus_set() text.focus_set()
self.set_width() self.set_width()
@ -345,6 +358,33 @@ class EditorWindow(object):
def handle_winconfig(self, event=None): def handle_winconfig(self, event=None):
self.set_width() self.set_width()
def set_font_size(self, size):
self.text['font'] = self.font = (self.font[0], size, self.font[2])
def decrease_font_size(self, event=None):
new_size = self.font[1] - 1
if new_size < min(self.font_sizes):
self.text.bell()
return 'break'
self.set_font_size(new_size)
return 'break'
def increase_font_size(self, event=None):
new_size = self.font[1] + 1
if new_size > max(self.font_sizes):
self.text.bell()
return 'break'
self.set_font_size(new_size)
return 'break'
def update_mousewheel(self, event):
# For wheel up, event.delta = 120 on Windows, -1 on darwin.
# X-11 sends Control-Button-4 event instead.
if event.delta < 0 == (not darwin):
return self.decrease_font_size()
else:
return self.increase_font_size()
def set_width(self): def set_width(self):
text = self.text text = self.text
inner_padding = sum(map(text.tk.getint, [text.cget('border'), inner_padding = sum(map(text.tk.getint, [text.cget('border'),
@ -817,7 +857,7 @@ class EditorWindow(object):
self.line_numbers.update_font() self.line_numbers.update_font()
# Finally, update the main text widget. # Finally, update the main text widget.
new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow') new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow')
self.text['font'] = new_font self.text['font'] = self.font = new_font
self.set_width() self.set_width()
def RemoveKeybindings(self): def RemoveKeybindings(self):