-
-
Notifications
You must be signed in to change notification settings - Fork 684
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
Implemented DPI process bug fix #717
Implemented DPI process bug fix #717
Conversation
src/winforms/toga_winforms/app.py
Outdated
shcore.SetProcessDpiAwareness(True) | ||
elif win_version >= 10 and win_build >= 15063: | ||
user32.SetProcessDpiAwarenessContext(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.
At column 1: (W293) blank line contains whitespace
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.
Looks good (and works for my testing); a couple of minor tweaks inline.
src/winforms/toga_winforms/libs.py
Outdated
win_version = Environment.OSVersion.Version.Major | ||
win_build = Environment.OSVersion.Version.Build |
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.
This is a really small thing, but could we change win_version
to be Environment.OSVersion.Version
, and then get access to all the structure?
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.
Went ahead and changed it to that.
src/winforms/toga_winforms/app.py
Outdated
user32.SetProcessDPIAware(True) | ||
elif win_version >= 8 and win_build < 15063: |
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.
Are you able to provide any reference to documentation for why these magic numbers exist? An inline docstring will help explain the magic to whoever comes along later.
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.
Actually - this specific check looks a little off - a windows 8 build with a high build number will break on this one.
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.
You are correct that this check is wrong as the windows 8 major version number is actually a 6 and not an 8. In regards to build number it should only pull the update build number, which for Windows 8 the highest build number is 9600. I will fix this tomorrow when I have the chance. Source for information: https://www.lifewire.com/windows-version-numbers-2625171
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 went ahead and implemented much better checks and loads of comments documenting what is what and why.
src/winforms/toga_winforms/app.py
Outdated
@@ -21,8 +21,23 @@ def __init__(self, interface): | |||
def create(self): | |||
self.native = WinForms.Application | |||
|
|||
if win_version >= 6: | |||
user32.SetProcessDPIAware(True) | |||
# Check the version of windows and make sure we are setting the DPI mode |
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.
At column 81: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
# Windows Versioning Check Sources : https://www.lifewire.com/windows-version-numbers-2625171 | ||
# and https://docs.microsoft.com/en-us/windows/release-information/ | ||
if win_version.Major >= 6: # Checks for Windows Vista or later | ||
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use |
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.
At column 89: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
if win_version.Major >= 6: # Checks for Windows Vista or later | ||
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if (win_version.Major == 6 and win_version.Minor == 3) or (win_version.Major == 10 and win_version.Build < 15063): |
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.
At column 120: (E501) line too long (126 > 119 characters)
src/winforms/toga_winforms/app.py
Outdated
if win_version.Major >= 6: # Checks for Windows Vista or later | ||
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if (win_version.Major == 6 and win_version.Minor == 3) or (win_version.Major == 10 and win_version.Build < 15063): |
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.
At column 127: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
# SetProcessDpiAwareness(True) | ||
if (win_version.Major == 6 and win_version.Minor == 3) or (win_version.Major == 10 and win_version.Build < 15063): | ||
shcore.SetProcessDpiAwareness(True) | ||
# Represents Windows 10 Build 1703 and beyond which should use |
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.
At column 75: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
if win_version.Major >= 6: # Checks for Windows Vista or later | ||
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if ((win_version.Major == 6 and win_version.Minor == 3) or |
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.
At column 71: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if ((win_version.Major == 6 and win_version.Minor == 3) or | ||
(win_version.Major == 10 and win_version.Build < 15063)): |
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.
At column 5: (E129) visually indented line with same indent as next logical line
src/winforms/toga_winforms/app.py
Outdated
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if ((win_version.Major == 6 and win_version.Minor == 3) or | ||
(win_version.Major == 10 and win_version.Build < 15063)): |
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.
At column 74: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
# with the most up to date API | ||
# Windows Versioning Check Sources : https://www.lifewire.com/windows-version-numbers-2625171 | ||
# and https://docs.microsoft.com/en-us/windows/release-information/ | ||
if win_version.Major >= 6: # Checks for Windows Vista or later |
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.
At column 35: (E261) at least two spaces before inline comment
src/winforms/toga_winforms/app.py
Outdated
if win_version.Major >= 6: # Checks for Windows Vista or later | ||
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if ((win_version.Major == 6 and win_version.Minor == 3) or |
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.
At column 71: (W291) trailing whitespace
src/winforms/toga_winforms/app.py
Outdated
# Represents Windows 8.1 up to Windows 10 before Build 1703 which should use | ||
# SetProcessDpiAwareness(True) | ||
if ((win_version.Major == 6 and win_version.Minor == 3) or | ||
(win_version.Major == 10 and win_version.Build < 15063)): |
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.
At column 13: (E128) continuation line under-indented for visual indent
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.
Awesome - Nicely done, and thanks for the contribution!
If you're still in this DPI hole, you might want to investigate why the font sizes in tutorial1 aren't adapting to DPI sizing... but that's not related to this patch.
Changed the app.py create method for toga_winforms to check the current OS Version and build number to make sure we are using the most up to date DPI setting API for the user. Came across this issue when updating windows to the 1903 update (Build #: 18362)
PR Checklist: