Skip to content

Commit

Permalink
Provide a more reliable solution for automatic review cursor tetherin…
Browse files Browse the repository at this point in the history
…g in terminals
  • Loading branch information
AAClause committed Apr 1, 2023
1 parent eca0f3f commit ae564b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
44 changes: 1 addition & 43 deletions addon/globalPlugins/brailleExtender/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# BrailleExtender Addon for NVDA
# This file is covered by the GNU General Public License.
# See the file LICENSE for more details.
# Copyright (C) 2016-2020 André-Abush Clause <[email protected]>
# Copyright (C) 2016-2023 André-Abush Clause <[email protected]>
#
# Additional third party copyrighted code is included:
# - *Attribra*: Copyright (C) 2017 Alberto Zanella <[email protected]>
Expand Down Expand Up @@ -168,8 +168,6 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
if not addoncfg.noUnicodeTable:
backupInputTable = brailleInput.handler.table
backupMessageTimeout = None
backupTether = utils.getTether()
switchedMode = False

def __init__(self):
startTime = time.time()
Expand Down Expand Up @@ -216,22 +214,6 @@ def event_gainFocus(self, obj, nextHandler):
rotorItem = 0
self.bindRotorGES()

if config.conf["brailleExtender"]["reviewModeTerminal"]:
if not self.switchedMode and obj.role == utils.get_control_type("ROLE_TERMINAL") and obj.hasFocus:
if not hasattr(braille.handler, "TETHER_AUTO"):
self.backupTether = utils.getTether()
braille.handler.tether = braille.handler.TETHER_REVIEW
else:
if config.conf["braille"]["autoTether"]:
self.backupTether = braille.handler.TETHER_AUTO
config.conf["braille"]["autoTether"] = False
else:
self.backupTether = utils.getTether()
braille.handler.setTether(braille.handler.TETHER_REVIEW, auto=False)
braille.handler.handleReviewMove(shouldAutoTether=False)
self.switchedMode = True
elif self.switchedMode and obj.role != utils.get_control_type("ROLE_TERMINAL"): self.restorReviewCursorTethering()

if "tabSize_%s" % addoncfg.curBD not in config.conf["brailleExtender"].copy().keys(): self.onReload(None, 1)
if self.hourDatePlayed: self.script_hourDate(None)
if self.autoTestPlayed: self.script_autoTest(None)
Expand All @@ -240,9 +222,7 @@ def event_gainFocus(self, obj, nextHandler):
self.onReload(None, 1)

if self.backup__brailleTableDict != config.conf["braille"]["translationTable"]: self.reloadBrailleTables()

nextHandler()
return

def event_foreground(self, obj, nextHandler):
if braille.handler._auto_scroll:
Expand Down Expand Up @@ -318,27 +298,6 @@ def onTableDictionary(evt):
def onTemporaryDictionary(evt):
gui.mainFrame._popupSettingsDialog(tabledictionaries.DictionaryDlg, _("Temporary dictionary"), "tmp")

def restorReviewCursorTethering(self):
if not self.switchedMode: return
if not hasattr(braille.handler, "TETHER_AUTO"):
braille.handler.tether = self.backupTether
else:
if self.backupTether == braille.handler.TETHER_AUTO:
config.conf["braille"]["autoTether"] = True
config.conf["braille"]["tetherTo"] = braille.handler.TETHER_FOCUS
else:
config.conf["braille"]["autoTether"] = False
braille.handler.setTether(self.backupTether, auto=False)
if self.backupTether == braille.handler.TETHER_REVIEW:
braille.handler.handleReviewMove(shouldAutoTether=False)
else:
focus = api.getFocusObject()
if focus.treeInterceptor and not focus.treeInterceptor.passThrough:
braille.handler.handleGainFocus(focus.treeInterceptor,shouldAutoTether=False)
else:
braille.handler.handleGainFocus(focus,shouldAutoTether=False)
self.switchedMode = False

def getGestureWithBrailleIdentifier(self, gesture = ''):
return ("br(%s):" % addoncfg.curBD if ':' not in gesture else '') + gesture

Expand Down Expand Up @@ -1278,7 +1237,6 @@ def terminate(self):
braille.TextInfoRegion.update = self.backup__update
braille.TextInfoRegion._getTypeformFromFormatField = self.backup__getTypeformFromFormatField
self.removeMenu()
self.restorReviewCursorTethering()
rolelabels.discardRoleLabels()
if addoncfg.noUnicodeTable:
brailleInput.handler.table = self.backupInputTable
Expand Down
16 changes: 16 additions & 0 deletions addon/globalPlugins/brailleExtender/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import braille
import brailleInput
import config
import controlTypes
import core
import globalCommands
import inputCore
Expand Down Expand Up @@ -561,6 +562,20 @@ def _displayWithCursor(self):
cells[self._cursorPos] |= config.conf["braille"]["cursorShapeReview"]
self._writeCells(cells)

origGetTether = braille.BrailleHandler.getTether

def getTetherWithRoleTerminal(self):
role = None
obj = api.getNavigatorObject()
if obj:
role = api.getNavigatorObject().role
if (
config.conf["brailleExtender"]["reviewModeTerminal"]
and role == controlTypes.ROLE_TERMINAL
):
return braille.handler.TETHER_REVIEW
return origGetTether(self)


# applying patches
braille.Region.update = update
Expand Down Expand Up @@ -590,3 +605,4 @@ def _displayWithCursor(self):
braille.BrailleHandler._displayWithCursor = _displayWithCursor

REASON_CARET = get_output_reason("CARET")
braille.BrailleHandler.getTether = getTetherWithRoleTerminal

0 comments on commit ae564b3

Please sign in to comment.