Skip to content

Commit

Permalink
Add "report formatting for text under braille cell" command (#7189)
Browse files Browse the repository at this point in the history
* Add a "report formatting info for text under this braille cell" command.

* Assign the Alva BC6 secondary cursor routing keys to the new report formatting command.

* Update copyrights.

* Update user guide for the new Alva BC6 key assignment.

* Also use the new report formatting braille command in both Papenmeier drivers.
This removes their "route to and report formatting" behavior. Instead, it now only reports formatting without routing the cursor.

* Address review actions.

* Update user docs.

* Add the report text formatting under braille cell command to the EuroBraille displays.

* Revert browseable message for the report text formatting under braille cell command.

* Incorporate PR #7990.

* Add translator comment
  • Loading branch information
dkager authored and michaelDCurran committed Mar 28, 2018
1 parent 99c3ca6 commit 9dd4836
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 47 deletions.
33 changes: 25 additions & 8 deletions source/braille.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,16 @@ def update(self):
else:
self._brailleInputIndStart = None

def getTextInfoForBraillePos(self, braillePos):
pos = self._rawToContentPos[self.brailleToRawPos[braillePos]]
# pos is relative to the start of the reading unit.
# Therefore, get the start of the reading unit...
dest = self._readingInfo.copy()
dest.collapse()
# and move pos characters from there.
dest.move(textInfos.UNIT_CHARACTER, pos)
return dest

def routeTo(self, braillePos):
if self._brailleInputIndStart is not None and self._brailleInputIndStart <= braillePos < self._brailleInputIndEnd:
# The user is moving within untranslated braille input.
Expand All @@ -1003,14 +1013,7 @@ def routeTo(self, braillePos):
except NotImplementedError:
pass
return

pos = self._rawToContentPos[self.brailleToRawPos[braillePos]]
# pos is relative to the start of the reading unit.
# Therefore, get the start of the reading unit...
dest = self._readingInfo.copy()
dest.collapse()
# and move pos characters from there.
dest.move(textInfos.UNIT_CHARACTER, pos)
dest = self.getTextInfoForBraillePos(braillePos)
self._setCursor(dest)

def nextLine(self):
Expand Down Expand Up @@ -1340,6 +1343,15 @@ def routeTo(self, windowPos):
region, pos = self.bufferPosToRegionPos(pos)
region.routeTo(pos)

def getTextInfoForWindowPos(self, windowPos):
pos = self.windowStartPos + windowPos
if pos >= self.windowEndPos:
return None
region, pos = self.bufferPosToRegionPos(pos)
if not isinstance(region, TextInfoRegion):
return None
return region.getTextInfoForBraillePos(pos)

def saveWindow(self):
"""Save the current window so that it can be restored after the buffer is updated.
The window start position is saved as a position relative to a region.
Expand Down Expand Up @@ -1671,6 +1683,11 @@ def routeTo(self, windowPos):
if self.buffer is self.messageBuffer:
self._dismissMessage()

def getTextInfoForWindowPos(self, windowPos):
if self.buffer is not self.mainBuffer:
return None
return self.buffer.getTextInfoForWindowPos(windowPos)

def message(self, text):
"""Display a message to the user which times out after a configured interval.
The timeout will be reset if the user scrolls the display.
Expand Down
1 change: 1 addition & 0 deletions source/brailleDisplayDrivers/alva.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ def script_toggleHidKeyboardInput(self, gesture):
"braille_nextLine": ("br(alva):t4",),
"braille_scrollForward": ("br(alva):t5","br(alva):etouch3"),
"braille_routeTo": ("br(alva):routing",),
"braille_reportFormatting": ("br(alva):secondRouting",),
"review_top": ("br(alva):t1+t2",),
"review_bottom": ("br(alva):t4+t5",),
"braille_toggleTether": ("br(alva):t1+t3",),
Expand Down
3 changes: 2 additions & 1 deletion source/brailleDisplayDrivers/eurobraille.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def announceUnavailableMessage():

gestureMap = inputCore.GlobalGestureMap({
"globalCommands.GlobalCommands": {
"braille_routeTo": ("br(eurobraille):routing","br(eurobraille):doubleRouting",),
"braille_routeTo": ("br(eurobraille):routing",),
"braille_reportFormatting": ("br(eurobraille):doubleRouting",),
"braille_scrollBack": (
"br(eurobraille):switch1Left",
"br(eurobraille):l1",
Expand Down
15 changes: 3 additions & 12 deletions source/brailleDisplayDrivers/papenmeier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2012-2015 Tobias Platen, Halim Sahin, Ali-Riza Ciftcioglu, NV Access Limited
#Copyright (C) 2012-2017 Tobias Platen, Halim Sahin, Ali-Riza Ciftcioglu, NV Access Limited, Davy Kager
#Author: Tobias Platen ([email protected])
#minor changes by Halim Sahin ([email protected]), Ali-Riza Ciftcioglu <[email protected]> and James Teh
#minor changes by Halim Sahin ([email protected]), Ali-Riza Ciftcioglu <[email protected]>, James Teh and Davy Kager

import time
import itertools
Expand Down Expand Up @@ -472,12 +472,6 @@ def _handleKeyPresses(self):
if(self._dev!=None): self._dev.close()
self._dev=None

def script_upperRouting(self, gesture):
globalCommands.commands.script_braille_routeTo(gesture)
wx.CallLater(50, scriptHandler.executeScript, globalCommands.commands.script_reportFormatting, gesture)

script_upperRouting.__doc__ = _("Route to and report formatting")

#global gestures
gestureMap = inputCore.GlobalGestureMap({
"globalCommands.GlobalCommands": {
Expand All @@ -486,6 +480,7 @@ def script_upperRouting(self, gesture):
"braille_previousLine": ("br(papenmeier):up",),
"braille_nextLine": ("br(papenmeier):dn",),
"braille_routeTo": ("br(papenmeier):route",),
"braille_reportFormatting": ("br(papenmeier):upperRouting",),

"braille_toggleTether": ("br(papenmeier):r2",),
"review_currentCharacter": ("br(papenmeier):l1",),
Expand All @@ -510,10 +505,6 @@ def script_upperRouting(self, gesture):
}
})

__gestures = {
"br(papenmeier):upperRouting": "upperRouting",
}

class InputGesture(braille.BrailleDisplayGesture, brailleInput.BrailleInputGesture):
"""Input gesture for papenmeier displays"""
source = BrailleDisplayDriver.name
Expand Down
16 changes: 3 additions & 13 deletions source/brailleDisplayDrivers/papenmeier_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2012-2013 Tobias Platen, Halim Sahin, Ali-Riza Ciftcioglu, NV Access Limited
#Copyright (C) 2012-2017 Tobias Platen, Halim Sahin, Ali-Riza Ciftcioglu, NV Access Limited, Davy Kager
#Author: Tobias Platen ([email protected])
#minor changes by Halim Sahin ([email protected]), Ali-Riza Ciftcioglu <[email protected]> and James Teh
#minor changes by Halim Sahin ([email protected]), Ali-Riza Ciftcioglu <[email protected]>, James Teh and Davy Kager
#used braille port selection code from braillenote driver

from collections import OrderedDict
Expand Down Expand Up @@ -150,13 +150,6 @@ def __init__(self, port):
self._keyCheckTimer = wx.PyTimer(self._handleKeyPresses)
self._keyCheckTimer.Start(KEY_CHECK_INTERVAL)

def script_upperRouting(self, gesture):
globalCommands.commands.script_braille_routeTo(gesture)
wx.CallLater(50, scriptHandler.executeScript, globalCommands.commands.script_reportFormatting, gesture)

# Translators: Describes action of routing buttons on a braille display.
script_upperRouting.__doc__ = _("Route to and report formatting")

def terminate(self):
"""free resources"""
super(BrailleDisplayDriver, self).terminate()
Expand Down Expand Up @@ -211,6 +204,7 @@ def _handleKeyPresses(self): #called by the keycheck timer
"braille_previousLine": ("br(papenmeier_serial):up",),
"braille_nextLine": ("br(papenmeier_serial):dn",),
"braille_routeTo": ("br(papenmeier_serial):route",),
"braille_reportFormatting": ("br(papenmeier_serial):upperRouting",),

"braille_toggleTether": ("br(papenmeier_serial):r2",),
"review_currentCharacter": ("br(papenmeier_serial):l1",),
Expand All @@ -227,10 +221,6 @@ def _handleKeyPresses(self): #called by the keycheck timer
}
})

__gestures = {
"br(papenmeier_serial):upperRouting": "upperRouting",
}

def brl_keyname2(keys):
"""returns keyname for key index on displays with eab"""
if(keys & 4 == 4): return 'l1'
Expand Down
32 changes: 25 additions & 7 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2006-2017 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee, Leonard de Ruijter, Derek Riemer, Babbage B.V., Ethan Holliger
#Copyright (C) 2006-2017 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee, Leonard de Ruijter, Derek Riemer, Babbage B.V., Davy Kager, Ethan Holliger

import time
import itertools
Expand Down Expand Up @@ -1279,7 +1279,7 @@ def script_sayAll(self,gesture):
script_sayAll.__doc__ = _("Reads from the system caret up to the end of the text, moving the caret as it goes")
script_sayAll.category=SCRCAT_SYSTEMCARET

def script_reportFormatting(self,gesture):
def _reportFormattingHelper(self, info, browseable=False):
formatConfig={
"detectFormatAfterCursor":False,
"reportFontName":True,"reportFontSize":True,"reportFontAttributes":True,"reportColor":True,"reportRevisions":False,"reportEmphasis":False,
Expand All @@ -1290,7 +1290,6 @@ def script_reportFormatting(self,gesture):
"reportBorderStyle":True,"reportBorderColor":True,
}
textList=[]
info=api.getReviewPosition()

# First, fetch indentation.
line=info.copy()
Expand All @@ -1299,14 +1298,14 @@ def script_reportFormatting(self,gesture):
if indentation:
textList.append(speech.getIndentationSpeech(indentation, formatConfig))

info=info.copy()
info.expand(textInfos.UNIT_CHARACTER)
formatField=textInfos.FormatField()
for field in info.getTextWithFields(formatConfig):
if isinstance(field,textInfos.FieldCommand) and isinstance(field.field,textInfos.FormatField):
formatField.update(field.field)

repeats=scriptHandler.getLastScriptRepeatCount()
if repeats==0:
if not browseable:
text=info.getFormatFieldSpeech(formatField,formatConfig=formatConfig) if formatField else None
if text:
textList.append(text)
Expand All @@ -1317,7 +1316,7 @@ def script_reportFormatting(self,gesture):
return

ui.message(" ".join(textList))
elif repeats==1:
else:
text=info.getFormatFieldSpeech(formatField,formatConfig=formatConfig , separator="\n") if formatField else None
if text:
textList.append(text)
Expand All @@ -1328,7 +1327,15 @@ def script_reportFormatting(self,gesture):
return

# Translators: title for formatting information dialog.
ui.browseableMessage(("\n".join(textList) ) , _("Formatting"))
ui.browseableMessage("\n".join(textList), _("Formatting"))

def script_reportFormatting(self,gesture):
info=api.getReviewPosition()
repeats=scriptHandler.getLastScriptRepeatCount()
if repeats==0:
self._reportFormattingHelper(info,False)
elif repeats==1:
self._reportFormattingHelper(info,True)
# Translators: Input help mode message for report formatting command.
script_reportFormatting.__doc__ = _("Reports formatting info for the current review cursor position within a document. If pressed twice, presents the information in browse mode")
script_reportFormatting.category=SCRCAT_TEXTREVIEW
Expand Down Expand Up @@ -1907,6 +1914,17 @@ def script_braille_routeTo(self, gesture):
script_braille_routeTo.__doc__ = _("Routes the cursor to or activates the object under this braille cell")
script_braille_routeTo.category=SCRCAT_BRAILLE

def script_braille_reportFormatting(self, gesture):
info = braille.handler.getTextInfoForWindowPos(gesture.routingIndex)
if info is None:
# Translators: Reported when trying to obtain formatting information (such as font name, indentation and so on) but there is no formatting information for the text under cursor.
ui.message(_("No formatting information"))
return
self._reportFormattingHelper(info, False)
# Translators: Input help mode message for Braille report formatting command.
script_braille_reportFormatting.__doc__ = _("Reports formatting info for the text under this braille cell")
script_braille_reportFormatting.category=SCRCAT_BRAILLE

def script_braille_previousLine(self, gesture):
if braille.handler.buffer.regions:
braille.handler.buffer.regions[-1].previousLine(start=True)
Expand Down
2 changes: 1 addition & 1 deletion source/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
HTMLDLG_PRINT_TEMPLATE = 0x0080
HTMLDLG_VERIFY = 0x0100

def browseableMessage(message,title=None , isHtml=False):
def browseableMessage(message,title=None,isHtml=False):
"""Present a message to the user that can be read in browse mode.
The message will be presented in an HTML document.
@param message: The message in either html or text.
Expand Down
12 changes: 7 additions & 5 deletions user_docs/en/userGuide.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ Please see the display's documentation for descriptions of where these keys can
| Move braille display to next line | t4 |
| Scroll braille display forward | t5 or etouch3 |
| Route to braille cell | routing |
| Report text formatting under braille cell | secondary routing |
| Toggle HID keyboard simulation | t1+spEnter |
| Move to top line in review | t1+t2 |
| Move to bottom line in review | t4+t5 |
Expand Down Expand Up @@ -2274,7 +2275,7 @@ Following are the Papenmeier command assignments for NVDA:
| Move to first contained object | dn2 |
| Move to previous object | left2 |
| Move to next object | right2 |
| Report text formatting | upper routing row |
| Report text formatting under braille cell | upper routing row |
%kc:endInclude

The Trio model has four additional keys which are in front of the braille keyboard.
Expand Down Expand Up @@ -2348,7 +2349,7 @@ Devices with EAB:
| Move to first contained object | dn2 |
| Move to next object | right2 |
| Move to previous object | left2 |
| Report text formatting | Upper routing strip |
| Report text formatting under braille cell | upper routing strip |

BRAILLEX Tiny:
|| Name | Key |
Expand All @@ -2363,7 +2364,7 @@ BRAILLEX Tiny:
| Move to first contained object | r1+dn |
| Move to previous object | r1+left |
| Move to next object | r1+right |
| Report text formatting | reportf |
| Report text formatting under braille cell | upper routing strip |
| Report title | l1+up |
| Report status bar | l2+down |

Expand All @@ -2372,7 +2373,7 @@ BRAILLEX 2D Screen:
| Report current character in review | l1 |
| Activate current navigator object | l2 |
| Toggle braille tethered to | r2 |
| Report text formatting | reportf |
| Report text formatting under braille cell | upper routing strip |
| Move braille display to previous line | up |
| Scroll braille display back | left |
| Scroll braille display forward | right |
Expand Down Expand Up @@ -2495,7 +2496,8 @@ Please see the display's documentation for descriptions of where these keys can
| Scroll braille display back | switch1-6left, l1 |
| Scroll braille display forward | switch1-6Right, l8 |
| Move to current focus | switch1-6Left+switch1-6Right, l1+l8 |
| Route to braille cell | routing, doubleRouting|
| Route to braille cell | routing |
| Report text formatting under braille cell | doubleRouting |
| Move to previous line in review | joystick1Up |
| Move to next line in review | joystick1Down |
| Move to previous character in review | joystick1Left |
Expand Down

0 comments on commit 9dd4836

Please sign in to comment.