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

Terry Jan Reedy webhook-mailer at python.org
Thu Sep 21 11:15:50 EDT 2017


https://github.com/python/cpython/commit/0c4997f1919d8583353b12537a63dcbe7b9d280f
commit: 0c4997f1919d8583353b12537a63dcbe7b9d280f
branch: 3.6
author: Terry Jan Reedy <tjreedy at udel.edu>
committer: GitHub <noreply at github.com>
date: 2017年09月21日T11:15:45-04:00
summary:
[3.6] bpo-31500: IDLE: Scale default fonts on HiDPI displays. (GH-3639) (#3686)
(cherry picked from commit a96c96f)
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 f46ad7cd7e9..5e1a3dcd77d 100644
--- a/Lib/idlelib/filelist.py
+++ b/Lib/idlelib/filelist.py
@@ -113,8 +113,10 @@ def canonize(self, filename):
 
 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)
diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py
index 47df74433cf..168eeae9ad8 100755
--- a/Lib/idlelib/pyshell.py
+++ b/Lib/idlelib/pyshell.py
@@ -12,6 +12,8 @@
 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')
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 9f6604bb0ac..39e0c116f9b 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -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
index 00000000000..68d68cb1c86
--- /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

AltStyle によって変換されたページ (->オリジナル) /