diff --git a/source/braille.py b/source/braille.py index 2fc82801e95..80aeaf85a9a 100644 --- a/source/braille.py +++ b/source/braille.py @@ -247,6 +247,11 @@ ) SELECTION_SHAPE = 0xC0 #: Dots 7 and 8 +#: The braille shape shown on a braille display when +#: the number of cells used by the braille handler is lower than the actual number of cells. +#: The 0 based position of the shape is equal to the number of cells used by the braille handler. +END_OF_BRAILLE_OUTPUT_SHAPE = 0xFF #: All dots + #: Unicode braille indicator at the start of untranslated braille input. INPUT_START_IND = u"⣏" #: Unicode braille indicator at the end of untranslated braille input. @@ -1568,14 +1573,22 @@ def __init__(self): self._detectionEnabled = False self._detector = None - #: Notifies when cells are about to be written to a braille display, - #: and allows components or add-ons to filter or change the raw cell data. + #: Filter that allows components or add-ons to filter or change the raw cell data, + #: that is written to a braille display. #: For example, the Handy Tech ATC functionality doesn't support empty lines, #: and therefore, empty lines should at least contain some filled cells. #: @param value: The list of braille cells. #: @type value: [int] self.filter_writeCells = extensionPoints.Filter() + #: Notifies when cells are about to be written to a braille display. + #: This allows components and add-ons to perform an action. + #: For example, when a system is controlled by a braille enabled remote system, + #: the remote system should know what cells to show on its display. + #: @param cells: The list of braille cells. + #: @type cells: [int] + self.pre_writeCells = extensionPoints.Action() + #: Filter that allows components or add-ons to change the display size used for braille output. #: For example, when a system is controlled by a remote system while having a 80 cells display connected, #: the display size should be lowered to 40 whenever the remote system has a 40 cells display connected. @@ -1601,6 +1614,7 @@ def _get_displaySize(self): def _set_displaySize(self, value): raise AttributeError("Can't set displaySize to %r, consider registering a handler to filter_displaySize" % value) + _cache_enabled = True def _get_enabled(self): """Returns whether braille is enabled. Handlers can register themselves to L{decide_enabled} and return C{False} to forcefully disable the braille handler. @@ -1717,7 +1731,7 @@ def setDisplayByName(self, name, isFallback=False, detected=None): config.conf["braille"]["display"] = name else: # detected: self._disableDetection() - log.info("Loaded braille display driver %s, current display has %d cells." %(name, self.displaySize)) + log.info("Loaded braille display driver %s, current display has %d cells." %(name, newDisplay.numCells)) self.initialDisplay() return True except: @@ -1747,6 +1761,26 @@ def _updateDisplay(self): def _writeCells(self, cells): cells = self.filter_writeCells.apply(cells) + self.pre_writeCells.notify(cells=cells) + displayCellCount = self.display.numCells + handlerCellCount = self.displaySize + if not displayCellCount: + # No physical display to write to + return + # Braille displays expect cells to be padded up to displayCellCount. + # However, the braille handler uses handlerCellCount to calculate the number of cells. + cellCountDif = displayCellCount - len(cells) + if cellCountDif < 0: + # There are more cells than the connected display could take. + log.warning( + "Connected display %s has %d cells, while braille handler is using %d cells" % + (self.display.name, displayCellCount, handlerCellCount) + ) + cells = cells[:displayCellCount] + elif cellCountDif > 0: + # The connected display could take more cells than the braille handler produces. + # Displays expect cells to be padded up to the number of cells. + cells += [END_OF_BRAILLE_OUTPUT_SHAPE] + [0]*cellCountDif if not self.display.isThreadSafe: try: self.display.display(cells) diff --git a/source/brailleDisplayDrivers/alva.py b/source/brailleDisplayDrivers/alva.py index 67f9a1bb44b..b66f0cf5cb5 100644 --- a/source/brailleDisplayDrivers/alva.py +++ b/source/brailleDisplayDrivers/alva.py @@ -118,7 +118,6 @@ def _get_model(self): return self.model def _updateSettings(self): - oldNumCells = self.numCells if self.isHid: displaySettings = self._dev.getFeature(ALVA_DISPLAY_SETTINGS_REPORT) if ord(displaySettings[ALVA_DISPLAY_SETTINGS_STATUS_CELL_SIDE_POS]) > 1: @@ -146,9 +145,6 @@ def _updateSettings(self): self._ser6SendMessage(b"H", b"?") # Get HID keyboard input state self._ser6SendMessage(b"r", b"?") - if oldNumCells not in (0, self.numCells): - # In case of splitpoint changes, we need to update the braille handler as well - braille.handler.displaySize = self.numCells def __init__(self, port="auto"): super(BrailleDisplayDriver,self).__init__() diff --git a/source/inputCore.py b/source/inputCore.py index 7b5ee55c787..346ee1a40f2 100644 --- a/source/inputCore.py +++ b/source/inputCore.py @@ -411,7 +411,7 @@ def __init__(self): #: Handlers are called with one argument: #: @param gesture: The gesture that is about to be executed. #: @type gesture: L{InputGesture} - self.decide_ExecuteGesture = extensionPoints.Decider() + self.decide_executeGesture = extensionPoints.Decider() def executeGesture(self, gesture): """Perform the action associated with a gesture.