Skip to content

Commit

Permalink
UI Automation in Windows Console: add focus redirection for the UIA c…
Browse files Browse the repository at this point in the history
…onsole main window (#9674)

* Add focus redirection for the UIA console main window.

* Implement winConsoleUIA.findExtraOverlayClasses.

* If->elif
  • Loading branch information
codeofdusk authored and michaelDCurran committed Jun 11, 2019
1 parent 549a6aa commit 11ec1be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,10 @@ def findOverlayClasses(self,clsList):
# Support Windows Console's UIA interface
if (
self.windowClassName == "ConsoleWindowClass"
and self.UIAElement.cachedAutomationId == "Text Area"
and config.conf['UIA']['winConsoleImplementation'] == "UIA"
):
from .winConsoleUIA import winConsoleUIA
clsList.append(winConsoleUIA)
from . import winConsoleUIA
winConsoleUIA.findExtraOverlayClasses(self, clsList)
# Add editableText support if UIA supports a text pattern
if self.TextInfo==UIATextInfo:
clsList.append(EditableTextWithoutAutoSelectDetection)
Expand Down
21 changes: 21 additions & 0 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from winVersion import isAtLeastWin10
from . import UIATextInfo
from ..behaviors import Terminal
from ..window import Window


class consoleUIATextInfo(UIATextInfo):
Expand Down Expand Up @@ -183,6 +184,20 @@ def _getWordOffsetsInThisLine(self, offset, lineInfo):
)


class consoleUIAWindow(Window):
def _get_focusRedirect(self):
"""
Sometimes, attempting to interact with the console too quickly after
focusing the window can make NVDA unable to get any caret or review
information or receive new text events.
To work around this, we must redirect focus to the console text area.
"""
for child in self.children:
if isinstance(child, winConsoleUIA):
return child
return None


class winConsoleUIA(Terminal):
STABILIZE_DELAY = 0.03
_TextInfo = consoleUIATextInfo
Expand Down Expand Up @@ -243,3 +258,9 @@ def _getTextLines(self):
ptr = self.UIATextPattern.GetVisibleRanges()
res = [ptr.GetElement(i).GetText(-1) for i in range(ptr.length)]
return res

def findExtraOverlayClasses(obj, clsList):
if obj.UIAElement.cachedAutomationId == "Text Area":
clsList.append(winConsoleUIA)
elif obj.UIAElement.cachedAutomationId == "Console Window":
clsList.append(consoleUIAWindow)

0 comments on commit 11ec1be

Please sign in to comment.