Skip to content

Commit f3ea2c3

Browse files
authored
Merge 1b56618 into 2fe9cb2
2 parents 2fe9cb2 + 1b56618 commit f3ea2c3

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

projectDocs/dev/developerGuide/developerGuide.t2t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ For examples of how to define and use new extension points, please see the code
10221022
|| Type | Extension Point | Description |
10231023
| ``Decider`` | ``decide_beep`` | Notifies when a beep is about to be generated and played, allowing a component to decide whether it should be. |
10241024

1025+
++ treeInterceptorHandler ++[treeInterceptorHandlerExtPts]
1026+
|| Type | Extension Point | Description |
1027+
| ``Action`` | ``post_browseModeStateChange`` | Notifies when browse mode state changes. |
1028+
10251029
++ utils.security ++[utils_securityExtPts]
10261030
|| Type | Extension Point | Description |
10271031
| ``Action`` | ``post_sessionLockStateChanged`` | Notifies when a session lock or unlock event occurs. |

source/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def setFocusObject(obj: NVDAObjects.NVDAObject) -> bool: # noqa: C901
9090
return False
9191
if globalVars.focusObject:
9292
eventHandler.executeEvent("loseFocus",globalVars.focusObject)
93+
oldTreeInterceptor = globalVars.focusObject.treeInterceptor
94+
else:
95+
oldTreeInterceptor = None
9396
oldFocusLine=globalVars.focusAncestors
9497
#add the old focus to the old focus ancestors, but only if its not None (is none at NVDA initialization)
9598
if globalVars.focusObject:
@@ -164,6 +167,13 @@ def setFocusObject(obj: NVDAObjects.NVDAObject) -> bool: # noqa: C901
164167
obj.treeInterceptor=treeInterceptorObject
165168
else:
166169
obj.treeInterceptor=None
170+
if oldTreeInterceptor is not obj.treeInterceptor:
171+
if obj.treeInterceptor:
172+
# obj.treeInterceptor has been assigned to treeInterceptorObject.
173+
browseMode = not treeInterceptorObject._passThrough
174+
else:
175+
browseMode = False
176+
treeInterceptorHandler.post_browseModeStateChange.notify(browseMode=browseMode)
167177
# #3804: handleAppSwitch should be called as late as possible,
168178
# as triggers must not be out of sync with global focus variables.
169179
# setFocusObject shouldn't fail earlier anyway, but it's best to be safe.

source/browseMode.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@
5151
from typing import Optional
5252

5353

54-
def reportPassThrough(treeInterceptor,onlyIfChanged=True):
54+
def reportPassThrough(treeInterceptor,onlyIfChanged=True, prevBrowseMode=False):
5555
"""Reports the pass through mode if it has changed.
5656
@param treeInterceptor: The current Browse Mode treeInterceptor.
5757
@type treeInterceptor: L{BrowseModeTreeInterceptor}
5858
@param onlyIfChanged: if true reporting will not happen if the last reportPassThrough reported the same thing.
5959
@type onlyIfChanged: bool
60+
@param prevBrowseMode: True if browse mode was active, False otherwise.
61+
@type browseMode: bool
6062
"""
61-
if not onlyIfChanged or treeInterceptor.passThrough != reportPassThrough.last:
63+
if not onlyIfChanged or treeInterceptor.passThrough != prevBrowseMode:
6264
if config.conf["virtualBuffers"]["passThroughAudioIndication"]:
6365
sound = "focusMode.wav" if treeInterceptor.passThrough else "browseMode.wav"
6466
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", sound))
@@ -70,8 +72,7 @@ def reportPassThrough(treeInterceptor,onlyIfChanged=True):
7072
# Translators: The mode that presents text in a flat representation
7173
# that can be navigated with the cursor keys like in a text document
7274
ui.message(_("Browse mode"))
73-
reportPassThrough.last = treeInterceptor.passThrough
74-
reportPassThrough.last = False
75+
7576

7677
def mergeQuickNavItemIterators(iterators,direction="next"):
7778
"""
@@ -1995,3 +1996,5 @@ def _iterNotLinkBlock(self, direction="next", pos=None):
19951996
def script_toggleScreenLayout(self, gesture):
19961997
# Translators: The message reported for not supported toggling of screen layout
19971998
ui.message(_("Not supported in this document."))
1999+
2000+
treeInterceptorHandler.post_browseModeStateChange.register(reportPassThrough)

source/treeInterceptorHandler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,20 @@
2020
import vision
2121
from speech.types import SpeechSequence
2222
from controlTypes import OutputReason
23+
import extensionPoints
2324

2425
if TYPE_CHECKING:
2526
import NVDAObjects
2627

28+
post_browseModeStateChange = extensionPoints.Action()
29+
"""
30+
Notifies when browse mode state has changed.
31+
This allows components and add-ons to perform an action.
32+
For example, an add-on may activate a profile when browse mode has been activated,
33+
and deactivate that profile when browse mode becomes inactive.
34+
@param browseMode: The state of browse mode.
35+
@type browseMode: bool
36+
"""
2737

2838
runningTable=set()
2939

@@ -134,6 +144,8 @@ def _set_passThrough(self, state):
134144
if self._passThrough == state:
135145
return
136146
self._passThrough = state
147+
browseMode = not self._passThrough
148+
post_browseModeStateChange.notify(browseMode=browseMode)
137149
if state:
138150
if config.conf['reviewCursor']['followFocus']:
139151
focusObj=api.getFocusObject()

user_docs/en/changes.t2t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ They should also be thread safe, making it possible to call them from background
130130
- Added official support to register custom braille display drivers in the automatic braille display detection process.
131131
Consult the ``braille.BrailleDisplayDriver`` class documentation for more details.
132132
Most notably, the ``supportsAutomaticDetection`` attribute must be set to ``True`` and the ``registerAutomaticDetection`` ``classmethod`` must be implemented. (#15196)
133+
- Added extension point: ``treeInterceptorHandler.post_browseModeStateChange``. (#14969)
133134
-
134135

135136
=== Deprecations ===

0 commit comments

Comments
 (0)