bpo-30981: IDLE -- Add more configdialog font page tests. (#2794) · python/cpython@d0969d6 (original) (raw)

`@@ -154,9 +154,9 @@ def create_page_font_tab(self):

`

154

154

`"""Return frame of widgets for Font/Tabs tab.

`

155

155

``

156

156

` Tk Variables:

`

``

157

`+

font_name: Font face.

`

157

158

` font_size: Font size.

`

158

159

` font_bold: Select font bold or not.

`

159

``

`-

font_name: Font face.

`

160

160

` Note: these 3 share var_changed_font callback.

`

161

161

` space_num: Indentation width.

`

162

162

``

`@@ -167,8 +167,7 @@ def create_page_font_tab(self):

`

167

167

` load_font_cfg: Set vars and fontlist.

`

168

168

` on_fontlist_select: Bound to fontlist button release

`

169

169

` or key release.

`

170

``

`-

set_font_sample: Command for opt_menu_font_size and

`

171

``

`-

check_font_bold.

`

``

170

`+

set_samples: Notify both samples of any font change.

`

172

171

` load_tab_cfg: Get current.

`

173

172

``

174

173

` Widget Structure: (*) widgets bound to self

`

`@@ -181,7 +180,7 @@ def create_page_font_tab(self):

`

181

180

` frame_font_param: Frame

`

182

181

` font_size_title: Label

`

183

182

` (*)opt_menu_font_size: DynOptionMenu - font_size

`

184

``

`-

check_font_bold: Checkbutton - font_bold

`

``

183

`+

bold_toggle: Checkbutton - font_bold

`

185

184

` frame_font_sample: Frame

`

186

185

` (*)font_sample: Label

`

187

186

` frame_indent: LabelFrame

`

`@@ -190,9 +189,9 @@ def create_page_font_tab(self):

`

190

189

` (*)scale_indent_size: Scale - space_num

`

191

190

` """

`

192

191

`parent = self.parent

`

``

192

`+

self.font_name = StringVar(parent)

`

193

193

`self.font_size = StringVar(parent)

`

194

194

`self.font_bold = BooleanVar(parent)

`

195

``

`-

self.font_name = StringVar(parent)

`

196

195

`self.space_num = IntVar(parent)

`

197

196

`self.edit_font = tkFont.Font(parent, ('courier', 10, 'normal'))

`

198

197

``

`@@ -218,10 +217,10 @@ def create_page_font_tab(self):

`

218

217

`self.fontlist.config(yscrollcommand=scroll_font.set)

`

219

218

`font_size_title = Label(frame_font_param, text='Size :')

`

220

219

`self.opt_menu_font_size = DynOptionMenu(

`

221

``

`-

frame_font_param, self.font_size, None, command=self.set_font_sample)

`

222

``

`-

check_font_bold = Checkbutton(

`

``

220

`+

frame_font_param, self.font_size, None, command=self.set_samples)

`

``

221

`+

bold_toggle = Checkbutton(

`

223

222

`frame_font_param, variable=self.font_bold, onvalue=1,

`

224

``

`-

offvalue=0, text='Bold', command=self.set_font_sample)

`

``

223

`+

offvalue=0, text='Bold', command=self.set_samples)

`

225

224

`frame_font_sample = Frame(frame_font, relief=SOLID, borderwidth=1)

`

226

225

`self.font_sample = Label(

`

227

226

`frame_font_sample, justify=LEFT, font=self.edit_font,

`

`@@ -247,7 +246,7 @@ def create_page_font_tab(self):

`

247

246

`scroll_font.pack(side=LEFT, fill=Y)

`

248

247

`font_size_title.pack(side=LEFT, anchor=W)

`

249

248

`self.opt_menu_font_size.pack(side=LEFT, anchor=W)

`

250

``

`-

check_font_bold.pack(side=LEFT, anchor=W, padx=20)

`

``

249

`+

bold_toggle.pack(side=LEFT, anchor=W, padx=20)

`

251

250

`frame_font_sample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)

`

252

251

`self.font_sample.pack(expand=TRUE, fill=BOTH)

`

253

252

`# frame_indent

`

`@@ -292,7 +291,7 @@ def create_page_highlight(self):

`

292

291

` Widget Structure: (*) widgets bound to self

`

293

292

` frame

`

294

293

` frame_custom: LabelFrame

`

295

``

`-

(*)text_highlight_sample: Text

`

``

294

`+

(*)highlight_sample: Text

`

296

295

` (*)frame_color_set: Frame

`

297

296

` button_set_color: Button

`

298

297

` (*)opt_menu_highlight_target: DynOptionMenu - highlight_target

`

`@@ -342,11 +341,11 @@ def create_page_highlight(self):

`

342

341

`frame_theme = LabelFrame(frame, borderwidth=2, relief=GROOVE,

`

343

342

`text=' Highlighting Theme ')

`

344

343

`#frame_custom

`

345

``

`-

self.text_highlight_sample=Text(

`

``

344

`+

self.highlight_sample=Text(

`

346

345

`frame_custom, relief=SOLID, borderwidth=1,

`

347

346

`font=('courier', 12, ''), cursor='hand2', width=21, height=11,

`

348

347

`takefocus=FALSE, highlightthickness=0, wrap=NONE)

`

349

``

`-

text=self.text_highlight_sample

`

``

348

`+

text=self.highlight_sample

`

350

349

`text.bind('', lambda e: 'break')

`

351

350

`text.bind('', lambda e: 'break')

`

352

351

`text_and_tags=(

`

`@@ -416,7 +415,7 @@ def tem(event, elem=element):

`

416

415

`#frame_custom

`

417

416

`self.frame_color_set.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X)

`

418

417

`frame_fg_bg_toggle.pack(side=TOP, padx=5, pady=0)

`

419

``

`-

self.text_highlight_sample.pack(

`

``

418

`+

self.highlight_sample.pack(

`

420

419

`side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH)

`

421

420

`button_set_color.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4)

`

422

421

`self.opt_menu_highlight_target.pack(

`

`@@ -1142,7 +1141,7 @@ def on_new_color_set(self):

`

1142

1141

`self.frame_color_set.config(bg=new_color) # Set sample.

`

1143

1142

`plane ='foreground' if self.fg_bg_toggle.get() else 'background'

`

1144

1143

`sample_element = self.theme_elements[self.highlight_target.get()][0]

`

1145

``

`-

self.text_highlight_sample.tag_config(sample_element, **{plane:new_color})

`

``

1144

`+

self.highlight_sample.tag_config(sample_element, **{plane:new_color})

`

1146

1145

`theme = self.custom_theme.get()

`

1147

1146

`theme_element = sample_element + '-' + plane

`

1148

1147

`changes.add_option('highlight', theme, theme_element, new_color)

`

`@@ -1210,41 +1209,25 @@ def on_fontlist_select(self, event):

`

1210

1209

`"""Handle selecting a font from the list.

`

1211

1210

``

1212

1211

` Event can result from either mouse click or Up or Down key.

`

1213

``

`-

Set font_name and example display to selection.

`

1214

``

-

1215

``

`-

Attributes updated:

`

1216

``

`-

font_name: Set to name selected from fontlist.

`

1217

``

-

1218

``

`-

Methods:

`

1219

``

`-

set_font_sample

`

``

1212

`+

Set font_name and example displays to selection.

`

1220

1213

` """

`

1221

1214

`font = self.fontlist.get(

`

1222

1215

`ACTIVE if event.type.name == 'KeyRelease' else ANCHOR)

`

1223

1216

`self.font_name.set(font.lower())

`

1224

``

`-

self.set_font_sample()

`

1225

``

-

1226

``

`-

def set_font_sample(self, event=None):

`

1227

``

`-

"""Update the screen samples with the font settings from the dialog.

`

``

1217

`+

self.set_samples()

`

1228

1218

``

1229

``

`-

Attributes accessed:

`

1230

``

`-

font_name

`

1231

``

`-

font_bold

`

1232

``

`-

font_size

`

``

1219

`+

def set_samples(self, event=None):

`

``

1220

`+

"""Update update both screen samples with the font settings.

`

1233

1221

``

1234

``

`-

Attributes updated:

`

1235

``

`-

font_sample: Set to selected font name, size, and weight.

`

1236

``

`-

text_highlight_sample: Set to selected font name, size, and weight.

`

1237

``

-

1238

``

`-

Called from:

`

1239

``

`-

handler for opt_menu_font_size and check_font_bold

`

1240

``

`-

on_fontlist_select

`

1241

``

`-

load_font_cfg

`

``

1222

`+

Called on font initialization and change events.

`

``

1223

`+

Accesses font_name, font_size, and font_bold Variables.

`

``

1224

`+

Updates font_sample and hightlight page highlight_sample.

`

1242

1225

` """

`

1243

1226

`font_name = self.font_name.get()

`

1244

1227

`font_weight = tkFont.BOLD if self.font_bold.get() else tkFont.NORMAL

`

1245

1228

`new_font = (font_name, self.font_size.get(), font_weight)

`

1246

``

`-

self.font_sample.config(font=new_font)

`

1247

``

`-

self.text_highlight_sample.configure(font=new_font)

`

``

1229

`+

self.font_sample['font'] = new_font

`

``

1230

`+

self.highlight_sample['font'] = new_font

`

1248

1231

``

1249

1232

`def set_highlight_target(self):

`

1250

1233

`"""Set fg/bg toggle and color based on highlight tag target.

`

`@@ -1289,15 +1272,15 @@ def set_color_sample(self):

`

1289

1272

` theme_elements

`

1290

1273

` highlight_target

`

1291

1274

` fg_bg_toggle

`

1292

``

`-

text_highlight_sample

`

``

1275

`+

highlight_sample

`

1293

1276

``

1294

1277

` Attributes updated:

`

1295

1278

` frame_color_set

`

1296

1279

` """

`

1297

1280

`# Set the color sample area.

`

1298

1281

`tag = self.theme_elements[self.highlight_target.get()][0]

`

1299

1282

`plane = 'foreground' if self.fg_bg_toggle.get() else 'background'

`

1300

``

`-

color = self.text_highlight_sample.tag_cget(tag, plane)

`

``

1283

`+

color = self.highlight_sample.tag_cget(tag, plane)

`

1301

1284

`self.frame_color_set.config(bg=color)

`

1302

1285

``

1303

1286

`def paint_theme_sample(self):

`

`@@ -1310,7 +1293,7 @@ def paint_theme_sample(self):

`

1310

1293

` custom_theme

`

1311

1294

``

1312

1295

` Attributes updated:

`

1313

``

`-

text_highlight_sample: Set the tag elements to the theme.

`

``

1296

`+

highlight_sample: Set the tag elements to the theme.

`

1314

1297

``

1315

1298

` Methods:

`

1316

1299

` set_color_sample

`

`@@ -1337,7 +1320,7 @@ def paint_theme_sample(self):

`

1337

1320

`colors['foreground'] = theme_dict[element + '-foreground']

`

1338

1321

`if element + '-background' in theme_dict:

`

1339

1322

`colors['background'] = theme_dict[element + '-background']

`

1340

``

`-

self.text_highlight_sample.tag_config(element, **colors)

`

``

1323

`+

self.highlight_sample.tag_config(element, **colors)

`

1341

1324

`self.set_color_sample()

`

1342

1325

``

1343

1326

`def help_source_selected(self, event):

`

`@@ -1424,7 +1407,7 @@ def load_font_cfg(self):

`

1424

1407

` font_bold: Set to current font weight.

`

1425

1408

``

1426

1409

` Methods:

`

1427

``

`-

set_font_sample

`

``

1410

`+

set_samples

`

1428

1411

` """

`

1429

1412

`# Set base editor font selection list.

`

1430

1413

`fonts = list(tkFont.families(self))

`

`@@ -1452,7 +1435,7 @@ def load_font_cfg(self):

`

1452

1435

`# Set font weight.

`

1453

1436

`self.font_bold.set(font_bold)

`

1454

1437

`# Set font sample.

`

1455

``

`-

self.set_font_sample()

`

``

1438

`+

self.set_samples()

`

1456

1439

``

1457

1440

`def load_tab_cfg(self):

`

1458

1441

`"""Load current configuration settings for the tab options.

`