Skip to content

Windows 10/11 Calculator: report correct number after paste by fetching the value directly from the UI element.#16672

Merged
seanbudd merged 13 commits into
nvaccess:masterfrom
tburc:fix-16573
Jun 20, 2024
Merged

Windows 10/11 Calculator: report correct number after paste by fetching the value directly from the UI element.#16672
seanbudd merged 13 commits into
nvaccess:masterfrom
tburc:fix-16573

Conversation

@tburc

@tburc tburc commented Jun 9, 2024

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #16573

Summary of the issue:

When pasting into the calculator, both speech and braille reported a truncated result (for example 1 instead of 12.34)

Description of user facing changes

When pasting into the Windows 10/11 calculator, the correct number is announced.

Description of development approach

  • While handling UIA notification events, NVDA may announce screen changes not caused by number entry or results commands, and this is what is being handled (pasting from clipboard, for example).
  • NVDA will traverse through result element's children, looking for the actual result.
  • NVDA will announce the element's content once actual result element is identified.

Testing strategy:

Manual testing. Specifically, test to make sure that NVDA is announcing the whole number when pasted (example: 12.34 instead of just 1). Also, make sure that NVDA only announces said number once.

Known issues with pull request:

Nothing I can think of.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

Summary by CodeRabbit

  • New Features
    • Improved NVDA screen reader support for Windows 10/11 Calculator. NVDA now correctly reports the full number pasted into the calculator.

@tburc tburc marked this pull request as ready for review June 9, 2024 18:56
@tburc tburc requested a review from a team as a code owner June 9, 2024 18:56
@tburc tburc requested a review from gerald-hartig June 9, 2024 18:56
@josephsl

josephsl commented Jun 9, 2024

Copy link
Copy Markdown
Contributor

Hello Tristan,

Thank you for your first contribution. As the original author of Calculator app module, I appreciate the effort taken to resolve this issue and update the code logic (and thank you for pointing out how tricky the logic is).

