Skip to content

Commit

Permalink
Add extension points to filter and process the cells written to a bra…
Browse files Browse the repository at this point in the history
…ille display
  • Loading branch information
Leonard de Ruijter committed Aug 29, 2018
1 parent 724447b commit 5096ded
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
40 changes: 37 additions & 3 deletions source/braille.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions source/brailleDisplayDrivers/alva.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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__()
Expand Down
2 changes: 1 addition & 1 deletion source/inputCore.py
Expand Up @@ -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.
Expand Down

0 comments on commit 5096ded

Please sign in to comment.