Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions addon/brailleDisplayDrivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ def _incoming_numCells(self, payload: bytes) -> int:

def _get_numCells(self) -> int:
if (value := self.numRows * self.numCols) == 0:
attribute = protocol.BrailleAttribute.NUM_CELLS
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
value = self._getRemoteAttributeValueWithFallback(protocol.BrailleAttribute.NUM_CELLS)
return value

@protocol.attributeReceiver(protocol.BrailleAttribute.NUM_ROWS, defaultValue=1)
Expand All @@ -68,27 +63,15 @@ def _incoming_numRows(self, payload: bytes) -> int:
return ord(payload)

def _get_numRows(self) -> int:
attribute = protocol.BrailleAttribute.NUM_ROWS
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(protocol.BrailleAttribute.NUM_ROWS)

@protocol.attributeReceiver(protocol.BrailleAttribute.NUM_COLS, defaultValue=0)
def _incoming_numCols(self, payload: bytes) -> int:
assert len(payload) == 1
return ord(payload)

def _get_numCols(self) -> int:
attribute = protocol.BrailleAttribute.NUM_COLS
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(protocol.BrailleAttribute.NUM_COLS)

@protocol.attributeReceiver(protocol.BrailleAttribute.GESTURE_MAP)
def _incoming_gestureMapUpdate(self, payload: bytes) -> inputCore.GlobalGestureMap:
Expand All @@ -100,13 +83,7 @@ def _default_gestureMap(self, _attribute: protocol.AttributeT):
return inputCore.GlobalGestureMap()

def _get_gestureMap(self) -> inputCore.GlobalGestureMap:
attribute = protocol.BrailleAttribute.GESTURE_MAP
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(protocol.BrailleAttribute.GESTURE_MAP)

@protocol.commandHandler(protocol.BrailleCommand.EXECUTE_GESTURE)
def _command_executeGesture(self, payload: bytes):
Expand Down
37 changes: 18 additions & 19 deletions addon/lib/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def updateCallback(self, func: AttributeValueUpdateCallbackT):
return func


def _constantDefaultValueGetter(defaultValue: Any) -> DefaultValueGetterT:
def _defaultValueGetter(_self: RemoteProtocolHandler, _attribute: AttributeT):
return defaultValue

return _defaultValueGetter


def attributeReceiver(
attribute: AttributeT,
defaultValue: Any = None,
Expand All @@ -183,11 +190,7 @@ def attributeReceiver(
if defaultValue is not None and defaultValueGetter is not None:
raise ValueError("Either defaultValue or defaultValueGetter is required, but not both")
if defaultValueGetter is None:

def _defaultValueGetter(_self: RemoteProtocolHandler, _attribute: AttributeT):
return defaultValue

defaultValueGetter = _defaultValueGetter
defaultValueGetter = _constantDefaultValueGetter(defaultValue)
return partial(
AttributeReceiver,
attribute,
Expand Down Expand Up @@ -442,6 +445,14 @@ def _safeWait(self, predicate: Callable[[], bool], timeout: float | None = None)
timeout -= time.perf_counter() - curTime
return predicate()

def _getRemoteAttributeValueWithFallback(self, attribute: AttributeT):
try:
return self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value

def getRemoteAttribute(
self,
attribute: AttributeT,
Expand Down Expand Up @@ -510,13 +521,7 @@ def _incoming_nvdaVersion(self, payload: bytes) -> str:
return payload.decode()

def _get_nvdaVersion(self) -> str:
attribute = GenericAttribute.NVDA_VERSION
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(GenericAttribute.NVDA_VERSION)

@attributeSender(GenericAttribute.RD_ACCESS_VERSION)
def _outgoing_rdAccessVersion(self) -> bytes:
Expand All @@ -527,10 +532,4 @@ def _incoming_rdAccessVersion(self, payload: bytes) -> str:
return payload.decode()

def _get_rdAccessVersion(self) -> str:
attribute = GenericAttribute.RD_ACCESS_VERSION
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(GenericAttribute.RD_ACCESS_VERSION)
16 changes: 2 additions & 14 deletions addon/synthDrivers/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,15 @@ def _incoming_supportedCommands(self, payLoad: bytes) -> frozenset:
return self._unpickle(payLoad)

def _get_supportedCommands(self):
attribute = protocol.SpeechAttribute.SUPPORTED_COMMANDS
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(protocol.SpeechAttribute.SUPPORTED_COMMANDS)

@protocol.attributeReceiver(protocol.SpeechAttribute.LANGUAGE, defaultValue=getLanguage())
def _incoming_language(self, payload: bytes) -> str | None:
assert len(payload) > 0
return self._unpickle(payload)

def _get_language(self):
attribute = protocol.SpeechAttribute.LANGUAGE
try:
value = self._attributeValueProcessor.getValue(attribute, fallBackToDefault=False)
except KeyError:
value = self._attributeValueProcessor._getDefaultValue(attribute)
self.requestRemoteAttribute(attribute)
return value
return self._getRemoteAttributeValueWithFallback(protocol.SpeechAttribute.LANGUAGE)

@protocol.commandHandler(protocol.SpeechCommand.INDEX_REACHED)
def _command_indexReached(self, incomingPayload: bytes):
Expand Down