Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the review cursor to be bounded to onscreen text #9735

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7a123c3
Remove bounds checking code from the console.
codeofdusk Jun 13, 2019
a61dab0
Implement isOutOfBounds.
codeofdusk Jun 13, 2019
a8b93bd
Implement review bounds configuration.
codeofdusk Jun 13, 2019
6bb21b2
Fix isOutOfBounds for UIA, implement initial bounds checking, and bou…
codeofdusk Jun 13, 2019
deffcea
Implement review of top and bottom lines when review is bounded.
codeofdusk Jun 13, 2019
51fa56a
Add new gesture to the input gestures dialog, update user guide.
codeofdusk Jun 13, 2019
a1ad305
Implement review bounds configuration for offsetsTextInfo.
codeofdusk Jun 13, 2019
d7a00e8
Apply suggestions from code review
codeofdusk Jun 13, 2019
1a937d2
Review actions.
codeofdusk Jun 13, 2019
536ccce
isOutOfBounds -> isOffscreen
codeofdusk Jun 13, 2019
d84570a
Move SCRCAT constants to a new scriptCategories module.
codeofdusk Jun 13, 2019
4540972
Review actions.
codeofdusk Jun 18, 2019
b7126db
Merge branch 'master' into reviewbounds
codeofdusk Jun 18, 2019
0f41ef3
Merge branch 'master' into reviewbounds
codeofdusk Jun 18, 2019
768cf6b
Clarify doc comment.
codeofdusk Jun 18, 2019
4cc443f
Add unique IDs for NVDA objects.
codeofdusk Jun 20, 2019
291b00e
Persist review bounds state when an object is regenerated.
codeofdusk Jun 20, 2019
c94229b
Make isOffscreen a property.
codeofdusk Jun 20, 2019
b2924fa
Fixes.
codeofdusk Jun 21, 2019
2c24358
Better default review bounds configuration for objects.
codeofdusk Jun 21, 2019
959a6c7
Remove unneeded import.
codeofdusk Jun 21, 2019
360ce53
Merge branch 'master' into reviewbounds
codeofdusk Jun 21, 2019
7146fae
Merge branch 'master' into reviewbounds
codeofdusk Jul 7, 2019
2f85736
Merge branch 'master' into reviewbounds
codeofdusk Jul 16, 2019
87d67e7
Revert "Add unique IDs for NVDA objects."
codeofdusk Jul 16, 2019
d41476b
Revert "Persist review bounds state when an object is regenerated."
codeofdusk Jul 16, 2019
8c50383
Revert "Better default review bounds configuration for objects."
codeofdusk Jul 16, 2019
cf11cdd
Make review bounds state global and bound review by default where sup…
codeofdusk Jul 16, 2019
11f0d59
Disable bounds checking if we're currently offscreen to avoid getting…
codeofdusk Jul 17, 2019
bd33c92
In UIA consoles, diff the entire buffer instead of just the visible r…
codeofdusk Jul 17, 2019
f3ff4a2
Fix top/bottom review scripts.
codeofdusk Jul 17, 2019
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
4 changes: 2 additions & 2 deletions developerGuide.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ For example:
--- start ---
@script(
description=_("Speaks the date and time"),
category=inputCore.SCRCAT_MISC,
category=scriptCategories.SCRCAT_MISC,
gestures=["kb:NVDA+shift+t", "kb:NVDA+alt+r"]
)
def script_sayDateTime(self, gesture):
Expand All @@ -421,7 +421,7 @@ The following keyword arguments can be used when applying the script decorator:
- category: The category of the script in order for it to be grouped with other similar scripts.
For example, a script in a global plugin which adds browse mode quick navigation keys may be categorized under the "Browse mode" category.
The category can be set for individual scripts, but you can also set the "scriptCategory" attribute on the plugin class, which will be used for scripts which do not specify a category.
There are constants for common categories prefixed with SCRCAT_ in the inputCore and globalCommands modules, which can also be specified.
There are constants for common categories prefixed with SCRCAT_ in the scriptCategories module, which can also be specified.
The script will be listed under the specified category in the Input Gestures dialog.
If no category is specified, the script will be categorized under "Miscellaneous".
- gesture: A string containing a single gesture associated with this script, e.g. "kb:NVDA+shift+r".
Expand Down
27 changes: 27 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ def __init__(self,obj,position,_rangeObj=None):
elif position==textInfos.POSITION_LAST:
self._rangeObj=self.obj.UIATextPattern.documentRange
self.collapse(True)
elif position in (textInfos.POSITION_FIRSTVISIBLE, textInfos.POSITION_LASTVISIBLE):
try:
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
element = 0 if position == textInfos.POSITION_FIRSTVISIBLE else visiRanges.length - 1
self._rangeObj = visiRanges.GetElement(element)
except COMError:
# Error: FIRST_VISIBLE/LAST_VISIBLE position not supported by the UIA text pattern.
raise NotImplementedError
elif position==textInfos.POSITION_ALL or position==self.obj:
self._rangeObj=self.obj.UIATextPattern.documentRange
elif isinstance(position,UIA) or isinstance(position,UIAHandler.IUIAutomationElement):
Expand Down Expand Up @@ -702,6 +710,25 @@ def compareEndPoints(self,other,which):
target=UIAHandler.TextPatternRangeEndpoint_End
return self._rangeObj.CompareEndpoints(src,other._rangeObj,target)

