From 18c44cc0c13eed792e286ddc1d331951e723aeb9 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sat, 20 Oct 2018 16:27:51 -0400 Subject: [2.7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (GH-6585) (cherry picked from commit a96c96f5dab68d4e611af4b8caefd7268533fd9a) --- Lib/idlelib/FileList.py | 2 ++ Lib/idlelib/PyShell.py | 2 ++ Lib/idlelib/run.py | 14 ++++++++++++++ .../next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst | 1 + 4 files changed, 19 insertions(+) create mode 100644 Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst diff --git a/Lib/idlelib/FileList.py b/Lib/idlelib/FileList.py index 8318ff1..46979e3 100644 --- a/Lib/idlelib/FileList.py +++ b/Lib/idlelib/FileList.py @@ -107,8 +107,10 @@ class FileList: def _test(): from idlelib.EditorWindow import fixwordbreaks + from idlelib.run import fix_scaling import sys root = Tk() + fix_scaling(root) fixwordbreaks(root) root.withdraw() flist = FileList(root) diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 337530a..db854b6 100755 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -1552,6 +1552,8 @@ def main(): # start editor and/or shell windows: root = Tk(className="Idle") root.withdraw() + from idlelib.run import fix_scaling + fix_scaling(root) # set application icon icondir = os.path.join(os.path.dirname(__file__), 'Icons') diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 466c61e..518afab 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -155,6 +155,7 @@ def show_socket_error(err, address): import Tkinter import tkMessageBox root = Tkinter.Tk() + fix_scaling(root) root.withdraw() if err.args[0] == 61: # connection refused msg = "IDLE's subprocess can't connect to %s:%d. This may be due "\ @@ -240,6 +241,19 @@ def exit(): capture_warnings(False) sys.exit(0) + +def fix_scaling(root): + """Scale fonts on HiDPI displays.""" + import tkFont + scaling = float(root.tk.call('tk', 'scaling')) + if scaling > 1.4: + for name in tkFont.names(root): + font = tkFont.Font(root=root, name=name, exists=True) + size = int(font['size']) + if size < 0: + font['size'] = int(round(-0.75*size)) + + class MyRPCServer(rpc.RPCServer): def handle_error(self, request, client_address): diff --git a/Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst b/Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst new file mode 100644 index 0000000..68d68cb --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst @@ -0,0 +1 @@ +Default fonts now are scaled on HiDPI displays. -- cgit v0.12