Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EcoBraille and Lilly braille display drivers #17635

Merged
merged 11 commits into from
Jan 29, 2025
19 changes: 14 additions & 5 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ def __init__(self, handler):
#: The translated braille representation of the entire buffer.
#: @type: [int, ...]
self.brailleCells = []
self._windowRowBufferOffsets: list[tuple[int, int]] = [(0, 1)]
self._windowRowBufferOffsets: list[tuple[int, int]] = [(0, 0)]
"""
A list representing the rows in the braille window,
each item being a tuple of start and end braille buffer offsets.
Expand Down Expand Up @@ -1879,6 +1879,8 @@ def windowPosToBufferPos(self, windowPos: int) -> int:
"""
Converts a position relative to the braille window to a position relative to the braille buffer.
"""
if self.handler.displaySize == 0:
return 0
windowPos = max(min(windowPos, self.handler.displaySize), 0)
row, col = divmod(windowPos, self.handler.displayDimensions.numCols)
if row < len(self._windowRowBufferOffsets):
Expand All @@ -1905,7 +1907,7 @@ def _calculateWindowRowBufferOffsets(self, pos: int) -> None:
self._windowRowBufferOffsets.clear()
if len(self.brailleCells) == 0:
# Initialising with no actual braille content.
self._windowRowBufferOffsets = [(0, 1)]
self._windowRowBufferOffsets = [(0, 0)]
return
doWordWrap = config.conf["braille"]["wordWrap"]
bufferEnd = len(self.brailleCells)
Expand Down Expand Up @@ -2539,9 +2541,14 @@ def _set_displaySize(self, value):
_cache_displayDimensions = True

def _get_displayDimensions(self) -> DisplayDimensions:
if not self.display:
numRows = numCols = 0
else:
numRows = self.display.numRows
numCols = self.display.numCols if numRows > 1 else self.display.numCells
rawDisplayDimensions = DisplayDimensions(
numRows=self.display.numRows if self.display else 0,
numCols=self.display.numCols if self.display else 0,
numRows=numRows,
numCols=numCols,
)
filteredDisplayDimensions = filter_displayDimensions.apply(rawDisplayDimensions)
# Would be nice if there were a more official way to find out if the displaySize filter is currently registered by at least 1 handler.
Expand Down Expand Up @@ -3284,7 +3291,9 @@ class BrailleDisplayDriver(driverHandler.Driver):
containing a BrailleDisplayDriver class which inherits from this base class.

At a minimum, drivers must set L{name} and L{description} and override the L{check} method.
To display braille, L{numCells} and L{display} must be implemented.
To display braille, :meth:`display` must be implemented.
For a single line display, :attr:`numCells` must be implemented.
For a multi line display, :attr:`numRows` and :attr:`numCols` must be implemented.

To support automatic detection of braille displays belonging to this driver:
* The driver must be thread safe and L{isThreadSafe} should be set to C{True}
Expand Down