From a58e407dd43f1da9c9bcac0d53d46d0df9525318 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 18 Sep 2017 10:43:23 +0300 Subject: [PATCH 1/7] bpo-31500: IDLE: Scale default fonts on HiDPI displays. --- Lib/idlelib/filelist.py | 2 ++ Lib/idlelib/pyshell.py | 4 ++++ Lib/idlelib/run.py | 2 ++ Lib/idlelib/util.py | 5 +++++ .../next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst | 1 + 5 files changed, 14 insertions(+) create mode 100644 Lib/idlelib/util.py create mode 100644 Misc/NEWS.d/next/IDLE/2017-09-18-10-43-03.bpo-31500.Y_YDxA.rst diff --git a/Lib/idlelib/filelist.py b/Lib/idlelib/filelist.py index f46ad7cd7e9e0e7..a72d66bbad7241f 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.util 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 47df74433cf87ac..eebc978db742157 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.util 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.util 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 9f6604bb0acc58b..c73be878362bfd3 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -183,7 +183,9 @@ def show_socket_error(err, address): "Display socket error from manage_socket." import tkinter from tkinter.messagebox import showerror + from idlelib.util import fix_scaling 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"\ diff --git a/Lib/idlelib/util.py b/Lib/idlelib/util.py new file mode 100644 index 000000000000000..35c731f087c4bf3 --- /dev/null +++ b/Lib/idlelib/util.py @@ -0,0 +1,5 @@ +def fix_scaling(root): + import tkinter.font + for name in tkinter.font.names(root): + font = tkinter.font.Font(root=root, name=name, exists=True) + font['size'] = abs(font['size']) 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 000000000000000..68d68cb1c860326 --- /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. From 61d3d28e5e7e15e9c898ab340347f21a565530f8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 19 Sep 2017 11:16:19 +0300 Subject: [PATCH 2/7] Move fix_scaling to run.py. --- Lib/idlelib/filelist.py | 2 +- Lib/idlelib/pyshell.py | 4 ++-- Lib/idlelib/run.py | 10 +++++++++- Lib/idlelib/util.py | 5 ----- 4 files changed, 12 insertions(+), 9 deletions(-) delete mode 100644 Lib/idlelib/util.py diff --git a/Lib/idlelib/filelist.py b/Lib/idlelib/filelist.py index a72d66bbad7241f..5e1a3dcd77dc67b 100644 --- a/Lib/idlelib/filelist.py +++ b/Lib/idlelib/filelist.py @@ -113,7 +113,7 @@ def canonize(self, filename): def _test(): from idlelib.editor import fixwordbreaks - from idlelib.util import fix_scaling + from idlelib.run import fix_scaling import sys root = Tk() fix_scaling(root) diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index eebc978db742157..168eeae9ad8e9c2 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -12,7 +12,7 @@ if TkVersion < 8.5: root = Tk() # otherwise create root in main root.withdraw() - from idlelib.util import fix_scaling + from idlelib.run import fix_scaling fix_scaling(root) tkMessageBox.showerror("Idle Cannot Start", "Idle requires tcl/tk 8.5+, not %s." % TkVersion, @@ -1459,7 +1459,7 @@ def main(): NoDefaultRoot() root = Tk(className="Idle") root.withdraw() - from idlelib.util import fix_scaling + from idlelib.run import fix_scaling fix_scaling(root) # set application icon diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index c73be878362bfd3..eae2741955b3301 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -183,7 +183,6 @@ def show_socket_error(err, address): "Display socket error from manage_socket." import tkinter from tkinter.messagebox import showerror - from idlelib.util import fix_scaling root = tkinter.Tk() fix_scaling(root) root.withdraw() @@ -279,6 +278,15 @@ def exit(): sys.exit(0) +def fix_scaling(root): + import tkinter.font + 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'] = -size + + class MyRPCServer(rpc.RPCServer): def handle_error(self, request, client_address): diff --git a/Lib/idlelib/util.py b/Lib/idlelib/util.py deleted file mode 100644 index 35c731f087c4bf3..000000000000000 --- a/Lib/idlelib/util.py +++ /dev/null @@ -1,5 +0,0 @@ -def fix_scaling(root): - import tkinter.font - for name in tkinter.font.names(root): - font = tkinter.font.Font(root=root, name=name, exists=True) - font['size'] = abs(font['size']) From 3c87c59d0e938b81049b9af59dada4dfc75942a5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 19 Sep 2017 11:35:29 +0300 Subject: [PATCH 3/7] Do not hardcode the size of config dialog. --- Lib/idlelib/configdialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index 0f530c66a111d65..a05f3b957afc6c4 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -105,7 +105,7 @@ def create_widgets(self): load_configs: Load pages except for extensions. activate_config_changes: Tell editors to reload. """ - self.note = note = Notebook(self, width=450, height=450) + self.note = note = Notebook(self) self.highpage = HighPage(note) self.fontpage = FontPage(note, self.highpage) self.keyspage = KeysPage(note) From 2bece790d11607af67901eb838afee52e62d3f1e Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 19 Sep 2017 23:58:18 +0300 Subject: [PATCH 4/7] Scale fonts only on HiDPI displays. --- Lib/idlelib/run.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index eae2741955b3301..6af04e94c199135 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -279,12 +279,15 @@ def exit(): def fix_scaling(root): + """Scale fonts on HiDPI displays.""" import tkinter.font - 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'] = -size + scaling = float(root.tk.call('tk', 'scaling')) + if scaling >= 1.2: + 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'] = -size class MyRPCServer(rpc.RPCServer): From c6db58cdc35b82f42409873ce5b3d9af47376a98 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Tue, 19 Sep 2017 19:04:19 -0400 Subject: [PATCH 5/7] Update configdialog.py --- Lib/idlelib/configdialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/configdialog.py b/Lib/idlelib/configdialog.py index a05f3b957afc6c4..0f530c66a111d65 100644 --- a/Lib/idlelib/configdialog.py +++ b/Lib/idlelib/configdialog.py @@ -105,7 +105,7 @@ def create_widgets(self): load_configs: Load pages except for extensions. activate_config_changes: Tell editors to reload. """ - self.note = note = Notebook(self) + self.note = note = Notebook(self, width=450, height=450) self.highpage = HighPage(note) self.fontpage = FontPage(note, self.highpage) self.keyspage = KeysPage(note) From 3eb08943b55407a19bdbe74b9ee5edcccc7cff60 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Sep 2017 08:50:29 +0300 Subject: [PATCH 6/7] Downscale fonts to about 100 DPI. --- Lib/idlelib/run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 6af04e94c199135..e904edac699cd08 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -282,12 +282,12 @@ def fix_scaling(root): """Scale fonts on HiDPI displays.""" import tkinter.font scaling = float(root.tk.call('tk', 'scaling')) - if scaling >= 1.2: + 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'] = -size + font['size'] = round(-0.75*size) class MyRPCServer(rpc.RPCServer): From 59847c2f3ddf12bda7e16f952612c9470bc7a7fe Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 20 Sep 2017 20:18:32 +0300 Subject: [PATCH 7/7] Minor change. --- Lib/idlelib/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index e904edac699cd08..39e0c116f9bc41d 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -282,7 +282,7 @@ def fix_scaling(root): """Scale fonts on HiDPI displays.""" import tkinter.font scaling = float(root.tk.call('tk', 'scaling')) - if scaling >= 1.4: + 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'])