]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[2.7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (GH-6585)
authorCheryl Sabella <cheryl.sabella@gmail.com>
Sat, 20 Oct 2018 20:27:51 +0000 (16:27 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Sat, 20 Oct 2018 20:27:51 +0000 (16:27 -0400)
(cherry picked from commit a96c96f5dab68d4e611af4b8caefd7268533fd9a)

Lib/idlelib/FileList.py
Lib/idlelib/PyShell.py
Lib/idlelib/run.py
Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst [new file with mode: 0644]

index 8318ff17b2dfd5f5246aad3d2570188295c15f98..46979e33e358ae77645cd2b1f0e5937fa1423ddb 100644 (file)
@@ -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)
index 337530ab8864e3c5bb12f3a8b42b67382b8aa0f2..db854b65e22aa9a27de66653288fa2d1b089489c 100755 (executable)
@@ -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')
index 466c61ea341a73a621085bdef6fb7a5eb47c9c8a..518afabd1dbbfc9eea86bff3c22b7612ad3ce49f 100644 (file)
@@ -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 (file)
index 0000000..68d68cb
--- /dev/null
@@ -0,0 +1 @@
+Default fonts now are scaled on HiDPI displays.