]> granicus.if.org Git - python/commitdiff
bpo-31500: IDLE: Scale default fonts on HiDPI displays. (#3639)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 21 Sep 2017 08:20:06 +0000 (11:20 +0300)
committerGitHub <noreply@github.com>
Thu, 21 Sep 2017 08:20:06 +0000 (11:20 +0300)
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 f46ad7cd7e9e0e7bd101c209561cc71bc7879b91..5e1a3dcd77dc67ba09097a5fe65c7f86680c8055 100644 (file)
@@ -113,8 +113,10 @@ class FileList:
 
 def _test():
     from idlelib.editor import fixwordbreaks
+    from idlelib.run import fix_scaling
     import sys
     root = Tk()
+    fix_scaling(root)
     fixwordbreaks(root)
     root.withdraw()
     flist = FileList(root)
index 47df74433cf87ac9ab83d72f1f589b1201b0bc6b..168eeae9ad8e9c2dfc21faca58dd03078cb6838a 100755 (executable)
@@ -12,6 +12,8 @@ import tkinter.messagebox as tkMessageBox
 if TkVersion < 8.5:
     root = Tk()  # otherwise create root in main
     root.withdraw()
+    from idlelib.run import fix_scaling
+    fix_scaling(root)
     tkMessageBox.showerror("Idle Cannot Start",
             "Idle requires tcl/tk 8.5+, not %s." % TkVersion,
             parent=root)
@@ -1457,6 +1459,8 @@ def main():
         NoDefaultRoot()
     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 9f6604bb0acc58bdde771f65e635f6afabb69395..39e0c116f9bc41d513020d14b4338b6415abffcd 100644 (file)
@@ -184,6 +184,7 @@ def show_socket_error(err, address):
     import tkinter
     from tkinter.messagebox import showerror
     root = tkinter.Tk()
+    fix_scaling(root)
     root.withdraw()
     msg = f"IDLE's subprocess can't connect to {address[0]}:{address[1]}.\n"\
           f"Fatal OSError #{err.errno}: {err.strerror}.\n"\
@@ -277,6 +278,18 @@ def exit():
     sys.exit(0)
 
 
+def fix_scaling(root):
+    """Scale fonts on HiDPI displays."""
+    import tkinter.font
+    scaling = float(root.tk.call('tk', 'scaling'))
+    if scaling > 1.4:
+        for name in tkinter.font.names(root):
+            font = tkinter.font.Font(root=root, name=name, exists=True)
+            size = int(font['size'])
+            if size < 0:
+                font['size'] = 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.