]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-30870: IDLE: Change sample font when select by key-up/down
authorLouie Lu <git@louie.lu>
Fri, 7 Jul 2017 07:51:58 +0000 (15:51 +0800)
committerLouie Lu <git@louie.lu>
Fri, 7 Jul 2017 07:51:58 +0000 (15:51 +0800)
Lib/idlelib/configdialog.py

index 84092275183685ac9067489de40b116b523884be..982380c0d474f8277737199e386df13c270ca9e2 100644 (file)
@@ -14,7 +14,7 @@ from tkinter import (Toplevel, Frame, LabelFrame, Listbox, Label, Button,
                      StringVar, BooleanVar, IntVar, TRUE, FALSE,
                      TOP, BOTTOM, RIGHT, LEFT, SOLID, GROOVE, NORMAL, DISABLED,
                      NONE, BOTH, X, Y, W, E, EW, NS, NSEW, NW,
-                     HORIZONTAL, VERTICAL, ANCHOR, END)
+                     HORIZONTAL, VERTICAL, ANCHOR, ACTIVE, END)
 from tkinter.ttk import Scrollbar
 import tkinter.colorchooser as tkColorChooser
 import tkinter.font as tkFont
@@ -157,8 +157,9 @@ class ConfigDialog(Toplevel):
                 frame_font_name, justify=LEFT, text='Font Face :')
         self.list_fonts = Listbox(
                 frame_font_name, height=5, takefocus=FALSE, exportselection=FALSE)
-        self.list_fonts.bind(
-                '<ButtonRelease-1>', self.on_list_fonts_button_release)
+        self.list_fonts.bind('<ButtonRelease-1>', self.on_list_fonts_button_release)
+        self.list_fonts.bind('<KeyRelease-Up>', self.on_list_fonts_key_release)
+        self.list_fonts.bind('<KeyRelease-Down>', self.on_list_fonts_key_release)
         scroll_font = Scrollbar(frame_font_name)
         scroll_font.config(command=self.list_fonts.yview)
         self.list_fonts.config(yscrollcommand=scroll_font.set)
@@ -1033,6 +1034,11 @@ class ConfigDialog(Toplevel):
         self.font_name.set(font.lower())
         self.set_font_sample()
 
+    def on_list_fonts_key_release(self, event):
+        font = self.list_fonts.get(ACTIVE)
+        self.font_name.set(font.lower())
+        self.set_font_sample()
+
     def set_font_sample(self, event=None):
         "Update the screen samples with the font settings from the dialog."
         font_name = self.font_name.get()