1414 StringVar , BooleanVar , IntVar , TRUE , FALSE ,
1515 TOP , BOTTOM , RIGHT , LEFT , SOLID , GROOVE , NORMAL , DISABLED ,
1616 NONE , BOTH , X , Y , W , E , EW , NS , NSEW , NW ,
17- HORIZONTAL , VERTICAL , ANCHOR , END )
17+ HORIZONTAL , VERTICAL , ANCHOR , ACTIVE , END )
1818from tkinter .ttk import Scrollbar
1919import tkinter .colorchooser as tkColorChooser
2020import tkinter .font as tkFont
@@ -78,7 +78,7 @@ def __init__(self, parent, title='', _htest=False, _utest=False):
7878 self .transient (parent )
7979 self .grab_set ()
8080 self .protocol ("WM_DELETE_WINDOW" , self .cancel )
81- self .tab_pages .focus_set ()
81+ self .fontlist .focus_set ()
8282 # XXX Decide whether to keep or delete these key bindings.
8383 # Key bindings for this dialog.
8484 # self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
@@ -143,26 +143,24 @@ def create_page_font_tab(self):
143143 self .space_num = IntVar (parent )
144144 self .edit_font = tkFont .Font (parent , ('courier' , 10 , 'normal' ))
145145
146- ##widget creation
147- #body frame
146+ # Create widgets.
147+ # body and body section frames.
148148 frame = self .tab_pages .pages ['Fonts/Tabs' ].frame
149- #body section frames
150149 frame_font = LabelFrame (
151150 frame , borderwidth = 2 , relief = GROOVE , text = ' Base Editor Font ' )
152151 frame_indent = LabelFrame (
153152 frame , borderwidth = 2 , relief = GROOVE , text = ' Indentation Width ' )
154- #frame_font
153+ # frame_font
155154 frame_font_name = Frame (frame_font )
156155 frame_font_param = Frame (frame_font )
157156 font_name_title = Label (
158157 frame_font_name , justify = LEFT , text = 'Font Face :' )
159- self .list_fonts = Listbox (
158+ self .fontlist = Listbox (
160159 frame_font_name , height = 5 , takefocus = FALSE , exportselection = FALSE )
161- self .list_fonts .bind (
162- '<ButtonRelease-1>' , self .on_list_fonts_button_release )
160+ self .fontlist .bind ('<<ListboxSelect>>' , self .on_fontlist_select )
163161 scroll_font = Scrollbar (frame_font_name )
164- scroll_font .config (command = self .list_fonts .yview )
165- self .list_fonts .config (yscrollcommand = scroll_font .set )
162+ scroll_font .config (command = self .fontlist .yview )
163+ self .fontlist .config (yscrollcommand = scroll_font .set )
166164 font_size_title = Label (frame_font_param , text = 'Size :' )
167165 self .opt_menu_font_size = DynOptionMenu (
168166 frame_font_param , self .font_size , None , command = self .set_font_sample )
@@ -173,7 +171,7 @@ def create_page_font_tab(self):
173171 self .font_sample = Label (
174172 frame_font_sample , justify = LEFT , font = self .edit_font ,
175173 text = 'AaBbCcDdEe\n FfGgHhIiJjK\n 1234567890\n #:+=(){}[]' )
176- #frame_indent
174+ # frame_indent
177175 frame_indent_size = Frame (frame_indent )
178176 indent_size_title = Label (
179177 frame_indent_size , justify = LEFT ,
@@ -182,25 +180,26 @@ def create_page_font_tab(self):
182180 frame_indent_size , variable = self .space_num ,
183181 orient = 'horizontal' , tickinterval = 2 , from_ = 2 , to = 16 )
184182
185- #widget packing
186- #body
183+ # Pack widgets.
184+ # body
187185 frame_font .pack (side = LEFT , padx = 5 , pady = 5 , expand = TRUE , fill = BOTH )
188186 frame_indent .pack (side = LEFT , padx = 5 , pady = 5 , fill = Y )
189- #frame_font
187+ # frame_font
190188 frame_font_name .pack (side = TOP , padx = 5 , pady = 5 , fill = X )
191189 frame_font_param .pack (side = TOP , padx = 5 , pady = 5 , fill = X )
192190 font_name_title .pack (side = TOP , anchor = W )
193- self .list_fonts .pack (side = LEFT , expand = TRUE , fill = X )
191+ self .fontlist .pack (side = LEFT , expand = TRUE , fill = X )
194192 scroll_font .pack (side = LEFT , fill = Y )
195193 font_size_title .pack (side = LEFT , anchor = W )
196194 self .opt_menu_font_size .pack (side = LEFT , anchor = W )
197195 check_font_bold .pack (side = LEFT , anchor = W , padx = 20 )
198196 frame_font_sample .pack (side = TOP , padx = 5 , pady = 5 , expand = TRUE , fill = BOTH )
199197 self .font_sample .pack (expand = TRUE , fill = BOTH )
200- #frame_indent
198+ # frame_indent
201199 frame_indent_size .pack (side = TOP , fill = X )
202200 indent_size_title .pack (side = TOP , anchor = W , padx = 5 )
203201 self .scale_indent_size .pack (side = TOP , padx = 5 , fill = X )
202+
204203 return frame
205204
206205 def create_page_highlight (self ):
@@ -986,13 +985,13 @@ def create_new_theme(self, new_theme_name):
986985 self .is_builtin_theme .set (0 )
987986 self .set_theme_type ()
988987
989- def on_list_fonts_button_release (self , event ):
990- """Handle event of selecting a font from the list.
988+ def on_fontlist_select (self , event ):
989+ """Handle selecting a font from the list.
991990
992- Change the font name to the font selected from the list
993- and update sample text to show that font .
991+ Event can result from either mouse click or Up or Down key.
992+ Set font_name and example display to selection .
994993 """
995- font = self .list_fonts .get (ANCHOR )
994+ font = self .fontlist .get (ANCHOR if event . type == 3 else ACTIVE )
996995 self .font_name .set (font .lower ())
997996 self .set_font_sample ()
998997
@@ -1126,7 +1125,7 @@ def load_font_cfg(self):
11261125 fonts = list (tkFont .families (self ))
11271126 fonts .sort ()
11281127 for font in fonts :
1129- self .list_fonts .insert (END , font )
1128+ self .fontlist .insert (END , font )
11301129 configured_font = idleConf .GetFont (self , 'main' , 'EditorWindow' )
11311130 font_name = configured_font [0 ].lower ()
11321131 font_size = configured_font [1 ]
@@ -1135,9 +1134,10 @@ def load_font_cfg(self):
11351134 lc_fonts = [s .lower () for s in fonts ]
11361135 try :
11371136 current_font_index = lc_fonts .index (font_name )
1138- self .list_fonts .see (current_font_index )
1139- self .list_fonts .select_set (current_font_index )
1140- self .list_fonts .select_anchor (current_font_index )
1137+ self .fontlist .see (current_font_index )
1138+ self .fontlist .select_set (current_font_index )
1139+ self .fontlist .select_anchor (current_font_index )
1140+ self .fontlist .activate (current_font_index )
11411141 except ValueError :
11421142 pass
11431143 # Set font size dropdown.
0 commit comments