Skip to content

Commit 18c44cc

Browse files
csabellaterryjreedy
authored andcommitted
[2.7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (GH-6585)
(cherry picked from commit a96c96f)
1 parent b53edb1 commit 18c44cc

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

Lib/idlelib/FileList.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ def canonize(self, filename):
107107

108108
def _test():
109109
from idlelib.EditorWindow import fixwordbreaks
110+
from idlelib.run import fix_scaling
110111
import sys
111112
root = Tk()
113+
fix_scaling(root)
112114
fixwordbreaks(root)
113115
root.withdraw()
114116
flist = FileList(root)

Lib/idlelib/PyShell.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,8 @@ def main():
15521552
# start editor and/or shell windows:
15531553
root = Tk(className="Idle")
15541554
root.withdraw()
1555+
from idlelib.run import fix_scaling
1556+
fix_scaling(root)
15551557

15561558
# set application icon
15571559
icondir = os.path.join(os.path.dirname(__file__), 'Icons')

Lib/idlelib/run.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def show_socket_error(err, address):
155155
import Tkinter
156156
import tkMessageBox
157157
root = Tkinter.Tk()
158+
fix_scaling(root)
158159
root.withdraw()
159160
if err.args[0] == 61: # connection refused
160161
msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\
@@ -240,6 +241,19 @@ def exit():
240241
capture_warnings(False)
241242
sys.exit(0)
242243

244+
245+
def fix_scaling(root):
246+
"""Scale fonts on HiDPI displays."""
247+
import tkFont
248+
scaling = float(root.tk.call('tk', 'scaling'))
249+
if scaling > 1.4:
250+
for name in tkFont.names(root):
251+
font = tkFont.Font(root=root, name=name, exists=True)
252+
size = int(font['size'])
253+
if size < 0:
254+
font['size'] = int(round(-0.75*size))
255+
256+
243257
class MyRPCServer(rpc.RPCServer):
244258

245259
def handle_error(self, request, client_address):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Default fonts now are scaled on HiDPI displays.

0 commit comments

Comments
 (0)