A few general comments:

  • I love the honesty when you put "trial and error" in development strategy (yep, even experienced project members write that, so you are not alone). In the future, please provide at least a high-level overview of the proposed code changes (for an example, see Windows 11 emoji panel/navigation menu item: handle UIA elemenet selected event by ignoring it or manipulating NVDA's focus object #16555)..
  • Calculator app module contents came from an NVDA add-on called Windows App Essentials (https://github.com/josephsl/wintenapps). When you read the commit log for that project, you will see some emotional content, including frustrations with app accessibility and usability.
  • Speaking of code and its origins, the tricky logic part stems from "debates" between Microsoft, apps, yours truly, and NVDA - whenever Microsoft made changes to their apps, I would test them and offer feedback on accessibility for screen reader users, explaining how the code is organized and not so organized at the same time (my apologies); this is a side effect of Windows as a Service (WaaS) era - continuous development, continuous refinements, ongoing hunt for accessibility and usability issues.

Enough musings - if I understand the proposed code changes correctly:

  1. While handling UIA notification events, NVDA may announce screen changes not caused by numer entry or results commands, and this is what is being handled (pasting from clipboard, for example).
  2. NVDA will traverse through result element's children, looking for actual result text (using a for loop is smart).
  3. NVDA will announce element content once actual result element is identified.

I don't expect new folks to be as detailed as above. I'll provide specific comments in the code fragments.

Thanks.

@josephsl josephsl requested review from josephsl and removed request for gerald-hartig June 9, 2024 20:11

@josephsl josephsl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks good. I advise reading NVDA development guide (or additional parts of the source code) so you can learn a few tricks here and there (one of them is ui.message which allows NVDA to both speak and braille whatever). If you have time, please do read Git commit logs for Windows App Essentials add-on so you can see how the Calculator ap module came to be.

Comment thread source/appModules/calculator.py Outdated
"""App module for Windows 10 Calculator.
This is also the base app module for Windows 11 Calculator."""

# This file has some fairly tricky logic, so here is a test plan to make sure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to write a test plan in the app module files - I think we should open a new discussion on adding test plans for Microsoft Store apps such as Calculator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I deleted the test plan for now. If the team does eventually decide you'd like to have such a thing, I'm happy to re-add it wherever you think it should go.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add manual test plans to tests/manual. Manual test plans are welcome per the contributing guide https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/githubPullRequestTemplateExplanationAndExamples.md#code-review-checklist

# (for example "Display is 1" when it should be "Display is 12.34").
# To fix this, we ignore the displayString sent via the UIA notification,
# and fetch the value directly from the UI element.
for child in resultElement.children:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - in full screen, expression text is marked as first child, whereas in compact (mini) mode, actual results text is the first child.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread source/appModules/calculator.py Outdated
# To fix this, we ignore the displayString sent via the UIA notification,
# and fetch the value directly from the UI element.
for child in resultElement.children:
if child.UIAAutomationId in ("CalculatorResults", "CalculatorAlwaysOnTopResults"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if the display string reported by UIA notification is the same as what's shown on screen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand that situation you're considering, but I think the fix would still be applicable to that situation. For example, if you type "1+2=", the calculator will still show the correct answer and NVDA will report it correctly as well. The UIA notification in this scenario would set displayText="Display is 3", and that string is exactly the same as what we would pull from the element itself. So effectively, if the previous UIA notification was correct, then this does not change any behavior.

@seanbudd

Copy link
Copy Markdown
Member

Hello Tristan, please use a descriptive title that explains what the PR does standalone.

@seanbudd seanbudd changed the title Fix 16573 Fix pasting bug for calculator Jun 10, 2024
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Jun 11, 2024
@tburc tburc changed the title Fix pasting bug for calculator Windows 10/11 Calculator: report correct number after paste by fetching the value directly from the UI element. Jun 11, 2024
@tburc

tburc commented Jun 11, 2024

Copy link
Copy Markdown
Contributor Author

@josephsl thanks so much for your insightful and kind comments. The code is quite good and I particularly appreciated how well commented it is. It must have taken a lot of work to get it to this point. This is my first time working with the NVDA project so I'm just not used to all the patterns involved.

@josephsl

Copy link
Copy Markdown
Contributor

Hello Tristan,

At least we got the basics of the fix right, and thank you for your willingness to think about our feedback/comments.

I'm known for writing lots of comments in my own code - maybe I can't "keep my mouth shut" while programming... I think programming is a variation on writing essays (more so if you think about Python syntax and grammar). After all, working on apps like Calculator gave me writing materials in graduate school (I am attending a university in western United States).

About the for loop logic: consider the following scenario:

  1. User presses Escape to clear Calculator display string.
  2. A UIA notification event is fired.
  3. NVDA notices that it can announce the display string since the last entered command is not a number.
  4. The just proposed code (for loop) runs, announcing "display is 0".
  5. Somehow notification event is handled once again, either becuase Calculator fired it or NVDA itself is handling it (again).
  6. The display string announcmenet may repeat.

The key is checking for value equality (== versus !=); a possible optimization is that NVDA doesn't have to fall back to default UIA notification event handling implementation (where it will report whatever the display string is as long as the element is focused on screen). This is what the call to "nextHandler" is - NVDA's event handling system could be viewed as an iterative "chain" where different modules can observe and handle events if they want to, otherwise default behavior (such as announcing things) will be performed. I think we can safely ignore this odd thing in this PR.

If you want this to be part of NVDA 2024.3, I advise adding a changelog entry (we use Markdown syntax); if you want it in the next release after that, wait until 2024.3 enters beta phase (or shortly before) once NV Access people updates NVDA version in the source code. Then mark this PR as ready for review. Of course, since the issue may as well lie with Calculator executable itself, sending a "love letter" a.k.a. feedback to Microsoft from time to time about UIA notification event issue would be nice too.

Thanks.

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an entry to the changelog.
The general approach here looks good to me for the code changes.

Comment thread source/appModules/calculator.py
Comment thread source/appModules/calculator.py Outdated
"""App module for Windows 10 Calculator.
This is also the base app module for Windows 11 Calculator."""

# This file has some fairly tricky logic, so here is a test plan to make sure

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add manual test plans to tests/manual. Manual test plans are welcome per the contributing guide https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/githubPullRequestTemplateExplanationAndExamples.md#code-review-checklist

Comment thread source/appModules/calculator.py Outdated
@seanbudd seanbudd marked this pull request as draft June 11, 2024 04:05
@tburc

tburc commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

Please add an entry to the changelog. The general approach here looks good to me for the code changes.

Done.

@tburc

tburc commented Jun 20, 2024

Copy link
Copy Markdown
Contributor Author

About the for loop logic: consider the following scenario:

  1. User presses Escape to clear Calculator display string.
  2. A UIA notification event is fired.
  3. NVDA notices that it can announce the display string since the last entered command is not a number.
  4. The just proposed code (for loop) runs, announcing "display is 0".
  5. Somehow notification event is handled once again, either becuase Calculator fired it or NVDA itself is handling it (again).
  6. The display string announcement may repeat.

Using speech.cancelSpeech() eliminates the issue of duplicated speech announcements from UIA notifications. In fact, when pasting into the calculator, this is exactly what happens -- you get two notifications. So that's why I added the cancelSpeech() call.

@seanbudd seanbudd marked this pull request as ready for review June 20, 2024 02:14
@coderabbitai

coderabbitai Bot commented Jun 20, 2024

Copy link
Copy Markdown
Contributor

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

Commits

Files that changed from the base of the PR and between 49a9757 and 0548aa5.

Files selected for processing (2)
  • source/appModules/calculator.py (2 hunks)
  • user_docs/en/changes.md (1 hunks)
 __________________________________________________________________________________________________________________________________________
< Test early. Test often. Test automatically. Tests that run with every build are much more effective than test plans that sit on a shelf. >
 ------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@seanbudd seanbudd merged commit e43e7c8 into nvaccess:master Jun 20, 2024
@tburc tburc deleted the fix-16573 branch July 20, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows 10/11 Calculator: NVDA does not announce the entire expression when pasting it from the clipboard

3 participants