Skip to content

Commit 7334a18

Browse files
authored
Merge 3b7877f into fedf666
2 parents fedf666 + 3b7877f commit 7334a18

9 files changed

Lines changed: 100 additions & 104 deletions

File tree

source/braille.py

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,62 @@ def formatCellsForLog(cells: List[int]) -> str:
18661866
if cell else "-"
18671867
for cell in cells])
18681868

1869+
1870+
pre_writeCells = extensionPoints.Action()
1871+
"""
1872+
Notifies when cells are about to be written to a braille display.
1873+
This allows components and add-ons to perform an action.
1874+
For example, when a system is controlled by a braille enabled remote system,
1875+
the remote system should know what cells to show on its display.
1876+
@param cells: The list of braille cells.
1877+
@type cells: List[int]
1878+
@param rawText: The raw text that corresponds with the cells.
1879+
@type rawText: str
1880+
@param currentCellCount: The current number of cells
1881+
@type currentCellCount: bool
1882+
"""
1883+
1884+
filter_displaySize = extensionPoints.Filter()
1885+
"""
1886+
Filter that allows components or add-ons to change the display size used for braille output.
1887+
For example, when a system is controlled by a remote system while having a 80 cells display connected,
1888+
the display size should be lowered to 40 whenever the remote system has a 40 cells display connected.
1889+
@param value: the number of cells of the current display.
1890+
@type value: int
1891+
"""
1892+
1893+
displaySizeChanged = extensionPoints.Action()
1894+
"""
1895+
Action that allows components or add-ons to be notified of display size changes.
1896+
For example, when a system is controlled by a remote system and the remote system swaps displays,
1897+
The local system should be notified about display size changes at the remote system.
1898+
@param displaySize: The current display size used by the braille handler.
1899+
@type displaySize: int
1900+
"""
1901+
1902+
displayChanged = extensionPoints.Action()
1903+
"""
1904+
Action that allows components or add-ons to be notified of braille display changes.
1905+
For example, when a system is controlled by a remote system and the remote system swaps displays,
1906+
The local system should be notified about display parameters at the remote system,
1907+
e.g. name and cellcount.
1908+
@param display: The new braille display driver
1909+
@type display: L{BrailleDisplayDriver}
1910+
@param isFallback: Whether the display is set as fallback display due to another display's failure
1911+
@type isFallback: bool
1912+
@param detected: If the display was set by auto detection, the device match that matched the driver
1913+
@type detected: bdDetect.DeviceMatch or C{None}
1914+
"""
1915+
1916+
decide_enabled = extensionPoints.Decider()
1917+
"""
1918+
Allows components or add-ons to decide whether the braille handler should be forcefully disabled.
1919+
For example, when a system is controlling a remote system with braille,
1920+
the local braille handler should be disabled as long as the system is in control of the remote system.
1921+
Handlers are called without arguments.
1922+
"""
1923+
1924+
18691925
class BrailleHandler(baseObject.AutoPropertyObject):
18701926
# TETHER_AUTO, TETHER_FOCUS, TETHER_REVIEW and tetherValues
18711927
# are deprecated, but remain to retain API backwards compatibility
@@ -1878,60 +1934,6 @@ class BrailleHandler(baseObject.AutoPropertyObject):
18781934
queuedWriteLock: threading.Lock
18791935
ackTimerHandle: int
18801936

