Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/idlelib/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ def canonize(self, filename):

def _test():
from idlelib.editor import fixwordbreaks
from idlelib.util import fix_scaling

@terryjreedy terryjreedy Sep 18, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care about _test either way. It is old code that I do not use. I don't even know if it runs correctly.

import sys
root = Tk()
fix_scaling(root)
fixwordbreaks(root)
root.withdraw()
flist = FileList(root)
Expand Down
4 changes: 4 additions & 0 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"\
Expand Down
5 changes: 5 additions & 0 deletions Lib/idlelib/util.py
Original file line number Diff line number Diff line change
@@ -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'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, this is nonsensical, but I remember that when we switched the IDLE default font to a tk default font, a year ago, there was a bug on Linux that sizes were negative. IDLE currently replaces negative sizes with 10. Should the size be negated instead?

It seems to me that the bug should be fixed in tkinter.font. Do you think that people are depending on the bug?

That aside, it is unclear how the function has any permanent effect after the function returns. I will have to trust that it does.

I would prefer that the function be put in run.py rather than a tiny new module. Pyshell already imports objects from run.py that are needed in both. If doing so results in a circular import problem, and you want to get this in before the cuttoff times today, I can fiddle with the placement and imports later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDLE currently replaces negative sizes with 10. Should the size be negated instead?

Perhaps.

It seems to me that the bug should be fixed in tkinter.font. Do you think that people are depending on the bug?

This is a delicate topic. Specifying negative size is a feature of Tk. It can be used for example for precise positioning texts together with bitmap images or other pixel graphics. And just negating it changes visible font size unless display has 72 DPI (very rarely in current days). On a display with 100 DPI a font with size 10 is 33% larger than a font with size -10.

I'll move fix_scaling to run.py.

Before merging I'm going to test changes on low-DPI display and on multi-display configuration. Would be nice to test it on OSX.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Default fonts now are scaled on HiDPI displays.