diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py index 12e6f9fae78b80..8647f44137046b 100644 --- a/Lib/idlelib/config.py +++ b/Lib/idlelib/config.py @@ -576,6 +576,10 @@ def IsCoreBinding(self, virtualEvent): """ 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 # and copied in function below. diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index df216582fe6093..533521c7b01f68 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -619,9 +619,7 @@ def load_font_cfg(self): 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) + self.sizelist.SetMenu(idleConf.GetFontSizes(), font_size) # Set font weight. self.font_bold.set(font_bold) self.set_samples() diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index adeed74059f847..3c3550ca7bf1a0 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -193,6 +193,17 @@ def __init__(self, flist=None, filename=None, key=None, root=None): text.bind("<>", self.del_word_left) text.bind("<>", self.del_word_right) text.bind("<>", 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("", self.update_mousewheel) + text.bind("", self.increase_font_size) + text.bind("", self.decrease_font_size) if flist: flist.inversedict[self] = key @@ -211,7 +222,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None): vbar['command'] = self.handle_yview vbar.grid(row=1, column=2, sticky=NSEW) 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.focus_set() self.set_width() @@ -345,6 +358,33 @@ def __init__(self, flist=None, filename=None, key=None, root=None): def handle_winconfig(self, event=None): 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): text = self.text inner_padding = sum(map(text.tk.getint, [text.cget('border'), @@ -817,7 +857,7 @@ def ResetFont(self): self.line_numbers.update_font() # Finally, update the main text widget. new_font = idleConf.GetFont(self.root, 'main', 'EditorWindow') - self.text['font'] = new_font + self.text['font'] = self.font = new_font self.set_width() def RemoveKeybindings(self): diff --git a/Misc/NEWS.d/next/IDLE/2019-11-11-16-26-54.bpo-17642.m6VW2z.rst b/Misc/NEWS.d/next/IDLE/2019-11-11-16-26-54.bpo-17642.m6VW2z.rst new file mode 100644 index 00000000000000..1ab4cda8f371b0 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-11-11-16-26-54.bpo-17642.m6VW2z.rst @@ -0,0 +1 @@ +Add hotkeys to resize the font of IDLE's shell and editor windows.