Skip to content
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

Improved DPI Scaling on Windows and Fixed related Bugs #2155

Merged
merged 128 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
184d5d4
Fixed bug in call of SetProcessDpiAwarenessContext
proneon267 Oct 15, 2023
986804f
Added a changelog.
proneon267 Oct 15, 2023
5967db9
Fixed winforms scaling bugs.
proneon267 Oct 16, 2023
a9f740b
Updated changelog.
proneon267 Oct 16, 2023
c1bdf9d
Added event handler to detect dpi change when live.
proneon267 Oct 18, 2023
196bf77
Merge branch 'patch-20' of https://github.com/proneon267/toga into pa…
proneon267 Oct 18, 2023
29a55d3
Merge branch 'main' into patch-20
proneon267 Oct 18, 2023
ff23b17
Empty commit for CI/CD
proneon267 Oct 18, 2023
afccfc6
Updated changelog
proneon267 Oct 18, 2023
94dce84
Added support for font scaling based on DPI change
proneon267 Oct 21, 2023
65c6bd7
Empty commit
proneon267 Oct 21, 2023
21d1f56
Miscellaneous fixes
proneon267 Oct 21, 2023
fcfe409
Merge branch 'beeware:main' into patch-20
proneon267 Oct 21, 2023
0129035
Merge branch 'beeware:main' into patch-20
proneon267 Oct 23, 2023
ebd1c29
Fixed Hwnd Related Bugs.
proneon267 Oct 23, 2023
4e4addc
Fixed menubar clipping bug.
proneon267 Oct 23, 2023
7aeeb7c
Miscellaneous fixes
proneon267 Oct 23, 2023
0ff2ec6
Empty commit for CI
proneon267 Oct 23, 2023
1012ac5
Merge branch 'beeware:main' into patch-20
proneon267 Oct 25, 2023
1393b7d
Empty commit for CI
proneon267 Oct 26, 2023
796db51
Added Support for Scaling Stack Trace Dialogs.
proneon267 Oct 27, 2023
ec7617d
Miscellaneous fixes
proneon267 Oct 27, 2023
a4ff196
Miscellaneous fixes
proneon267 Oct 27, 2023
9e3685a
Miscellaneous fixes
proneon267 Oct 27, 2023
20b6793
Merge branch 'main' into patch-20
proneon267 Nov 1, 2023
4619553
Merge branch 'main' into patch-20
proneon267 Nov 3, 2023
6f8019c
Empty commit for CI
proneon267 Nov 3, 2023
407156e
Added support for scaling window toolbar
proneon267 Nov 3, 2023
550839c
Added tests
proneon267 Nov 5, 2023
392487a
Miscellaneous fixes
proneon267 Nov 5, 2023
2d59078
Fixed tests
proneon267 Nov 6, 2023
d54bc4d
Merge branch 'beeware:main' into patch-20
proneon267 Nov 7, 2023
c45aa2e
Modified scaling code
proneon267 Nov 7, 2023
1714095
Merge branch 'patch-20' of https://github.com/proneon267/toga into pa…
proneon267 Nov 7, 2023
5c512cb
Fixed Stack Trace Dialog Scaling issues
proneon267 Nov 9, 2023
cbdc69a
Miscellaneous Fixes
proneon267 Nov 9, 2023
2ae714f
Merge branch 'main' into patch-20
proneon267 Nov 9, 2023
a285a53
Merge branch 'patch-20' of https://github.com/proneon267/toga into HEAD
proneon267 Nov 9, 2023
c5fb1b0
Miscellaneous Fixes
proneon267 Nov 9, 2023
469f287
Merge branch 'main' into patch-20
proneon267 Nov 9, 2023
9929c3a
Merge branch 'patch-20' of https://github.com/proneon267/toga into HEAD
proneon267 Nov 9, 2023
ab754c2
Merge branch 'main' into patch-20
proneon267 Nov 9, 2023
a670a2a
Miscellaneous Fixes
proneon267 Nov 9, 2023
eeeeaa3
Merge branch 'patch-20' of https://github.com/proneon267/toga into dp…
proneon267 Nov 9, 2023
d2e5948
Fixed tests
proneon267 Nov 9, 2023
6aa68d7
Empty commit for CI
proneon267 Nov 9, 2023
083d9da
Added scaling support for moving between screens.
proneon267 Nov 9, 2023
f1ddd6f
Empty commit for CI
proneon267 Nov 9, 2023
0325388
Empty commit for CI
proneon267 Nov 9, 2023
7527b39
Miscellaneous Fixes
proneon267 Nov 11, 2023
4b7791b
Miscellaneous Fixes
proneon267 Nov 11, 2023
995819b
Merge branch 'beeware:main' into patch-20
proneon267 Nov 11, 2023
8c422e8
Miscellaneous Fixes
proneon267 Nov 11, 2023
0eb366a
Merge branch 'main' into patch-20
proneon267 Nov 12, 2023
c7b2f19
Merge branch 'beeware:main' into patch-20
proneon267 Nov 14, 2023
30b088b
Merge branch 'beeware:main' into patch-20
proneon267 Nov 15, 2023
3e7bdea
Merge branch 'main' into patch-20
proneon267 Nov 25, 2023
ee76a14
Miscellaneous Fixes
proneon267 Nov 29, 2023
d92d929
Miscellaneous Fixes
proneon267 Nov 29, 2023
48cd2bf
Merge branch 'beeware:main' into patch-20
proneon267 Dec 2, 2023
0a9e732
Merge branch 'beeware:main' into patch-20
proneon267 Dec 10, 2023
de079fa
Merge branch 'main' into patch-20
proneon267 Dec 17, 2023
81a04ae
Miscellaneous Fixes
proneon267 Dec 17, 2023
279458f
Merge branch 'beeware:main' into patch-20
proneon267 Dec 18, 2023
2e16e16
Merge branch 'beeware:main' into patch-20
proneon267 Dec 22, 2023
acf13d3
Miscellaneous Fixes
proneon267 Dec 22, 2023
c97df03
Merge branch 'beeware:main' into patch-20
proneon267 Jan 13, 2024
b8db567
Merge branch 'beeware:main' into patch-20
proneon267 Jan 14, 2024
4086055
Merge branch 'beeware:main' into patch-20
proneon267 Jan 17, 2024
85bcb6b
Merge branch 'beeware:main' into patch-20
proneon267 Jan 17, 2024
4d77f3f
Merge branch 'beeware:main' into patch-20
proneon267 Jan 20, 2024
7842aff
Empty commit for CI
proneon267 Jan 21, 2024
4f4f988
Merge branch 'beeware:main' into patch-20
proneon267 Jan 25, 2024
c529e5f
Merge branch 'beeware:main' into patch-20
proneon267 Feb 3, 2024
46eb4a9
Misc Fixes
proneon267 Feb 3, 2024
3090935
Removed dialog scaling
proneon267 Feb 6, 2024
a99b83a
Misc Fixes
proneon267 Feb 6, 2024
71d06b5
Misc Fixes
proneon267 Feb 6, 2024
fd718a2
Merge branch 'beeware:main' into patch-20
proneon267 Feb 9, 2024
d0b7f0e
Corrected windows implementation
proneon267 Feb 10, 2024
6ceb39d
Updated to latest main branch
proneon267 Feb 11, 2024
03062b9
Corrected winforms screens dpi scaling
proneon267 Feb 11, 2024
69f83cc
Corrected winforms tests_backend to detect dpi scale
proneon267 Feb 11, 2024
65e6144
Corrected winforms dpi scaling
proneon267 Feb 11, 2024
b6451f5
Corrected winforms tests_backend dpi scaling
proneon267 Feb 11, 2024
8cf5eef
Corrected winforms tests_backend dpi scaling
proneon267 Feb 11, 2024
6a0b6d7
Empty commit for CI
proneon267 Feb 11, 2024
18bc25d
Empty commit for CI
proneon267 Feb 11, 2024
87c88af
Merge branch 'main' into patch-20
proneon267 Mar 21, 2024
6713490
updated to latest main branch
proneon267 Mar 21, 2024
c873366
updated to latest main branch
proneon267 Mar 21, 2024
fac093d
Merge branch 'beeware:main' into patch-20
proneon267 Apr 2, 2024
3084c42
Merge remote-tracking branch 'remotes/origin/main' into patch-20
mhsmith Apr 3, 2024
31e54c9
Fix StackTraceDialog scaling
mhsmith Apr 3, 2024
c793d64
Fix various scaling bugs
mhsmith Apr 4, 2024
c44fef0
Merge branch 'beeware:main' into patch-20
proneon267 Apr 14, 2024
64221ab
Fixed reported dpi scaling bugs
proneon267 Apr 14, 2024
12a70d1
Fixed tests
proneon267 Apr 15, 2024
2cd6213
Empty commit for CI
proneon267 Apr 15, 2024
7c8a9b8
Empty commit for CI
proneon267 Apr 15, 2024
69054c1
Fixed remaining errors
proneon267 Apr 26, 2024
5e58f35
Fixed test
proneon267 Apr 28, 2024
ae20798
Merge branch 'main' into patch-20
proneon267 May 7, 2024
ff6223c
Modified DPI change test
proneon267 May 15, 2024
1313d7e
Fixed DPI change test
proneon267 May 15, 2024
a53a820
Merge branch 'beeware:main' into patch-20
proneon267 May 15, 2024
f3db6ff
Merge branch 'beeware:main' into patch-20
proneon267 Jun 1, 2024
afdbb30
Merge branch 'main' into patch-20
proneon267 Jun 12, 2024
37e1add
Merge branch 'main' into patch-20
proneon267 Jun 17, 2024
9d199f5
Merge branch 'main' into patch-20
proneon267 Jul 10, 2024
41574d4
Updated to latest main branch
proneon267 Jul 10, 2024
9455196
Updated to latest main branch
proneon267 Jul 10, 2024
767e35e
Fixed winforms
proneon267 Jul 10, 2024
a30a8e3
Update 2155.bugfix.rst
proneon267 Jul 11, 2024
a4eb081
Merge branch 'beeware:main' into patch-20
proneon267 Jul 19, 2024
d228109
Merge branch 'main' into patch-20
proneon267 Oct 4, 2024
c4d5c5e
Parameterized test
proneon267 Oct 13, 2024
b7b1061
Merge branch 'beeware:main' into patch-20
proneon267 Oct 13, 2024
83159fe
Parameterized test
proneon267 Oct 13, 2024
0800f3f
Revert unnecessary change to iOS
mhsmith Oct 30, 2024
ddd61db
Merge remote-tracking branch 'remotes/origin/main' into patch-20
mhsmith Nov 3, 2024
617c4fe
Various cleanups and fixes
mhsmith Nov 3, 2024
44f9124
Rewrite DPI tests
mhsmith Nov 6, 2024
ca540a4
Add test of DisplaySettingsChanged event
mhsmith Nov 6, 2024
1188ff9
Correct font scaling
mhsmith Nov 7, 2024
99d1f76
Avoid redundant refreshes on DPI changes
mhsmith Nov 9, 2024
fcbae32
Add tests of menubar and toolbar scaling
mhsmith Nov 10, 2024
066d5b6
Fix scaling of Window/Screen position/size
mhsmith Nov 10, 2024
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
1 change: 1 addition & 0 deletions changes/2155.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DPI scaling on Windows is now improved and related bugs are fixed.
14 changes: 10 additions & 4 deletions core/src/toga/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __str__(self) -> str:


