Skip to content

Commit

Permalink
monkeypatch: inputCore.InputManager.executeGesture -> `inputCore.de…
Browse files Browse the repository at this point in the history
…cide_executeGesture`

See <nvaccess/nvda#14503>, <LeonarddeR/rdAccess#14>
  • Loading branch information
AAClause committed May 12, 2024
1 parent ed8d04a commit 163e5b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 82 deletions.
113 changes: 32 additions & 81 deletions addon/globalPlugins/brailleExtender/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,89 +883,41 @@ def previousLine(self, start=False):


# inputCore.InputManager.executeGesture
def executeGesture(self, gesture):
"""Perform the action associated with a gesture.
@param gesture: The gesture to execute.
@type gesture: L{InputGesture}
@raise NoInputGestureAction: If there is no action to perform.
"""
if watchdog.isAttemptingRecovery:
# The core is dead, so don't try to perform an action.
# This lets gestures pass through unhindered where possible,
# as well as stopping a flood of actions when the core revives.
raise NoInputGestureAction

script = gesture.script
if "brailleDisplayDrivers" in str(type(gesture)):
if instanceGP.brailleKeyboardLocked and ((hasattr(script, "__func__") and script.__func__.__name__ != "script_toggleLockBrailleKeyboard") or not hasattr(script, "__func__")): return
if not config.conf["brailleExtender"]['stopSpeechUnknown'] and gesture.script == None: stopSpeech = False
elif hasattr(script, "__func__") and (script.__func__.__name__ in [
"script_braille_dots", "script_braille_enter",
"script_volumePlus", "script_volumeMinus", "script_toggleVolume",
"script_hourDate",
"script_ctrl", "script_alt", "script_nvda", "script_win",
"script_ctrlAlt", "script_ctrlAltWin", "script_ctrlAltWinShift", "script_ctrlAltShift","script_ctrlWin","script_ctrlWinShift","script_ctrlShift","script_altWin","script_altWinShift","script_altShift","script_winShift"]
or (
not config.conf["brailleExtender"]['stopSpeechScroll'] and
script.__func__.__name__ in ["script_braille_scrollBack","script_braille_scrollForward"])):
stopSpeech = False
else: stopSpeech = True
else: stopSpeech = True

focus = api.getFocusObject()
if focus.sleepMode is focus.SLEEP_FULL or (focus.sleepMode and not getattr(script, 'allowInSleepMode', False)):
raise NoInputGestureAction

wasInSayAll=False
if gesture.isModifier:
if not self.lastModifierWasInSayAll:
wasInSayAll=self.lastModifierWasInSayAll=sayAllHandler.isRunning()
elif self.lastModifierWasInSayAll:
wasInSayAll=True
self.lastModifierWasInSayAll=False
else:
wasInSayAll=sayAllHandler.isRunning()
if wasInSayAll:
gesture.wasInSayAll=True

speechEffect = gesture.speechEffectWhenExecuted
if not stopSpeech: pass
elif speechEffect == gesture.SPEECHEFFECT_CANCEL:
queueHandler.queueFunction(queueHandler.eventQueue, speech.cancelSpeech)
elif speechEffect in (gesture.SPEECHEFFECT_PAUSE, gesture.SPEECHEFFECT_RESUME):
queueHandler.queueFunction(queueHandler.eventQueue, speech.pauseSpeech, speechEffect == gesture.SPEECHEFFECT_PAUSE)

if log.isEnabledFor(log.IO) and not gesture.isModifier:
self._lastInputTime = time.time()
log.io("Input: %s" % gesture.identifiers[0])

if self._captureFunc:
try:
if self._captureFunc(gesture) is False:
return
except BaseException:
log.error("Error in capture function, disabling", exc_info=True)
self._captureFunc = None

if gesture.isModifier:
raise NoInputGestureAction

if config.conf["keyboard"]["speakCommandKeys"] and gesture.shouldReportAsCommand:
queueHandler.queueFunction(queueHandler.eventQueue, speech.speakMessage, gesture.displayName)

gesture.reportExtra()

# #2953: if an intercepted command Script (script that sends a gesture) is queued
# then queue all following gestures (that don't have a script) with a fake script so that they remain in order.
if not script and scriptHandler._numIncompleteInterceptedCommandScripts:
script=lambda gesture: gesture.send()
def executeGesture(gesture):
script = gesture.script
if "brailleDisplayDrivers" in str(type(gesture)):
if (
instanceGP.brailleKeyboardLocked
and (
(
hasattr(script, "__func__")
and script.__func__.__name__ != "script_toggleLockBrailleKeyboard"
)
or not hasattr(script, "__func__")
)
):
return
if (
hasattr(script, "__func__")
and (
script.__func__.__name__ in [
"script_braille_dots", "script_braille_enter",
"script_volumePlus", "script_volumeMinus", "script_toggleVolume",
"script_hourDate",
"script_ctrl", "script_alt", "script_nvda", "script_win",
"script_ctrlAlt", "script_ctrlAltWin", "script_ctrlAltWinShift", "script_ctrlAltShift","script_ctrlWin","script_ctrlWinShift","script_ctrlShift","script_altWin","script_altWinShift","script_altShift","script_winShift"
] or (
not config.conf["brailleExtender"]['stopSpeechScroll']
and script.__func__.__name__ in ["script_braille_scrollBack", "script_braille_scrollForward"]
)
)
):
gesture.speechEffectWhenExecuted = None
return True

inputCore.decide_executeGesture.register(executeGesture)

if script:
scriptHandler.queueScript(script, gesture)
return

raise NoInputGestureAction
# brailleInput.BrailleInputHandler.sendChars()
def sendChars(self, chars):
"""Sends the provided unicode characters to the system.
Expand Down Expand Up @@ -1234,7 +1186,6 @@ def getTetherWithRoleTerminal(self):
braille.TextInfoRegion.update = update_TextInfoRegion
braille.TextInfoRegion.previousLine = previousLine
braille.TextInfoRegion.nextLine = nextLine
inputCore.InputManager.executeGesture = executeGesture
NoInputGestureAction = inputCore.NoInputGestureAction
brailleInput.BrailleInputHandler._translate = _translate
brailleInput.BrailleInputHandler.emulateKey = emulateKey
Expand Down
2 changes: 1 addition & 1 deletion buildVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _(arg):
# Documentation file name
"addon_docFileName": "readme.html",
# Minimum NVDA version supported (e.g. "2018.3.0", minor version is optional)
"addon_minimumNVDAVersion": "2021.1",
"addon_minimumNVDAVersion": "2021.4",
# Last NVDA version supported/tested (e.g. "2018.4.0", ideally more recent than minimum version)
"addon_lastTestedNVDAVersion": "2024.1",
# Add-on update channel (default is None, denoting stable releases,
Expand Down

0 comments on commit 163e5b9

Please sign in to comment.