1881-
pre_writeCells: extensionPoints.Action
1882-
"""
1883-
Notifies when cells are about to be written to a braille display.
1884-
This allows components and add-ons to perform an action.
1885-
For example, when a system is controlled by a braille enabled remote system,
1886-
the remote system should know what cells to show on its display.
1887-
@param cells: The list of braille cells.
1888-
@type cells: List[int]
1889-
@param rawText: The raw text that corresponds with the cells.
1890-
@type rawText: str
1891-
@param currentCellCount: The current number of cells
1892-
@type currentCellCount: bool
1893-
"""
1894-
1895-
filter_displaySize: extensionPoints.Filter
1896-
"""
1897-
Filter that allows components or add-ons to change the display size used for braille output.
1898-
For example, when a system is controlled by a remote system while having a 80 cells display connected,
1899-
the display size should be lowered to 40 whenever the remote system has a 40 cells display connected.
1900-
@param value: the number of cells of the current display.
1901-
@type value: int
1902-
"""
1903-
1904-
displaySizeChanged: extensionPoints.Action
1905-
"""
1906-
Action that allows components or add-ons to be notified of display size changes.
1907-
For example, when a system is controlled by a remote system and the remote system swaps displays,
1908-
The local system should be notified about display size changes at the remote system.
1909-
@param displaySize: The current display size used by the braille handler.
1910-
@type displaySize: int
1911-
"""
1912-
1913-
displayChanged: extensionPoints.Action
1914-
"""
1915-
Action that allows components or add-ons to be notified of braille display changes.
1916-
For example, when a system is controlled by a remote system and the remote system swaps displays,
1917-
The local system should be notified about display parameters at the remote system,
1918-
e.g. name and cellcount.
1919-
@param display: The new braille display driver
1920-
@type display: L{BrailleDisplayDriver}
1921-
@param isFallback: Whether the display is set as fallback display due to another display's failure
1922-
@type isFallback: bool
1923-
@param detected: If the display was set by auto detection, the device match that matched the driver
1924-
@type detected: bdDetect.DeviceMatch or C{None}
1925-
"""
1926-
1927-
decide_enabled: extensionPoints.Decider
1928-
"""
1929-
Allows components or add-ons to decide whether the braille handler should be forcefully disabled.
1930-
For example, when a system is controlling a remote system with braille,
1931-
the local braille handler should be disabled as long as the system is in control of the remote system.
1932-
Handlers are called without arguments.
1933-
"""
1934-
19351937
def __init__(self):
19361938
louisHelper.initialize()
19371939
self.display: Optional[BrailleDisplayDriver] = None
@@ -1975,12 +1977,6 @@ def __init__(self):
19751977

19761978
brailleViewer.postBrailleViewerToolToggledAction.register(self._onBrailleViewerChangedState)
19771979

