Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 20, 2018
Merged
2 changes: 2 additions & 0 deletions Lib/idlelib/FileList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Lib/idlelib/PyShell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
14 changes: 14 additions & 0 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Default fonts now are scaled on HiDPI displays.