class Position(NamedTuple):
"""A 2D window position."""
"""A 2D position."""

#: X coordinate, in CSS pixels.
x: int
Expand All @@ -46,15 +46,21 @@ def __add__(self, other):
def __sub__(self, other):
return Position(self.x - other.x, self.y - other.y)

def __mul__(self, other):
return Position(self.x * other, self.y * other)


class Size(NamedTuple):
"""A 2D window size."""
"""A 2D size."""

#: Width
#: Width, in CSS pixels.
width: int

#: Height
#: Height, in CSS pixels.
height: int

def __str__(self) -> str:
return f"({self.width} x {self.height})"

def __mul__(self, other):
return Size(self.width * other, self.height * other)
23 changes: 22 additions & 1 deletion core/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ def test_position_properties():
assert p.x == 1
assert p.y == 2
assert str(p) == "(1, 2)"
p == (1, 2) # Tuple equivalence for backwards-compatibility

assert p == Position(1, 2)
assert p != Position(1, 3)

assert p == (1, 2) # Tuple equivalence for backwards-compatibility
assert p != (1, 3)


def test_add_positions():
Expand All @@ -20,10 +25,26 @@ def test_sub_positions():
assert Position(1, 2) - Position(3, 4) == Position(-2, -2)


def test_mul_position():
"""Multiplying a Position multiplies its X and Y values"""
assert Position(1, 2) * 2 == Position(2, 4)
assert Position(1, 2) * 0.5 == Position(0.5, 1)
assert Position(1, 2) * 0 == Position(0, 0)
assert Position(1, 2) * -1 == Position(-1, -2)