1978-
self.pre_writeCells = extensionPoints.Action()
1979-
self.filter_displaySize = extensionPoints.Filter()
1980-
self.displaySizeChanged = extensionPoints.Action()
1981-
self.displayChanged = extensionPoints.Action()
1982-
self.decide_enabled = extensionPoints.Decider()
1983-
19841980
def terminate(self):
19851981
self._disableDetection()
19861982
if self._messageCallLater:
@@ -2025,9 +2021,9 @@ def _get_displaySize(self):
20252021
Therefore, this is a read only property and can't be set.
20262022
"""
20272023
numCells = self.display.numCells if self.display else 0
2028-
currentDisplaySize = self.filter_displaySize.apply(numCells)
2024+
currentDisplaySize = filter_displaySize.apply(numCells)
20292025
if self._displaySize != currentDisplaySize:
2030-
self.displaySizeChanged.notify(displaySize=currentDisplaySize)
2026+
displaySizeChanged.notify(displaySize=currentDisplaySize)
20312027
self._displaySize = currentDisplaySize
20322028
return currentDisplaySize
20332029

@@ -2054,7 +2050,7 @@ def _get_enabled(self):
20542050
and thus is C{True} when the display size is greater than 0.
20552051
This is a read only property and can't be set.
20562052
"""
2057-
currentEnabled = bool(self.displaySize) and self.decide_enabled.decide()
2053+
currentEnabled = bool(self.displaySize) and decide_enabled.decide()
20582054
if self._enabled != currentEnabled:
20592055
self._enabled = currentEnabled
20602056
if currentEnabled is False:
@@ -2164,7 +2160,7 @@ def setDisplayByName( # noqa: C901
21642160
# When setDisplayByName is refactored, ensure that braille display detection no longer triggers
21652161
# an unnecessary reinit of noBraille.
21662162
if not (sameDisplayReInit and newDisplay.name == "noBraille"):
2167-
self.displayChanged.notify(display=newDisplay, isFallback=isFallback, detected=detected)
2163+
displayChanged.notify(display=newDisplay, isFallback=isFallback, detected=detected)
21682164
return True
21692165
except:
21702166
# For auto display detection, logging an error for every failure is too obnoxious.
@@ -2198,7 +2194,7 @@ def _updateDisplay(self):
21982194

21992195
def _writeCells(self, cells: List[int]):
22002196
handlerCellCount = self.displaySize
2201-
self.pre_writeCells.notify(cells=cells, rawText=self._rawText, currentCellCount=handlerCellCount)
2197+
pre_writeCells.notify(cells=cells, rawText=self._rawText, currentCellCount=handlerCellCount)
22022198
displayCellCount = self.display.numCells
22032199
if not displayCellCount:
22042200
# No physical display to write to

source/brailleViewer/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def destroyBrailleViewer():
6868
_brailleGui = None # protect against re-entrance
6969
if d and not d.isDestroyed:
7070
import braille # imported late to avoid a circular import.
71-
updateBrailleDisplayedUnregistered = braille.handler.pre_writeCells.unregister(d.updateBrailleDisplayed)
71+
updateBrailleDisplayedUnregistered = braille.pre_writeCells.unregister(d.updateBrailleDisplayed)
7272
assert updateBrailleDisplayedUnregistered
73-
getDisplaySizeUnregistered = braille.handler.filter_displaySize.unregister(_getDisplaySize)
73+
getDisplaySizeUnregistered = braille.filter_displaySize.unregister(_getDisplaySize)
7474
assert getDisplaySizeUnregistered
7575
d.saveInfoAndDestroy()
7676

@@ -98,7 +98,7 @@ def createBrailleViewerTool():
9898
if not braille.handler:
9999
raise RuntimeError("Can not initialise the BrailleViewerGui: braille.handler not yet initialised")
100100

101-
braille.handler.filter_displaySize.register(_getDisplaySize)
101+
braille.filter_displaySize.register(_getDisplaySize)
102102

103103
global _brailleGui
104104
if _brailleGui:
@@ -108,5 +108,5 @@ def createBrailleViewerTool():
108108
braille.handler.displaySize,
109109
_onGuiDestroyed
110110
)
111-
braille.handler.pre_writeCells.register(_brailleGui.updateBrailleDisplayed)
111+
braille.pre_writeCells.register(_brailleGui.updateBrailleDisplayed)
112112
postBrailleViewerToolToggledAction.notify(created=True)

source/extensionPoints/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def notifyOnce(self, **kwargs):
6666
log.exception(f"Error running handler {handler} for {self}. Exception {e}")
6767

6868

69-
FilterValueTypeT = TypeVar("FilterOutputTypeT")
69+
FilterValueT = TypeVar("FilterValueT")
7070

7171

72-
class Filter(HandlerRegistrar, Generic[FilterValueTypeT]):
72+
class Filter(HandlerRegistrar, Generic[FilterValueT]):
7373
"""Allows interested parties to register to modify a specific kind of data.
7474
For example, this might be used to allow modification of spoken messages before they are passed to the synthesizer.
7575
@@ -93,7 +93,7 @@ class Filter(HandlerRegistrar, Generic[FilterValueTypeT]):
9393
'This is a message which has been filtered'
9494
"""
9595

