bpo-31500: IDLE: Scale default fonts on HiDPI displays. (#3639) · python/cpython@a96c96f

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -113,8 +113,10 @@ def canonize(self, filename):

113113
114114

def _test():

115115

from idlelib.editor import fixwordbreaks

116+

from idlelib.run import fix_scaling

116117

import sys

117118

root = Tk()

119+

fix_scaling(root)

118120

fixwordbreaks(root)

119121

root.withdraw()

120122

flist = FileList(root)

Original file line numberDiff line numberDiff line change

@@ -12,6 +12,8 @@

1212

if TkVersion < 8.5:

1313

root = Tk() # otherwise create root in main

1414

root.withdraw()

15+

from idlelib.run import fix_scaling

16+

fix_scaling(root)

1517

tkMessageBox.showerror("Idle Cannot Start",

1618

"Idle requires tcl/tk 8.5+, not %s." % TkVersion,

1719

parent=root)

@@ -1457,6 +1459,8 @@ def main():

14571459

NoDefaultRoot()

14581460

root = Tk(className="Idle")

14591461

root.withdraw()

1462+

from idlelib.run import fix_scaling

1463+

fix_scaling(root)

14601464
14611465

# set application icon

14621466

icondir = os.path.join(os.path.dirname(__file__), 'Icons')

Original file line numberDiff line numberDiff line change

@@ -184,6 +184,7 @@ def show_socket_error(err, address):

184184

import tkinter

185185

from tkinter.messagebox import showerror

186186

root = tkinter.Tk()

187+

fix_scaling(root)

187188

root.withdraw()

188189

msg = f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"\

189190

f"Fatal OSError #{err.errno}: {err.strerror}.\n"\

@@ -277,6 +278,18 @@ def exit():

277278

sys.exit(0)

278279
279280
281+

def fix_scaling(root):

282+

"""Scale fonts on HiDPI displays."""

283+

import tkinter.font

284+

scaling = float(root.tk.call('tk', 'scaling'))

285+

if scaling > 1.4:

286+

for name in tkinter.font.names(root):

287+

font = tkinter.font.Font(root=root, name=name, exists=True)

288+

size = int(font['size'])

289+

if size < 0:

290+

font['size'] = round(-0.75*size)

291+
292+
280293

class MyRPCServer(rpc.RPCServer):

281294
282295

def handle_error(self, request, client_address):

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

Default fonts now are scaled on HiDPI displays.