From d90ea79e940961dd4defe8adfc81b8e3e82528b3 Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Fri, 31 May 2019 14:14:25 +0200 Subject: [PATCH 1/8] Use auto select detection for UIA when listening for TextChanged and TextSelectionChanged events --- source/NVDAObjects/UIA/__init__.py | 16 +++++++++++++--- source/NVDAObjects/window/winword.py | 11 +++++++---- source/_UIAHandler.py | 10 +++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py index 9e24448b21b..ab9c12db1d0 100644 --- a/source/NVDAObjects/UIA/__init__.py +++ b/source/NVDAObjects/UIA/__init__.py @@ -28,7 +28,14 @@ from UIAUtils import * from NVDAObjects.window import Window from NVDAObjects import NVDAObjectTextInfo, InvalidNVDAObject -from NVDAObjects.behaviors import ProgressBar, EditableTextWithoutAutoSelectDetection, Dialog, Notification, EditableTextWithSuggestions +from NVDAObjects.behaviors import ( + ProgressBar, + EditableTextWithoutAutoSelectDetection, + EditableTextWithAutoSelectDetection, + Dialog, + Notification, + EditableTextWithSuggestions +) import braille from locationHelper import RectLTWH import ui @@ -868,7 +875,10 @@ def findOverlayClasses(self,clsList): clsList.append(winConsoleUIA) # Add editableText support if UIA supports a text pattern if self.TextInfo==UIATextInfo: - clsList.append(EditableTextWithoutAutoSelectDetection) + if UIAHandler.autoSelectDetectionAvailable: + clsList.append(EditableTextWithAutoSelectDetection) + else: + clsList.append(EditableTextWithoutAutoSelectDetection) clsList.append(UIA) @@ -1452,7 +1462,7 @@ def event_UIA_elementSelected(self): self.event_stateChange() def event_valueChange(self): - if isinstance(self, EditableTextWithoutAutoSelectDetection): + if self.TextInfo==UIATextInfo: return return super(UIA, self).event_valueChange() diff --git a/source/NVDAObjects/window/winword.py b/source/NVDAObjects/window/winword.py index 87464e77556..a2803528b47 100755 --- a/source/NVDAObjects/window/winword.py +++ b/source/NVDAObjects/window/winword.py @@ -1431,6 +1431,13 @@ def script_changeLineSpacing(self,gesture): # Translators: a message when switching to 1.5 line spaceing in Microsoft word ui.message(_("1.5 line spacing")) + def initOverlayClass(self): + if isinstance(self, EditableTextWithoutAutoSelectDetection): + self.bindGesture("kb:alt+shift+home", "caret_changeSelection") + self.bindGesture("kb:alt+shift+end", "caret_changeSelection") + self.bindGesture("kb:alt+shift+pageUp", "caret_changeSelection",) + self.bindGesture("kb:alt+shift+pageDown", "caret_changeSelection",) + __gestures = { "kb:control+[":"increaseDecreaseFontSize", "kb:control+]":"increaseDecreaseFontSize", @@ -1458,10 +1465,6 @@ def script_changeLineSpacing(self,gesture): "kb:control+5":"changeLineSpacing", "kb:tab": "tab", "kb:shift+tab": "tab", - "kb:alt+shift+home":"caret_changeSelection", - "kb:alt+shift+end":"caret_changeSelection", - "kb:alt+shift+pageUp":"caret_changeSelection", - "kb:alt+shift+pageDown":"caret_changeSelection", "kb:control+pageUp": "caret_moveByLine", "kb:control+pageDown": "caret_moveByLine", } diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 090fbeaf68e..5564dedc3e2 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -1,6 +1,6 @@ #_UIAHandler.py #A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2011-2019 NV Access Limited, Joseph Lee, Babbage B.V. +#Copyright (C) 2011-2019 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter #This file is covered by the GNU General Public License. #See the file COPYING for more details. @@ -142,7 +142,6 @@ UIA_SelectionItem_ElementAddedToSelectionEventId:"stateChange", UIA_SelectionItem_ElementRemovedFromSelectionEventId:"stateChange", #UIA_MenuModeEndEventId:"menuModeEnd", - #UIA_Text_TextSelectionChangedEventId:"caret", UIA_ToolTipOpenedEventId:"UIA_toolTipOpened", #UIA_AsyncContentLoadedEventId:"documentLoadComplete", #UIA_ToolTipClosedEventId:"hide", @@ -150,8 +149,13 @@ UIA_SystemAlertEventId:"UIA_systemAlert", } +autoSelectDetectionAvailable = False if winVersion.isAtLeastWin10(): - UIAEventIdsToNVDAEventNames[UIA_Text_TextChangedEventId] = "textChange" + UIAEventIdsToNVDAEventNames.update({ + UIA_Text_TextChangedEventId:"textChange", + UIA_Text_TextSelectionChangedEventId:"caret", + }) + autoSelectDetectionAvailable = True ignoreWinEventsMap = { UIA_AutomationPropertyChangedEventId: list(UIAPropertyIdsToNVDAEventNames.keys()), From 5f64b1c192a48b65e6dcf14893ca6201ff28484f Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Sat, 1 Jun 2019 19:43:14 +0200 Subject: [PATCH 2/8] event_valueChange, make sure we match on UIATextInfo and subclasses to ignore them if appropriate --- source/NVDAObjects/UIA/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py index ab9c12db1d0..995bb00cdf2 100644 --- a/source/NVDAObjects/UIA/__init__.py +++ b/source/NVDAObjects/UIA/__init__.py @@ -1462,7 +1462,7 @@ def event_UIA_elementSelected(self): self.event_stateChange() def event_valueChange(self): - if self.TextInfo==UIATextInfo: + if issubclass(self.TextInfo, UIATextInfo): return return super(UIA, self).event_valueChange() From 54adf1ab2a456955d766293b5b623c4886934cec Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Sat, 1 Jun 2019 19:53:15 +0200 Subject: [PATCH 3/8] Make sure event_caret in UIABrowseMode executes nextHandler when in focus moude --- source/UIABrowseMode.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/UIABrowseMode.py b/source/UIABrowseMode.py index 86c285ab194..b7b14c55bab 100644 --- a/source/UIABrowseMode.py +++ b/source/UIABrowseMode.py @@ -444,6 +444,7 @@ def __contains__(self,obj): return True def event_caret(self,obj,nextHandler): - pass + if self.passThrough: + nextHandler() From 311c2482b7fba2f781d04e25049044aea6b7de9b Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Mon, 3 Jun 2019 19:59:37 +0200 Subject: [PATCH 4/8] Remove event_caret override from UIABrowseMode --- source/UIABrowseMode.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/UIABrowseMode.py b/source/UIABrowseMode.py index b7b14c55bab..b22efdf2d6f 100644 --- a/source/UIABrowseMode.py +++ b/source/UIABrowseMode.py @@ -442,9 +442,3 @@ def __contains__(self,obj): except LookupError: return False return True - - def event_caret(self,obj,nextHandler): - if self.passThrough: - nextHandler() - - From fe7bbf06a0991d2051f9977b7e65a9241bcb93f1 Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Mon, 3 Jun 2019 21:24:36 +0200 Subject: [PATCH 5/8] Fix autoselect detection in Excel edit fields --- source/_UIAHandler.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 5564dedc3e2..aeadde54022 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -274,12 +274,18 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID): NVDAEventName=UIAEventIdsToNVDAEventNames.get(eventID,None) if not NVDAEventName: return - if not self.isNativeUIAElement(sender): + focus=api.getFocusObject() + import NVDAObjects.UIA + if ( + isinstance(focus, NVDAObjects.UIA.UIA) + and self.clientObject.compareElements(focus.UIAElement, sender) + ): + pass + elif not self.isNativeUIAElement(sender): return window=self.getNearestWindowHandle(sender) if window and not eventHandler.shouldAcceptEvent(NVDAEventName,windowHandle=window): return - import NVDAObjects.UIA obj=NVDAObjects.UIA.UIA(UIAElement=sender) if ( not obj @@ -287,7 +293,6 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID): or (NVDAEventName=="liveRegionChange" and not obj._shouldAllowUIALiveRegionChangeEvent) ): return - focus=api.getFocusObject() if obj==focus: obj=focus eventHandler.queueEvent(NVDAEventName,obj) @@ -329,16 +334,21 @@ def IUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent(self,sen NVDAEventName=UIAPropertyIdsToNVDAEventNames.get(propertyId,None) if not NVDAEventName: return - if not self.isNativeUIAElement(sender): + focus = api.getFocusObject() + import NVDAObjects.UIA + if ( + isinstance(focus, NVDAObjects.UIA.UIA) + and self.clientObject.compareElements(focus.UIAElement, sender) + ): + pass + elif not self.isNativeUIAElement(sender): return window=self.getNearestWindowHandle(sender) if window and not eventHandler.shouldAcceptEvent(NVDAEventName,windowHandle=window): return - import NVDAObjects.UIA obj=NVDAObjects.UIA.UIA(UIAElement=sender) if not obj: return - focus=api.getFocusObject() if obj==focus: obj=focus eventHandler.queueEvent(NVDAEventName,obj) From ab80d9feadba8c5a949392273f75d71573545aca Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Fri, 2 Aug 2019 09:07:08 +0200 Subject: [PATCH 6/8] Fix most linting warnings --- source/UIAHandler.py | 10 +++++----- source/_UIAHandler.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/source/UIAHandler.py b/source/UIAHandler.py index 1eedf4ec0dc..cb1e628ca1b 100644 --- a/source/UIAHandler.py +++ b/source/UIAHandler.py @@ -1,8 +1,8 @@ -#UIAHandler.py -#A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2008-2018 NV Access Limited, Joseph Lee -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. +# UIAHandler.py +# A part of NonVisual Desktop Access (NVDA) +# Copyright (C) 2008-2018 NV Access Limited, Joseph Lee +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. from comtypes import COMError import config diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 1711463e67d..28cdd48ee31 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -154,9 +154,9 @@ autoSelectDetectionAvailable = False if winVersion.isWin10(): UIAEventIdsToNVDAEventNames.update({ - UIA_Text_TextChangedEventId:"textChange", - UIA_Text_TextSelectionChangedEventId:"caret", - }) + UIA_Text_TextChangedEventId: "textChange", + UIA_Text_TextSelectionChangedEventId: "caret", + }) autoSelectDetectionAvailable = True ignoreWinEventsMap = { @@ -277,7 +277,7 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID): NVDAEventName=UIAEventIdsToNVDAEventNames.get(eventID,None) if not NVDAEventName: return - focus=api.getFocusObject() + focus = api.getFocusObject() import NVDAObjects.UIA if ( isinstance(focus, NVDAObjects.UIA.UIA) From 471c27fb47489698641b59be106529e451262e08 Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Fri, 2 Aug 2019 09:48:28 +0200 Subject: [PATCH 7/8] More error fixes, except for f405 --- source/UIAHandler.py | 10 +++++----- source/_UIAHandler.py | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/source/UIAHandler.py b/source/UIAHandler.py index cb1e628ca1b..1eedf4ec0dc 100644 --- a/source/UIAHandler.py +++ b/source/UIAHandler.py @@ -1,8 +1,8 @@ -# UIAHandler.py -# A part of NonVisual Desktop Access (NVDA) -# Copyright (C) 2008-2018 NV Access Limited, Joseph Lee -# This file is covered by the GNU General Public License. -# See the file COPYING for more details. +#UIAHandler.py +#A part of NonVisual Desktop Access (NVDA) +#Copyright (C) 2008-2018 NV Access Limited, Joseph Lee +#This file is covered by the GNU General Public License. +#See the file COPYING for more details. from comtypes import COMError import config diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 28cdd48ee31..7dec1640ee2 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -1,8 +1,8 @@ -#_UIAHandler.py -#A part of NonVisual Desktop Access (NVDA) -#Copyright (C) 2011-2019 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. +# _UIAHandler.py +# A part of NonVisual Desktop Access (NVDA) +# Copyright (C) 2011-2019 NV Access Limited, Joseph Lee, Babbage B.V., Leonard de Ruijter +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. from ctypes import * from ctypes.wintypes import * @@ -155,8 +155,7 @@ if winVersion.isWin10(): UIAEventIdsToNVDAEventNames.update({ UIA_Text_TextChangedEventId: "textChange", - UIA_Text_TextSelectionChangedEventId: "caret", - }) + UIA_Text_TextSelectionChangedEventId: "caret", }) autoSelectDetectionAvailable = True ignoreWinEventsMap = { From ee6c547dfe04c1bf3fd3a07bbec20eabea73070d Mon Sep 17 00:00:00 2001 From: Leonard de Ruijter Date: Mon, 9 Sep 2019 09:29:43 +0200 Subject: [PATCH 8/8] Fix linting issues --- source/_UIAHandler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py index 5fe8896028e..5be59805e57 100644 --- a/source/_UIAHandler.py +++ b/source/_UIAHandler.py @@ -25,6 +25,7 @@ import eventHandler from logHandler import log import UIAUtils +from comtypes.gen import UIAutomationClient as UIA from comtypes.gen.UIAutomationClient import * #Some newer UIA constants that could be missing @@ -154,8 +155,8 @@ autoSelectDetectionAvailable = False if winVersion.isWin10(): UIAEventIdsToNVDAEventNames.update({ - UIA_Text_TextChangedEventId: "textChange", - UIA_Text_TextSelectionChangedEventId: "caret", }) + UIA.UIA_Text_TextChangedEventId: "textChange", + UIA.UIA_Text_TextSelectionChangedEventId: "caret", }) autoSelectDetectionAvailable = True ignoreWinEventsMap = {