def _get_isOffscreen(self):
try:
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
except COMError:
raise NotImplementedError
visiLength = visiRanges.length
if visiLength > 0:
firstVisiRange = visiRanges.GetElement(0)
lastVisiRange = visiRanges.GetElement(visiLength - 1)
return self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange,
UIAHandler.TextPatternRangeEndpoint_Start
) < 0 or self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange,
UIAHandler.TextPatternRangeEndpoint_End) >= 0
else:
# Review bounds not available.
return super(UIATextInfo, self).isOffscreen()

def setEndPoint(self,other,which):
if which.startswith('start'):
src=UIAHandler.TextPatternRangeEndpoint_Start
Expand Down
31 changes: 7 additions & 24 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ def collapse(self,end=False):
)

def move(self, unit, direction, endPoint=None):
oldRange = None
if self.basePosition != textInfos.POSITION_CARET:
# Insure we haven't gone beyond the visible text.
# UIA adds thousands of blank lines to the end of the console.
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
visiLength = visiRanges.length
if visiLength > 0:
firstVisiRange = visiRanges.GetElement(0)
lastVisiRange = visiRanges.GetElement(visiLength - 1)
oldRange = self._rangeObj.clone()
if unit == textInfos.UNIT_WORD and direction != 0:
# UIA doesn't implement word movement, so we need to do it manually.
# Relative to the current line, calculate our offset
Expand Down Expand Up @@ -106,18 +96,8 @@ def move(self, unit, direction, endPoint=None):
endPoint=endPoint
)
else: # moving by a unit other than word
res = super(consoleUIATextInfo, self).move(unit, direction,
return super(consoleUIATextInfo, self).move(unit, direction,
endPoint)
if oldRange and (
self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange,
UIAHandler.TextPatternRangeEndpoint_Start) < 0
or self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange,
UIAHandler.TextPatternRangeEndpoint_End) >= 0):
self._rangeObj = oldRange
return 0
return res

def expand(self, unit):
if unit == textInfos.UNIT_WORD:
Expand Down Expand Up @@ -292,9 +272,12 @@ def script_flush_queuedChars(self, gesture):

def _getTextLines(self):
# Filter out extraneous empty lines from UIA
ptr = self.UIATextPattern.GetVisibleRanges()
res = [ptr.GetElement(i).GetText(-1) for i in range(ptr.length)]
return res
return (
self.makeTextInfo(textInfos.POSITION_ALL)
._rangeObj.getText(-1)
.rstrip()
.split("\r\n")
)