96-
def apply(self, value: FilterValueTypeT, **kwargs) -> FilterValueTypeT:
96+
def apply(self, value: FilterValueT, **kwargs) -> FilterValueT:
9797
"""Pass a value to be filtered through all registered handlers.
9898
The value is passed to the first handler
9999
and the return value from that handler is passed to the next handler.

source/inputCore.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,19 @@ def save(self):
428428
with FaultTolerantFile(out.filename) as f:
429429
out.write(f)
430430

431+
432+
decide_executeGesture = extensionPoints.Decider()
433+
"""
434+
Notifies when a gesture is about to be executed,
435+
and allows components or add-ons to decide whether or not to execute a gesture.
436+
For example, when controlling a remote system with a connected local braille display,
437+
braille display gestures should not be executed locally.
438+
Handlers are called with one argument:
439+
@param gesture: The gesture that is about to be executed.
440+
@type gesture: L{InputGesture}
441+
"""
442+
443+
431444
class InputManager(baseObject.AutoPropertyObject):
432445
"""Manages functionality related to input from the user.
433446
Input includes key presses on the keyboard, as well as key presses on Braille displays, etc.
@@ -437,17 +450,6 @@ class InputManager(baseObject.AutoPropertyObject):
437450
#: @type: bool
438451
lastModifierWasInSayAll=False
439452

440-
decide_executeGesture: extensionPoints.Decider
441-
"""
442-
Notifies when a gesture is about to be executed,
443-
and allows components or add-ons to decide whether or not to execute a gesture.
444-
For example, when controlling a remote system with a connected local braille display,
445-
braille display gestures should not be executed locally.
446-
Handlers are called with one argument:
447-
@param gesture: The gesture that is about to be executed.
448-
@type gesture: L{InputGesture}
449-
"""
450-
451453
def __init__(self):
452454
#: The function to call when capturing gestures.
453455
#: If it returns C{False}, normal execution will be prevented.
@@ -463,8 +465,6 @@ def __init__(self):
463465
self.loadUserGestureMap()
464466
self._lastInputTime = None
465467

