14
14
StringVar , BooleanVar , IntVar , TRUE , FALSE ,
15
15
TOP , BOTTOM , RIGHT , LEFT , SOLID , GROOVE , NORMAL , DISABLED ,
16
16
NONE , BOTH , X , Y , W , E , EW , NS , NSEW , NW ,
17
- HORIZONTAL , VERTICAL , ANCHOR , END )
17
+ HORIZONTAL , VERTICAL , ANCHOR , ACTIVE , END )
18
18
from tkinter .ttk import Scrollbar
19
19
import tkinter .colorchooser as tkColorChooser
20
20
import tkinter .font as tkFont
@@ -78,7 +78,7 @@ def __init__(self, parent, title='', _htest=False, _utest=False):
78
78
self .transient (parent )
79
79
self .grab_set ()
80
80
self .protocol ("WM_DELETE_WINDOW" , self .cancel )
81
- self .tab_pages .focus_set ()
81
+ self .fontlist .focus_set ()
82
82
# XXX Decide whether to keep or delete these key bindings.
83
83
# Key bindings for this dialog.
84
84
# self.bind('<Escape>', self.Cancel) #dismiss dialog, no save
@@ -143,26 +143,24 @@ def create_page_font_tab(self):
143
143
self .space_num = IntVar (parent )
144
144
self .edit_font = tkFont .Font (parent , ('courier' , 10 , 'normal' ))
145
145
146
- ##widget creation
147
- #body frame
146
+ # Create widgets.
147
+ # body and body section frames.
148
148
frame = self .tab_pages .pages ['Fonts/Tabs' ].frame
149
- #body section frames
150
149
frame_font = LabelFrame (
151
150
frame , borderwidth = 2 , relief = GROOVE , text = ' Base Editor Font ' )
152
151
frame_indent = LabelFrame (
153
152
frame , borderwidth = 2 , relief = GROOVE , text = ' Indentation Width ' )
154
- #frame_font
153
+ # frame_font
155
154
frame_font_name = Frame (frame_font )
156
155
frame_font_param = Frame (frame_font )
157
156
font_name_title = Label (
158
157
frame_font_name , justify = LEFT , text = 'Font Face :' )
159
- self .list_fonts = Listbox (
158
+ self .fontlist = Listbox (
160
159
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 )
163
161
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 )
166
164
font_size_title = Label (frame_font_param , text = 'Size :' )
167
165
self .opt_menu_font_size = DynOptionMenu (
168
166
frame_font_param , self .font_size , None , command = self .set_font_sample )
@@ -173,7 +171,7 @@ def create_page_font_tab(self):
173
171
self .font_sample = Label (
174
172
frame_font_sample , justify = LEFT , font = self .edit_font ,
175
173
text = 'AaBbCcDdEe\n FfGgHhIiJjK\n 1234567890\n #:+=(){}[]' )
176
- #frame_indent
174
+ # frame_indent
177
175
frame_indent_size = Frame (frame_indent )
178
176
indent_size_title = Label (
179
177
frame_indent_size , justify = LEFT ,
@@ -182,25 +180,26 @@ def create_page_font_tab(self):
182
180
frame_indent_size , variable = self .space_num ,
183
181
orient = 'horizontal' , tickinterval = 2 , from_ = 2 , to = 16 )
184
182
185
- #widget packing
186
- #body
183
+ # Pack widgets.
184
+ # body
187
185
frame_font .pack (side = LEFT , padx = 5 , pady = 5 , expand = TRUE , fill = BOTH )
188
186
frame_indent .pack (side = LEFT , padx = 5 , pady = 5 , fill = Y )
189
- #frame_font
187
+ # frame_font
190
188
frame_font_name .pack (side = TOP , padx = 5 , pady = 5 , fill = X )
191
189
frame_font_param .pack (side = TOP , padx = 5 , pady = 5 , fill = X )
192
190
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 )
194
192
scroll_font .pack (side = LEFT , fill = Y )
195
193
font_size_title .pack (side = LEFT , anchor = W )
196
194
self .opt_menu_font_size .pack (side = LEFT , anchor = W )
197
195
check_font_bold .pack (side = LEFT , anchor = W , padx = 20 )
198
196
frame_font_sample .pack (side = TOP , padx = 5 , pady = 5 , expand = TRUE , fill = BOTH )
199
197
self .font_sample .pack (expand = TRUE , fill = BOTH )
200
- #frame_indent
198
+ # frame_indent
201
199
frame_indent_size .pack (side = TOP , fill = X )
202
200
indent_size_title .pack (side = TOP , anchor = W , padx = 5 )
203
201
self .scale_indent_size .pack (side = TOP , padx = 5 , fill = X )
202
+
204
203
return frame
205
204
206
205
def create_page_highlight (self ):
@@ -986,13 +985,13 @@ def create_new_theme(self, new_theme_name):
986
985
self .is_builtin_theme .set (0 )
987
986
self .set_theme_type ()
988
987
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.
991
990
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 .
994
993
"""
995
- font = self .list_fonts .get (ANCHOR )
994
+ font = self .fontlist .get (ANCHOR if event . type == 3 else ACTIVE )
996
995
self .font_name .set (font .lower ())
997
996
self .set_font_sample ()
998
997
@@ -1126,7 +1125,7 @@ def load_font_cfg(self):
1126
1125
fonts = list (tkFont .families (self ))
1127
1126
fonts .sort ()
1128
1127
for font in fonts :
1129
- self .list_fonts .insert (END , font )
1128
+ self .fontlist .insert (END , font )
1130
1129
configured_font = idleConf .GetFont (self , 'main' , 'EditorWindow' )
1131
1130
font_name = configured_font [0 ].lower ()
1132
1131
font_size = configured_font [1 ]
@@ -1135,9 +1134,10 @@ def load_font_cfg(self):
1135
1134
lc_fonts = [s .lower () for s in fonts ]
1136
1135
try :
1137
1136
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 )
1141
1141
except ValueError :
1142
1142
pass
1143
1143
# Set font size dropdown.
0 commit comments