Skip to content

Commit

Permalink
Merge 071872c into c4ca763
Browse files Browse the repository at this point in the history
  • Loading branch information
burmancomp committed Jul 19, 2023
2 parents c4ca763 + 071872c commit 2165a40
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ def bufferPosToRegionPos(self, bufferPos):
raise LookupError("No such position")

def regionPosToBufferPos(self, region, pos, allowNearest=False):
start: int = 0
for testRegion, start, end in self.regionsWithPositions:
if region == testRegion:
if pos < end - start:
Expand Down Expand Up @@ -2003,6 +2004,10 @@ def formatCellsForLog(cells: List[int]) -> str:
"""


UPDATE_DISPLAY_PERIODICALLY_INTERVAL: int = 250
"""Timer interval for L{BrailleHandler._updateDisplayPeriodically}."""


class BrailleHandler(baseObject.AutoPropertyObject):
# TETHER_AUTO, TETHER_FOCUS, TETHER_REVIEW and tetherValues
# are deprecated, but remain to retain API backwards compatibility
Expand Down Expand Up @@ -2042,6 +2047,10 @@ def __init__(self):
self._cursorPos = None
self._cursorBlinkUp = True
self._cells = []
self._oldCells: List[int] = []
self._updateTimer = gui.NonReEntrantTimer(self._updateDisplayPeriodically)
# Start from main thread
wx.CallAfter(self._updateTimer.Start, UPDATE_DISPLAY_PERIODICALLY_INTERVAL)
self._cursorBlinkTimer = None
config.post_configProfileSwitch.register(self.handlePostConfigProfileSwitch)
if config.conf["braille"]["tetherTo"] == TetherTo.AUTO.value:
Expand All @@ -2064,6 +2073,9 @@ def terminate(self):
if self._cursorBlinkTimer:
self._cursorBlinkTimer.Stop()
self._cursorBlinkTimer = None
if self._updateTimer:
self._updateTimer.Stop()
self._updateTimer = None
config.post_configProfileSwitch.unregister(self.handlePostConfigProfileSwitch)
if self.display:
self.display.terminate()
Expand Down Expand Up @@ -2468,6 +2480,12 @@ def handleCaretMove(
if shouldAutoTether:
self.setTether(TetherTo.FOCUS.value, auto=True)
if self._tether != TetherTo.FOCUS.value:
# Braille display content is updated in case where:
# braille is tethered to review, review cursor does not follow system caret,
# and focus object is navigator object.
if not config.conf["reviewCursor"]["followCaret"]:
if obj == api.getNavigatorObject():
self.handleUpdate(obj)
return
region = self.mainBuffer.regions[-1] if self.mainBuffer.regions else None
if region and region.obj==obj:
Expand Down Expand Up @@ -2552,10 +2570,13 @@ def handleUpdate(self, obj: "NVDAObject") -> None:
region.update()
self.mainBuffer.update()
self.mainBuffer.restoreWindow()
if self._oldCells == self.buffer.windowBrailleCells:
return
if self.buffer is self.mainBuffer:
self.update()
elif self.buffer is self.messageBuffer and keyboardHandler.keyCounter>self._keyCountForLastMessage:
self._dismissMessage()
self._oldCells = self.buffer.windowBrailleCells.copy()

def handleReviewMove(self, shouldAutoTether=True):
if not self.enabled:
Expand Down Expand Up @@ -2686,6 +2707,19 @@ def _ackTimeoutResetter(self, param: int):
self.display._awaitingAck = False
self._writeCellsInBackground()

def _updateDisplayPeriodically(self):
"""Timer runs this function periodically to check if braille needs update."""
if self.buffer is not self.mainBuffer:
return
obj: NVDAObject
if api.isObjectInActiveTreeInterceptor(api.getNavigatorObject()):
obj = api.getCaretObject()
elif handler.getTether() == TetherTo.FOCUS.value:
obj = api.getFocusObject()
else:
obj = api.getNavigatorObject()
self.handleUpdate(obj)


# Maps old braille display driver names to new drivers that supersede old drivers.
# Ensure that if a user has set a preferred driver which has changed name, the new
Expand Down Expand Up @@ -2728,6 +2762,7 @@ def terminate():
handler.terminate()
handler = None


class BrailleDisplayDriver(driverHandler.Driver):
"""Abstract base braille display driver.
Each braille display driver should be a separate Python module in the root brailleDisplayDrivers directory
Expand Down

0 comments on commit 2165a40

Please sign in to comment.