[Python-checkins] [2.7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (GH-6585)

Terry Jan Reedy webhook-mailer at python.org
Sat Oct 20 16:27:55 EDT 2018


https://github.com/python/cpython/commit/18c44cc0c13eed792e286ddc1d331951e723aeb9
commit: 18c44cc0c13eed792e286ddc1d331951e723aeb9
branch: 2.7
author: Cheryl Sabella <cheryl.sabella at gmail.com>
committer: Terry Jan Reedy <tjreedy at udel.edu>
date: 2018-10-20T16:27:51-04:00
summary:

[2.7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (GH-6585)


(cherry picked from commit a96c96f5dab68d4e611af4b8caefd7268533fd9a)

files:
A Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst
M Lib/idlelib/FileList.py
M Lib/idlelib/PyShell.py
M Lib/idlelib/run.py

diff --git a/Lib/idlelib/FileList.py b/Lib/idlelib/FileList.py
index 8318ff17b2df..46979e33e358 100644
--- a/Lib/idlelib/FileList.py
+++ b/Lib/idlelib/FileList.py
@@ -107,8 +107,10 @@ def canonize(self, filename):
 
 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 337530ab8864..db854b65e22a 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 466c61ea341a..518afabd1dbb 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 000000000000..68d68cb1c860
--- /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.



More information about the Python-checkins mailing list