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

Refactor BrailleHandler.setDisplayByName #14524

Merged
merged 15 commits into from Feb 13, 2023

Conversation

LeonarddeR
Copy link
Collaborator

@LeonarddeR LeonarddeR commented Jan 9, 2023

Link to issue number:

None

Summary of the issue:

braille.BrailleHandler.setDisplayname is too complex. It also relies on reentrancy and is difficult to grasp.

Description of user facing changes

See bug fixes below

Description of development approach

  • setDisplayByName is now split in three functions
  • setDisplayByName will no longer set noBraille as a fallback if noBraille is already active. This avoids reinitializing noBraille multiple times
  • BrailleHandler._detectionEnabled is removed, as it was supposed to be equal to the boolean value of BrailleHandler._detector and that value was checked anyway. Note that that's supposed to be private API
  • When configuration was set to auto detect, BrailleHandler.handleDisplayUnavailable relied on behavior in setDisplayByName to re-enable the detector when falling back to no braille. This logic is now simplified.

Testing strategy:

  • Ensure that auto detection works over USB
  • Ensure that auto detection works over Bluetooth
  • Ensure that when a display was detected over Bluetooth, the detector is still running for USB in order to switch when an USB connection is active
  • Ensure that auto detection will be activated when a display looses connectivity and autodetect is in config

Known issues with pull request:

None known

Change log entries:

Bug fixes

Code Review Checklist:

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

@LeonarddeR LeonarddeR requested a review from a team as a code owner January 9, 2023 10:30
@LeonarddeR LeonarddeR marked this pull request as draft January 9, 2023 10:30
@LeonarddeR LeonarddeR marked this pull request as ready for review January 9, 2023 11:01
@AppVeyorBot
Copy link

See test results for failed build of commit d349afb9d3

@seanbudd seanbudd added the merge-early Merge Early in a developer cycle label Jan 9, 2023
@seanbudd seanbudd added this to the 2023.2 milestone Jan 9, 2023
Copy link
Member

@seanbudd seanbudd left a comment

Choose a reason for hiding this comment

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

Hi @LeonarddeR, the approach looks good to me, just minor suggestions.

Due to the risk of this PR, I think we should merge it after #14512

source/braille.py Outdated Show resolved Hide resolved
source/braille.py Outdated Show resolved Hide resolved
source/braille.py Outdated Show resolved Hide resolved
source/braille.py Outdated Show resolved Hide resolved
source/braille.py Outdated Show resolved Hide resolved
source/braille.py Outdated Show resolved Hide resolved
@seanbudd seanbudd marked this pull request as draft January 9, 2023 23:48
@LeonarddeR
Copy link
Collaborator Author

@seanbudd Thanks for the review.
I removed the change to handlePostConfigProfileSwitch as I realized that every display supporting port selection will have its port defined in config, also when it is automatic. Given no complaint about this anyway, let's leave it as is.

@LeonarddeR LeonarddeR marked this pull request as ready for review January 10, 2023 11:36
Copy link
Member

@seanbudd seanbudd left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM, will merge once we branch for release

source/braille.py Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

See test results for failed build of commit 7e3b7ecec9

@seanbudd seanbudd removed the blocked label Feb 13, 2023
@seanbudd seanbudd merged commit 17cd891 into nvaccess:master Feb 13, 2023
seanbudd pushed a commit that referenced this pull request Feb 14, 2023
…14531)

Related to #3564, #2315

Summary of the issue:
Currently, USB and Bluetooth devices are supported for braille display detection. Other devices using other protocols or software devices aren't supported. This pr intends to add support for this.

Description of user facing changes
None. User shouldn't experience anything different for now.

Description of development approach
Added Chain, a new extension point type that allows to register handlers that return iterables (mainly generators). Calling iter on the Chain returns a generator that iterates over all the handlers.
The braille display detector now relies on a new Chain. By default, functions are registered to the chain that yield usb and bluetooth devices. A custom provider can yield own driver names and device matches that are supported by that particular driver. A potential use case would be implementing automatic detection for displays using BRLTTY, for example. It will also be used to fix Braille does not work on secure Windows screens while normal copy of NVDA is running #2315 (see below)
Added a moveToEnd method on HandlerRegistrar, which allows changing the order of registered handlers. This allows add-ons to give priority to their handlers, which is especially helpful for both Chain and Filter. NVDA Remote should come for the braille viewer, otherwise controlling a system with braille viewer on with a 80 cell display connected to the controller would lower the display size to 40 unnecessarily. This will also be used to register a custom handler to bdDetect.scanForDevices to support auto detection of the user display on the secure screen instance of NVDA, which should come before USB and Bluetooth.
As a bonus, added type hints to extension points. For Filters and Chains, you could provide the value type and then a type checker can check validity.
As another bonus, all features are covered by new tests. So there are tests for the Chain extension point and for the specific use case in bdDetect
Testing strategy:
As this touches braille display auto detection quite a lot, probably merge this early in the 2023.2 cycle.

Known issues with pull request:
bdDetect.Detector does no longer take constructor parameters, rather queueBgScan should be called explicitly. This is because if we queue a scan in the constructor of Detector, the detector could switch to a display and disable detection before the _detector was set on the braille handler. Ideally we should use a lock as well, but that might be something as a follow up for both this pr and #14524. Note that though we're changing the constructor of a public class in bdDetect, the doc string of the class explicitly states that the Detector class should be used by the braille module only. That should be enough warning for users not to use this class and therefore I don't consider this API breaking.
log.debugWarning(f"Couldn't initialize display driver {name!r}", exc_info=True)
fallbackDisplayClass = _getDisplayDriver(NO_BRAILLE_DISPLAY_NAME)
# Only initialize the fallback if it is not already set
if self.display.__class__ == fallbackDisplayClass:
Copy link
Member

Choose a reason for hiding this comment

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

Should this not be != instead?
Getting reports if NVDA can not initialize a specifically configured display on start-up, then handler.display is None and the Braille page in the GUI is broken.

seanbudd pushed a commit that referenced this pull request Jul 28, 2023
Addresses issue introduced by pr #14524

Summary of the issue:
Reports from users that if a specifically configured braille display cannot be initialized on start-up, then the Braille category in the NVDA settings dialog is broken and does not show a valid braille driver (noBraille or otherwise).

Description of user facing changes
The Braille category in NVDA settings will continue to be usable if the configured Braille display cannot be initialized on start-up.

Description of development approach
In braille.handler.setDisplayByName if setting the display failed, the display is not set to NoBraille if the display was (not) already NoBraille. Previously this logic was incorrectly reversed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-early Merge Early in a developer cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants