-
-
Notifications
You must be signed in to change notification settings - Fork 801
Block touch input while the magnifier is running #20357
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
Open
Boumtchack
wants to merge
9
commits into
nvaccess:beta
Choose a base branch
from
France-Travail:feature/disableTouchscreen
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b40ff7
touchscreen first draft
Boumtchack fa66cab
unit tests
Boumtchack 67e098a
Merge branch 'beta' into feature/disableTouchscreen
Boumtchack ce3a3b0
changed approach
Boumtchack 3215ead
Merge branch 'beta' into feature/disableTouchscreen
Boumtchack 9befad6
review modifications
Boumtchack fb3ecd3
review
Boumtchack c2093e4
review ruff
Boumtchack 2ca6058
refactoring
Boumtchack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # A part of NonVisual Desktop Access (NVDA) | ||
| # Copyright (C) 2025-2026 NV Access Limited, Antoine Haffreingue | ||
| # This file may be used under the terms of the GNU General Public License, version 2 or later, as modified by the NVDA license. | ||
| # For full terms and any additional permissions, see the NVDA license file: https://github.com/nvaccess/nvda/blob/master/copying.txt | ||
|
|
||
| from _magnifier.magnifier import Magnifier | ||
| from _magnifier.utils.types import Coordinates | ||
| from tests.unit.test_magnifier.test_magnifier import _TestMagnifier | ||
| import touchHandler | ||
| from winAPI._displayTracking import getPrimaryDisplayOrientation | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
|
|
||
| class TestMagnifierTouchscreen(_TestMagnifier): | ||
| """Tests for touchscreen blocking/warning behaviour when the magnifier starts and stops.""" | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.magnifier = Magnifier() | ||
| screenDimensions = getPrimaryDisplayOrientation() | ||
| self.focusCoords = Coordinates(screenDimensions.width // 2, screenDimensions.height // 2) | ||
| self.magnifier._focusManager.getCurrentFocusCoordinates = MagicMock(return_value=self.focusCoords) | ||
|
|
||
| def tearDown(self): | ||
| if hasattr(self.magnifier, "_timer") and self.magnifier._timer: | ||
| self.magnifier._timer.Stop() | ||
| self.magnifier._timer = None | ||
| if hasattr(self.magnifier, "_isActive") and self.magnifier._isActive: | ||
| self.magnifier._isActive = False | ||
| super().tearDown() | ||
|
|
||
| def testStartMagnifierBlocksTouchWhenHandlerActive(self): | ||
| """blockTouchInput is set when the magnifier starts with the touch handler running.""" | ||
| with ( | ||
| patch("touchHandler.handler", new=MagicMock()), | ||
| patch("touchHandler.blockTouchInput", False), | ||
| ): | ||
| self.magnifier._startMagnifier() | ||
| self.assertTrue(touchHandler.blockTouchInput) | ||
|
|
||
| def testStartMagnifierWarnsWhenTouchSupportDisabled(self): | ||
| """Dialog shown when device has a touchscreen but NVDA touch support is disabled.""" | ||
| with ( | ||
| patch("touchHandler.handler", new=None), | ||
| patch("winBindings.user32.GetSystemMetrics", return_value=5), | ||
| patch("touchHandler.touchSupported", return_value=True), | ||
| patch("_magnifier.magnifier.wx.CallAfter") as mock_call_after, | ||
| ): | ||
| self.magnifier._startMagnifier() | ||
|
|
||
| mock_call_after.assert_called_once() | ||
|
|
||
| def testStartMagnifierWarnsOnPortableOrNoUIAccess(self): | ||
| """Dialog shown when device has a touchscreen but NVDA cannot intercept (portable/no UI access).""" | ||
| with ( | ||
| patch("touchHandler.handler", new=None), | ||
| patch("winBindings.user32.GetSystemMetrics", return_value=5), | ||
| patch("touchHandler.touchSupported", return_value=False), | ||
| patch("_magnifier.magnifier.wx.CallAfter") as mock_call_after, | ||
| ): | ||
| self.magnifier._startMagnifier() | ||
|
|
||
| mock_call_after.assert_called_once() | ||
|
|
||
| def testStartMagnifierNoActionWithoutTouchscreen(self): | ||
| """No dialog and no blocking when the device has no touchscreen.""" | ||
| with ( | ||
| patch("touchHandler.handler", new=None), | ||
| patch("winBindings.user32.GetSystemMetrics", return_value=0), | ||
| patch("_magnifier.magnifier.wx.CallAfter") as mock_call_after, | ||
| ): | ||
| self.magnifier._startMagnifier() | ||
|
|
||
| mock_call_after.assert_not_called() | ||
|
|
||
| def testStopMagnifierUnblocksTouchInput(self): | ||
| """blockTouchInput is reset to False when the magnifier stops with the touch handler active.""" | ||
| self.magnifier._stopTimer = MagicMock() | ||
| self.magnifier._isActive = True | ||
| touchHandler.blockTouchInput = True | ||
| self.addCleanup(setattr, touchHandler, "blockTouchInput", False) | ||
|
|
||
| with patch("touchHandler.handler", new=MagicMock()): | ||
| self.magnifier._stopMagnifier() | ||
|
|
||
| self.assertFalse(touchHandler.blockTouchInput) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
this still seems to be unnecessarily duplicating setup/tearDown from
TestMagnifierThere 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 think tests could use a good clean up regarding all the changes that have been made since the start, I would say we let this like that and I'll do a big clean up in the future
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.
Can we make base class and use it across these two test suites? I'm not asking for a full refactor, just for the changed/added code. We try to fix things incrementally when we touch them rather than do large scale refactors.