def _calculateNewText(self, newLines, oldLines):
self._hasNewLines = (
Expand Down
1 change: 1 addition & 0 deletions source/NVDAObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import braille
import globalPluginHandler
import brailleInput
import scriptCategories

class NVDAObjectTextInfo(textInfos.offsets.OffsetsTextInfo):
"""A default TextInfo which is used to enable text review of information about widgets that don't support text content.
Expand Down
5 changes: 5 additions & 0 deletions source/displayModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,8 @@ def _setSelectionOffsets(self,start,end):
if start!=end:
raise NotImplementedError("Expanded selections not supported")
self._setCaretOffset(start)

def isOffscreen(self):
"""DisplayModelTextInfo instances only show screen contents, so
unbounding is impossible."""
raise NotImplementedError
15 changes: 13 additions & 2 deletions source/documentBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ui
import controlTypes

class TextContainerObject(AutoPropertyObject):
class TextContainerObject(ScriptableObject):
"""
An object that contains text which can be accessed via a call to a makeTextInfo method.
E.g. NVDAObjects, BrowseModeDocument TreeInterceptors.
Expand All @@ -21,14 +21,25 @@ def _get_TextInfo(self):
raise NotImplementedError

def makeTextInfo(self,position):
return self.TextInfo(self,position)
try:
return self.TextInfo(self,position)
except NotImplementedError as e:
if position == textInfos.POSITION_FIRSTVISIBLE:
# Fall back to POSITION_FIRST
return self.makeTextInfo(textInfos.POSITION_FIRST)
elif position == textInfos.POSITION_LASTVISIBLE:
# Fall back to POSITION_LAST
return self.makeTextInfo(textInfos.POSITION_LAST)
else:
raise e

def _get_selection(self):
return self.makeTextInfo(textInfos.POSITION_SELECTION)

def _set_selection(self,info):
info.updateSelection()


class DocumentWithTableNavigation(TextContainerObject,ScriptableObject):
"""
A document that supports standard table navigiation comments (E.g. control+alt+arrows to move between table cells).
Expand Down
125 changes: 74 additions & 51 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import treeInterceptorHandler
import browseMode
import scriptHandler
from scriptHandler import script
from scriptCategories import *
import ui
import braille
import brailleInput
Expand All @@ -44,49 +44,6 @@
import winVersion
from base64 import b16encode

#: Script category for text review commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TEXTREVIEW = _("Text review")
#: Script category for Object navigation commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_OBJECTNAVIGATION = _("Object navigation")
#: Script category for system caret commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SYSTEMCARET = _("System caret")
#: Script category for mouse commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_MOUSE = _("Mouse")
#: Script category for speech commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SPEECH = _("Speech")
#: Script category for configuration dialogs commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_CONFIG = _("Configuration")
#: Script category for configuration profile activation and management commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_CONFIG_PROFILES = _("Configuration profiles")
#: Script category for Braille commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_BRAILLE = _("Braille")
#: Script category for tools commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TOOLS = pgettext('script category', 'Tools')
#: Script category for touch commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_TOUCH = _("Touch screen")
#: Script category for focus commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_FOCUS = _("System focus")
#: Script category for system status commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_SYSTEM = _("System status")
#: Script category for input commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_INPUT = _("Input")
#: Script category for document formatting commands.
# Translators: The name of a category of NVDA commands.
SCRCAT_DOCUMENTFORMATTING = _("Document formatting")

class GlobalCommands(ScriptableObject):
"""Commands that are available at all times, regardless of the current focus.
"""
Expand Down Expand Up @@ -972,8 +929,35 @@ def script_review_activate(self,gesture):
script_review_activate.__doc__=_("Performs the default action on the current navigator object (example: presses it if it is a button).")
script_review_activate.category=SCRCAT_OBJECTNAVIGATION

def _moveWithBoundsChecking(self, info, unit, direction, endPoint=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be moved into the base TextInfo class.
Also, is there a reason why this is non-distructive (I.e. returns a copy)? I don't think you actually ever make use of this. It could just do it distructively and return res like the other move... unless you have a particular plan for this not yet done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a generalization of the console's old bounds checking code (i.e. we captured an oldRange and didn't update the underlying UIA text range if a move was impossible). Would destructive be okay here?

"""
Nondestructively moves a textInfo and returns a (newInfo, res) tuple.
Res is 0 and the original C{textInfo} is returned if the move would be out of bounds.
"""
try:
if info.isOffscreen:
res = info.move(unit, direction, endPoint=endPoint)
return (info, res)
except NotImplementedError:
pass
newInfo = info.copy()
res = newInfo.move(unit, direction, endPoint=endPoint)
try:
if globalVars.reviewBounded and newInfo.isOffscreen:
return (info, 0)
except NotImplementedError:
pass
return (newInfo, res)

def script_review_top(self,gesture):
info=api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_FIRST)
rp = api.getReviewPosition()
pos = textInfos.POSITION_FIRST
try:
if globalVars.reviewBounded and not rp.isOffscreen:
pos = textInfos.POSITION_FIRSTVISIBLE
except NotImplementedError:
pass
info = rp.obj.makeTextInfo(pos)
api.setReviewPosition(info)
info.expand(textInfos.UNIT_LINE)
ui.reviewMessage(_("Top"))
Expand All @@ -987,7 +971,7 @@ def script_review_previousLine(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_LINE)
info.collapse()
res=info.move(textInfos.UNIT_LINE,-1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_LINE,-1)
if res==0:
# Translators: a message reported when review cursor is at the top line of the current navigator object.
ui.reviewMessage(_("Top"))
Expand Down Expand Up @@ -1019,7 +1003,7 @@ def script_review_nextLine(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_LINE)
info.collapse()
res=info.move(textInfos.UNIT_LINE,1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_LINE,1)
if res==0:
# Translators: a message reported when review cursor is at the bottom line of the current navigator object.
ui.reviewMessage(_("Bottom"))
Expand All @@ -1033,7 +1017,14 @@ def script_review_nextLine(self,gesture):
script_review_nextLine.category=SCRCAT_TEXTREVIEW

def script_review_bottom(self,gesture):
info=api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_LAST)
rp = api.getReviewPosition()
pos = textInfos.POSITION_LAST
try:
if globalVars.reviewBounded and not rp.isOffscreen:
pos = textInfos.POSITION_LASTVISIBLE
except NotImplementedError:
pass
info = rp.obj.makeTextInfo(pos)
api.setReviewPosition(info)
info.expand(textInfos.UNIT_LINE)
ui.reviewMessage(_("Bottom"))
Expand All @@ -1047,7 +1038,7 @@ def script_review_previousWord(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_WORD)
info.collapse()
res=info.move(textInfos.UNIT_WORD,-1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_WORD,-1)
if res==0:
# Translators: a message reported when review cursor is at the top line of the current navigator object.
ui.reviewMessage(_("Top"))
Expand Down Expand Up @@ -1078,7 +1069,7 @@ def script_review_nextWord(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_WORD)
info.collapse()
res=info.move(textInfos.UNIT_WORD,1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_WORD,1)
if res==0:
# Translators: a message reported when review cursor is at the bottom line of the current navigator object.
ui.reviewMessage(_("Bottom"))
Expand Down Expand Up @@ -1206,7 +1197,7 @@ def _getCurrentLanguageForTextInfo(self, info):
curLanguage = speech.getCurrentLanguage()
return curLanguage

@script(
@scriptHandler.script(
# Translators: Input help mode message for Review Current Symbol command.
description=_("Reports the symbol where the review cursor is positioned. Pressed twice, shows the symbol and the text used to speak it in browse mode"),
category=SCRCAT_TEXTREVIEW,
Expand Down Expand Up @@ -2286,6 +2277,37 @@ def script_recognizeWithUwpOcr(self, gesture):
# Translators: Describes a command.
script_recognizeWithUwpOcr.__doc__ = _("Recognizes the content of the current navigator object with Windows 10 OCR")

def script_toggleReviewBounds(self, gesture):
rp = api.getReviewPosition()
outOfBounds = None
try:
outOfBounds = rp.isOffscreen
except NotImplementedError:
ui.message(
# Translators: Reported when review bound configuration isn't supported for this object.
_(u"Not supported here"))
else:
globalVars.reviewBounded = not globalVars.reviewBounded
if globalVars.reviewBounded:
ui.message(
# Translators: Reported when review is constrained to this
# object's visible text.
_(u"Bounded review")
)
if outOfBounds:
api.setReviewPosition(
api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_CARET))
else:
ui.message(
# Translators: Reported when review is unconstrained, so all
# of this object's text can be read.
_(u"Unbounded review")
)

# Translators: A gesture description.
script_toggleReviewBounds.__doc__ = _(u"Toggles whether review is constrained to the currently visible text")
script_toggleReviewBounds.category=SCRCAT_TEXTREVIEW

__gestures = {
# Basic
"kb:NVDA+n": "showGui",
Expand Down Expand Up @@ -2397,6 +2419,7 @@ def script_recognizeWithUwpOcr(self, gesture):
"kb:NVDA+numpad1": "reviewMode_previous",
"kb(laptop):NVDA+pageDown": "reviewMode_previous",
"ts(object):2finger_flickDown": "reviewMode_previous",
"kb:NVDA+o": "toggleReviewBounds",

# Mouse
"kb:numpadDivide": "leftMouseClick",
Expand Down
2 changes: 2 additions & 0 deletions source/globalVars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@type navigatorObject: L{NVDAObjects.NVDAObject}
@var navigatorTracksFocus: if true, the navigator object will follow the focus as it changes
@type navigatorTracksFocus: boolean
@var reviewBounded: Whether the review cursor is bounded to the currently visible text.
"""

startTime=0
Expand All @@ -32,6 +33,7 @@
navigatorObject=None
reviewPosition=None
reviewPositionObj=None
reviewBounded = True
lastProgressValue=0
appArgs=None
appArgsExtra=None
Expand Down
Loading