def test_size_properties():
"""A Size NamedTuple has a width and height."""
s = Size(1, 2)
assert s.width == 1
assert s.height == 2
assert str(s) == "(1 x 2)"
s == (1, 2) # Tuple equivalence for backwards-compatibility


def test_mul_size():
"""Multiplying a Size multiplies its width and height values"""
assert Size(1, 2) * 2 == Size(2, 4)
assert Size(1, 2) * 0.5 == Size(0.5, 1)
assert Size(1, 2) * 0 == Size(0, 0)
assert Size(1, 2) * -1 == Size(-1, -2)
3 changes: 1 addition & 2 deletions examples/command/command/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ def startup(self):
cmd5 = toga.Command(
self.action5,
text="TB Action 5",
tooltip="Perform toolbar action 5",
order=2,
group=sub_menu,
) # there is deliberately no icon to show that a toolbar action also works with text
) # there is deliberately no icon or tooltip
cmd6 = toga.Command(
self.action6,
text="Action 6",
Expand Down
117 changes: 87 additions & 30 deletions examples/window/window/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,79 @@
from functools import partial

import toga
from toga.constants import COLUMN, RIGHT
from toga.constants import COLUMN, RIGHT, ROW
from toga.style import Pack


class WindowDemoApp(toga.App):
# Button callback functions
def do_origin(self, widget, **kwargs):
self.main_window.position = (0, 0)
self.do_report()

def do_up(self, widget, **kwargs):
self.main_window.position = (
self.main_window.position.x,
self.main_window.position.y - 200,
)
self.do_report()

def do_down(self, widget, **kwargs):
self.main_window.position = (
self.main_window.position.x,
self.main_window.position.y + 200,
)
self.do_report()

def do_left(self, widget, **kwargs):
self.main_window.position = (-1000, 500)
self.main_window.position = (
self.main_window.position.x - 200,
self.main_window.position.y,
)
self.do_report()

def do_right(self, widget, **kwargs):
self.main_window.position = (2000, 500)
self.main_window.position = (
self.main_window.position.x + 200,
self.main_window.position.y,
)
self.do_report()

def do_left_current_screen(self, widget, **kwargs):
self.main_window.screen_position = (0, 100)
def do_screen_top(self, widget, **kwargs):
self.main_window.screen_position = (
self.main_window.screen_position.x,
0,
)
self.do_report()

def do_screen_bottom(self, widget, **kwargs):
self.main_window.screen_position = (
self.main_window.screen_position.x,
self.main_window.screen.size.height - self.main_window.size.height,
)
self.do_report()

def do_right_current_screen(self, widget, **kwargs):
self.main_window.screen_position = (1080, 100)
def do_screen_left(self, widget, **kwargs):
self.main_window.screen_position = (
0,
self.main_window.screen_position.y,
)
self.do_report()

def do_screen_right(self, widget, **kwargs):
self.main_window.screen_position = (
self.main_window.screen.size.width - self.main_window.size.width,
self.main_window.screen_position.y,
)
self.do_report()

def do_small(self, widget, **kwargs):
self.main_window.size = (400, 300)
self.do_report()

def do_large(self, widget, **kwargs):
self.main_window.size = (1500, 1000)
self.do_report()

def do_app_full_screen(self, widget, **kwargs):
if self.is_full_screen:
Expand Down Expand Up @@ -85,6 +132,7 @@ def do_new_windows(self, widget, **kwargs):

def do_screen_change(self, screen, widget, **kwargs):
self.current_window.screen = screen
self.do_report()

async def do_save_screenshot(self, screen, window, **kwargs):
screenshot = screen.as_image()
Expand Down Expand Up @@ -112,11 +160,14 @@ async def do_hide_cursor(self, widget, **kwargs):
self.show_cursor()
self.label.text = "Cursor should be back!"

def do_report(self, widget, **kwargs):
def do_report(self, *args, **kwargs):
window = self.main_window
screen = window.screen
self.label.text = (
f"Window {self.main_window.title!r} "
f"has size {self.main_window.size!r} "
f"at {self.main_window.position!r}"
f"Window: size={tuple(window.size)}, position={tuple(window.position)}, "
f"screen_position={tuple(window.screen_position)}\n"
f"Screen: name={screen.name!r}, size={tuple(screen.size)}, "
f"origin={tuple(screen.origin)}"
)

def do_next_content(self, widget):
Expand Down Expand Up @@ -166,21 +217,30 @@ def startup(self):

# Buttons
btn_style = Pack(flex=1, padding=5)
btn_do_origin = toga.Button(
"Go to origin", on_press=self.do_origin, style=btn_style
)
btn_do_left = toga.Button("Go left", on_press=self.do_left, style=btn_style)
btn_do_right = toga.Button("Go right", on_press=self.do_right, style=btn_style)
btn_do_left_current_screen = toga.Button(
"Go left on current screen",
on_press=self.do_left_current_screen,
style=btn_style,

row_move = toga.Box(
style=Pack(direction=ROW),
children=[
toga.Label("Move: "),
toga.Button("Origin", on_press=self.do_origin, style=btn_style),
toga.Button("Up", on_press=self.do_up, style=btn_style),
toga.Button("Down", on_press=self.do_down, style=btn_style),
toga.Button("Left", on_press=self.do_left, style=btn_style),
toga.Button("Right", on_press=self.do_right, style=btn_style),
],
)
btn_do_right_current_screen = toga.Button(
"Go right on current screen",
on_press=self.do_right_current_screen,
style=btn_style,

row_screen_edge = toga.Box(
style=Pack(direction=ROW),
children=[
toga.Label("Screen edge: "),
toga.Button("Top", on_press=self.do_screen_top, style=btn_style),
toga.Button("Bottom", on_press=self.do_screen_bottom, style=btn_style),
toga.Button("Left", on_press=self.do_screen_left, style=btn_style),
toga.Button("Right", on_press=self.do_screen_right, style=btn_style),
],
)

btn_do_small = toga.Button(
"Become small", on_press=self.do_small, style=btn_style
)
Expand Down Expand Up @@ -256,11 +316,9 @@ def startup(self):
self.inner_box = toga.Box(
children=[
self.label,
btn_do_origin,
btn_do_left,
btn_do_right,
btn_do_left_current_screen,
btn_do_right_current_screen,
row_move,
row_screen_edge,
btn_do_report,
btn_do_small,
btn_do_large,
btn_do_app_full_screen,
Expand All @@ -269,7 +327,6 @@ def startup(self):
btn_do_new_windows,
btn_do_current_window_cycling,
btn_do_hide_cursor,
btn_do_report,
btn_change_content,
btn_hide,
btn_beep,
Expand Down
Loading