-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-33656: On Windows, add API call saying that tk scales for DPI. #7137
Conversation
Lib/idlelib/pyshell.py
Outdated
|
||
import ctypes | ||
try: | ||
ctypes.windll.shcore.SetProcessDpiAwareness(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use cdll
, windll
, or oledll
. These are LibraryLoader
instances that cache the loaded instance of CDLL
, WinDLL
, or OleDLL
, which in turn cache function pointers. This leads to conflicts between projects that use the same libraries with different function prototypes (or lack thereof in this case).
Since this is a function that returns an HRESULT
, use shcore = ctypes.OleDLL('shcore')
. This will raise OSError
if the function returns an error code, which will be the winerror
attribute of the exception.
Two errors are documented. It fails with E_ACCESSDENIED
(-2147024891, i.e. ctypes.HRESULT(0x80070005).value
) if the DPI awareness has already been set by calling this function or in the application manifest. E_INVALIDARG
(-2147024809, i.e. ctypes.HRESULT(0x80070057).value
) is unlikely, but you should properly define the argument from the PROCESS_DPI_AWARENESS
enum. The valid values are PROCESS_DPI_UNAWARE
(0), PROCESS_SYSTEM_DPI_AWARE
(1), and PROCESS_PER_MONITOR_DPI_AWARE
(2).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed windll.shcore
to OleDLL('shcore')
. The enum values seem inaccessible and using them would make no real difference. Given the information on the issue (I am about to add more), would you recommend merging this?
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
GH-7639 is a backport of this pull request to the 3.7 branch. |
GH-7640 is a backport of this pull request to the 3.6 branch. |
…thonGH-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>
…thonGH-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>
…-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>
…-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>
if sys.platform == 'win32': | ||
import ctypes | ||
try: | ||
ctypes.OleDLL('shcore').SetProcessDpiAwareness(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define PROCESS_SYSTEM_DPI_AWARE = 1
instead of using a magic number. It wouldn't hurt to quote MSDN in a brief comment that explains this value and also the MSDN URL for the PROCESS_DPI_AWARENESS
enumeration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I made a new PR with both changes. It should make it into today's releases.
#7642.
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 caused 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.
https://bugs.python.org/issue33656