Skip to content

Commit

Permalink
Basic support for braille display key modifiers (#7503)
Browse files Browse the repository at this point in the history
* Implemented support for braille display key modifiers:

	* For example, if L{self.id} is 'key1+key2', key1 is bound to 'kb:control' and key2 to 'kb:tab', this gesture should execute 'kb:control+tab'
	* Combining modifiers with braille input (#7306) is not yet supported

* Review action

* Removed line of code which has become obsolete after the review action
  • Loading branch information
Leonard de Ruijter authored and michaelDCurran committed Oct 3, 2017
1 parent 1e36745 commit f1ba4ca
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions source/braille.py
Expand Up @@ -26,6 +26,7 @@
import inputCore
import brailleTables
from collections import namedtuple
import scriptHandler

roleLabels = {
# Translators: Displayed in braille for an object which is a
Expand Down Expand Up @@ -1948,6 +1949,25 @@ def getPossiblePorts(cls):
#: @type: L{inputCore.GlobalGestureMap}
gestureMap = None

@classmethod
def _getModifierGestures(cls):
"""Retrieves modifier gestures from this display driver's L{gestureMap}
that are bound to modifier only keyboard emulate scripts.
@return: the ids of the display keys and the associated generalised modifier names
@rtype: generator of (set, set)
"""
import globalCommands
# Ignore the locale gesture map when searching for braille display gestures
globalMaps = [inputCore.manager.userGestureMap]
if cls.gestureMap:
globalMaps.append(cls.gestureMap)
for globalMap in globalMaps:
for scriptCls, gesture, scriptName in globalMap.getScriptsForAllGestures():
if gesture.startswith("br({source})".format(source=cls.name)) and scriptCls is globalCommands.GlobalCommands and scriptName.startswith("kb"):
emuGesture = keyboardHandler.KeyboardInputGesture.fromName(scriptName.split(":")[1])
if emuGesture.isModifier:
yield set(gesture.split(":")[1].split("+")), set(emuGesture._keyNamesInDisplayOrder)

class BrailleDisplayGesture(inputCore.InputGesture):
"""A button, wheel or other control pressed on a braille display.
Subclasses must provide L{source} and L{id}.
Expand Down Expand Up @@ -1997,6 +2017,49 @@ def _get_scriptableObject(self):
return display
return super(BrailleDisplayGesture, self).scriptableObject

def _get_script(self):
# Overrides L{inputCore.InputGesture._get_script} to support modifier keys.
script=scriptHandler.findScript(self)
if script:
self.script = script
return self.script
# No script for this gesture has been found, so process this gesture for possible modifiers.
# For example, if L{self.id} is 'key1+key2',
# key1 is bound to 'kb:control' and key2 to 'kb:tab',
# this gesture should execute 'kb:control+tab'.
# Combining modifiers with braille input (#7306) is not yet supported.
gestureKeys = set(self.keyNames)
gestureModifiers = set()
for keys, modifiers in handler.display._getModifierGestures():
if keys<gestureKeys:
gestureModifiers |= modifiers
gestureKeys -= keys
if not gestureModifiers:
# No modifier assignments found in this gesture.
return None
# Find a script for L{gestureKeys}.
fakeGestureId = u"br({source}):{id}".format(source=self.source, id="+".join(gestureKeys))
scriptNames = []
globalMaps = [inputCore.manager.userGestureMap, handler.display.gestureMap]
for globalMap in globalMaps:
scriptNames.extend(scriptName for cls, scriptName in globalMap.getScriptsForGesture(fakeGestureId) if scriptName.startswith("kb"))
if not scriptNames:
# Gesture contains modifiers, but no keyboard emulate script exists for the gesture without modifiers
return None
# We can't bother about multiple scripts for a gesture, we will just use the first one
scriptName = "kb:{modifiers}+{keys}".format(
modifiers="+".join(gestureModifiers),
keys=scriptNames[0].split(":")[1]
)
self.script = scriptHandler._makeKbEmulateScript(scriptName)
return self.script

def _get_keyNames(self):
"""The names of the keys that are part of this gesture.
@rtype: list
"""
return self.id.split("+")

@classmethod
def getDisplayTextForIdentifier(cls, identifier):
return handler.display.description, identifier.split(":", 1)[1]
Expand Down

0 comments on commit f1ba4ca

Please sign in to comment.