Skip to content

Commit 0404d35

Browse files
bpo-33656: On Windows, add API call saying that tk scales for DPI (GH-7137)
On Windows 8.1+ or 10, with DPI compatibility properties of the Python binary unchanged, and a monitor resolution greater than 96 DPI, this should make text and lines sharper. It should otherwise have no effect. Using a magnifier, I determined that the improvement comes from horizontal and lines being better lined up with the monitor pixels. I checked that this call causes no problem on any Windows buildbot, including the Win7 buildbots. Unlike most IDLE patches, this one can be easily reverted by users by removing a few lines, at the top of idlelib/pyshell.py. (cherry picked from commit 800415e) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 860d8c4 commit 0404d35

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

Doc/whatsnew/3.6.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,12 @@ colors for custom themes is added to Highlights tab of Settings dialog.
11781178
(Contributed by Cheryl Sabella and Terry Jan Reedy in :issue:`33642`,
11791179
:issue:`33768`, and :issue:`33679`)
11801180

1181+
On Windows, a new API call tells Windows that tk scales for DPI. On Windows
1182+
8.1+ or 10, with DPI compatibility properties of the Python binary
1183+
unchanged, and a monitor resolution greater than 96 DPI, this should
1184+
make text and lines sharper. It should otherwise have no effect.
1185+
(Contributed by Terry Jan Reedy in :issue:`33656`).
1186+
11811187

11821188
importlib
11831189
---------

Lib/idlelib/NEWS.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ Released on 2018-06-15?
33
======================================
44

55

6+
bpo-33656: On Windows, add API call saying that tk scales for DPI.
7+
On Windows 8.1+ or 10, with DPI compatibility properties of the Python
8+
binary unchanged, and a monitor resolution greater than 96 DPI, this
9+
should make text and lines sharper. It should otherwise have no
10+
effect. If perchance it make text worse on your monitor, you can
11+
disable the ctypes.OleDLL call near the top of pyshell.py and report
12+
the problem on python-list or idle-dev@python.org.
13+
614
bpo-33768: Clicking on a context line moves that line to the top
715
of the editor window.
816

Lib/idlelib/configdialog.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,12 @@ def create_extension_frame(self, ext_name):
373373
).grid(row=row, column=1, sticky=W, padx=7)
374374
elif opt['type'] == 'int':
375375
Entry(entry_area, textvariable=var, validate='key',
376-
validatecommand=(self.is_int, '%P')
376+
validatecommand=(self.is_int, '%P'), width=10
377377
).grid(row=row, column=1, sticky=NSEW, padx=7)
378378

379-
else:
380-
Entry(entry_area, textvariable=var
379+
else: # type == 'str'
380+
# Limit size to fit non-expanding space with larger font.
381+
Entry(entry_area, textvariable=var, width=15
381382
).grid(row=row, column=1, sticky=NSEW, padx=7)
382383
return
383384

Lib/idlelib/pyshell.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
print("** IDLE can't import Tkinter.\n"
99
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
1010
raise SystemExit(1)
11+
12+
if sys.platform == 'win32':
13+
import ctypes
14+
try:
15+
ctypes.OleDLL('shcore').SetProcessDpiAwareness(1)
16+
except (AttributeError, OSError):
17+
pass
18+
1119
import tkinter.messagebox as tkMessageBox
1220
if TkVersion < 8.5:
1321
root = Tk() # otherwise create root in main
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
On Windows, add API call saying that tk scales for DPI. On Windows
2+
8.1+ or 10, with DPI compatibility properties of the Python binary
3+
unchanged, and a monitor resolution greater than 96 DPI, this should
4+
make text and lines sharper. It should otherwise have no effect.

0 commit comments

Comments
 (0)