466-
self.decide_executeGesture = extensionPoints.Decider()
467-
468468
def executeGesture(self, gesture):
469469
"""Perform the action associated with a gesture.
470470
@param gesture: The gesture to execute.
@@ -477,7 +477,7 @@ def executeGesture(self, gesture):
477477
# as well as stopping a flood of actions when the core revives.
478478
raise NoInputGestureAction
479479

480-
if not self.decide_executeGesture.decide(gesture=gesture):
480+
if not decide_executeGesture.decide(gesture=gesture):
481481
# A registered handler decided that this gesture shouldn't be executed.
482482
# Purposely do not raise a NoInputGestureAction here, as that could
483483
# lead to unexpected behavior for gesture emulation, i.e. the gesture will be send to the system

tests/unit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def getFakeCellCount(numCells: int) -> int:
9999
return 40
100100

101101

102-
braille.handler.filter_displaySize.register(getFakeCellCount)
102+
braille.filter_displaySize.register(getFakeCellCount)
103103

104104
# The focus and navigator objects need to be initialized to something.
105105
from .objectProvider import PlaceholderNVDAObject,NVDAObjectWithRole

tests/unit/extensionPointTestHelpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"""Helper functions to test extension points."""
77

8-
from extensionPoints import Action, Decider, Filter, FilterValueTypeT
8+
from extensionPoints import Action, Decider, Filter, FilterValueT
99
import unittest
1010
from contextlib import contextmanager
1111
from typing import Optional
@@ -83,8 +83,8 @@ def handler(**kwargs):
8383
def filterTester(
8484
testCase: unittest.TestCase,
8585
filter: Filter,
86-
expectedInput: FilterValueTypeT,
87-
expectedOutput: FilterValueTypeT,
86+
expectedInput: FilterValueT,
87+
expectedOutput: FilterValueT,
8888
useAssertDictContainsSubset: bool = False,
8989
**expectedKwargs
9090
):
@@ -104,7 +104,7 @@ def filterTester(
104104
expectedKwargs["_value"] = expectedInput
105105
actualKwargs = {}
106106

107-
def handler(value: FilterValueTypeT, **kwargs):
107+
def handler(value: FilterValueT, **kwargs):
108108
actualKwargs.update(kwargs)
109109
actualKwargs["_called"] = True
110110
actualKwargs["_value"] = value

tests/unit/test_braille.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ def test_pre_writeCells(self):
138138
currentCellCount=braille.handler.displaySize
139139
)
140140

141-
with actionTester(self, braille.handler.pre_writeCells, **expectedKwargs):
141+
with actionTester(self, braille.pre_writeCells, **expectedKwargs):
142142
braille.handler._writeCells(cells)
143143

144144
def test_displaySizeChanged(self):
145145
expectedKwargs = dict(
146146
displaySize=braille.handler.displaySize
147147
)
148148

149-
with actionTester(self, braille.handler.displaySizeChanged, **expectedKwargs):
149+
with actionTester(self, braille.displaySizeChanged, **expectedKwargs):
150150
# Change the attribute that is compared with the value coming from filter_displaySize
151151
braille.handler._displaySize = 0
152152
# The getter should now trigger the action.
@@ -158,7 +158,7 @@ def test_displayChanged(self):
158158
detected=None
159159
)
160160

161-
with actionTester(self, braille.handler.displayChanged, useAssertDictContainsSubset=True, **expectedKwargs):
161+
with actionTester(self, braille.displayChanged, useAssertDictContainsSubset=True, **expectedKwargs):
162162
# Terminate the current noBraille instance to ensure that the action is triggered when choosing it again.
163163
braille.handler.display.terminate()
164164
braille.handler.display = None
@@ -167,7 +167,7 @@ def test_displayChanged(self):
167167
def test_filter_displaySize(self):
168168
with filterTester(
169169
self,
170-
braille.handler.filter_displaySize,
170+
braille.filter_displaySize,
171171
braille.handler._displaySize, # The currently cached display size
172172
20, # The filter handler should change the display size to 40
173173
) as expectedOutput:
@@ -176,7 +176,7 @@ def test_filter_displaySize(self):
176176
def test_decide_enabled(self):
177177
with deciderTester(
178178
self,
179-
braille.handler.decide_enabled,
179+
braille.decide_enabled,
180180
expectedDecision=False,
181181
) as expectedDecision:
182182
# Ensure that disabling braille by the decider doesn't try to call _handleEnabledDecisionFalse,

tests/unit/test_inputCore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_decide_executeGesture(self):
2525
gesture = keyboardHandler.KeyboardInputGesture.fromName("NVDA+T")
2626
with deciderTester(
2727
self,
28-
inputCore.manager.decide_executeGesture,
28+
inputCore.decide_executeGesture,
2929
expectedDecision=False,
3030
gesture=gesture
3131
):

user_docs/en/changes.t2t

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ This functionality is now available generically via ``behaviours.EditableText``
9696
- This new class is not a singleton by design, add-on authors are encouraged to use their own instance when doing hardware i/o.
9797
-
9898
- The processor architecture for the computer can be queried from ``winVersion.WinVersion.processorArchitecture attribute.`` (#14439)
99-
- New extension points have be added. (#14503)
100-
- ``inputCore.manager.decide_executeGesture``
99+
- New extension points have been added. (#14503)
100+
- ``inputCore.decide_executeGesture``
101101
- ``tones.decide_beep``
102102
- ``nvwave.decide_playWaveFile``
103-
- ``braille.handler.pre_writeCells``
104-
- ``braille.handler.filter_displaySize``
105-
- ``braille.handler.decide_enabled``
106-
- ``braille.handler.displayChanged``
107-
- ``braille.handler.displaySizeChanged``
103+
- ``braille.pre_writeCells``
104+
- ``braille.filter_displaySize``
105+
- ``braille.decide_enabled``
106+
- ``braille.displayChanged``
107+
- ``braille.displaySizeChanged``
108108
-
109109
-
110110

0 commit comments

Comments
 (0)