diff --git a/source/NVDAObjects/IAccessible/sysTreeView32.py b/source/NVDAObjects/IAccessible/sysTreeView32.py index 90b60809090..432ab3bc28b 100755 --- a/source/NVDAObjects/IAccessible/sysTreeView32.py +++ b/source/NVDAObjects/IAccessible/sysTreeView32.py @@ -12,7 +12,7 @@ import speech import UIAHandler from . import IAccessible -if UIAHandler.isUIAAvailable: from ..UIA import UIA +from ..UIA import UIA from .. import NVDAObject from logHandler import log import watchdog diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py index 5b936ddc01f..80600dd416a 100644 --- a/source/NVDAObjects/UIA/__init__.py +++ b/source/NVDAObjects/UIA/__init__.py @@ -90,7 +90,7 @@ def _get_controlFieldNVDAObjectClass(self): UIAHandler.UIA_AriaPropertiesPropertyId, UIAHandler.UIA_LevelPropertyId, UIAHandler.UIA_IsEnabledPropertyId, - } if UIAHandler.isUIAAvailable else set() + } def _get__controlFieldUIACacheRequest(self): """ The UIA cacheRequest object that will be used when fetching all UIA elements needed when generating control fields for this TextInfo's content.""" @@ -108,7 +108,7 @@ def _get__controlFieldUIACacheRequest(self): UIAHandler.TextUnit_Format, UIAHandler.TextUnit_Word, UIAHandler.TextUnit_Character - ] if UIAHandler.isUIAAvailable else [] + ] def find(self,text,caseSensitive=False,reverse=False): tempRange=self._rangeObj.clone() @@ -379,7 +379,7 @@ def _get_bookmark(self): UIAHandler.UIA_TabItemControlTypeId, UIAHandler.UIA_TextControlTypeId, UIAHandler.UIA_SplitButtonControlTypeId - } if UIAHandler.isUIAAvailable else None + } def _getControlFieldForObject(self, obj,isEmbedded=False,startOfNode=False,endOfNode=False): @@ -1186,7 +1186,7 @@ def _get_keyboardShortcut(self): UIAHandler.UIA_IsSelectionItemPatternAvailablePropertyId, UIAHandler.UIA_IsEnabledPropertyId, UIAHandler.UIA_IsOffscreenPropertyId, - } if UIAHandler.isUIAAvailable else set() + } def _get_states(self): states=set() diff --git a/source/UIAHandler.py b/source/UIAHandler.py index fb2c26c4d2d..528af0a81c0 100644 --- a/source/UIAHandler.py +++ b/source/UIAHandler.py @@ -7,32 +7,24 @@ from comtypes import COMError import config from logHandler import log +# Maintain backwards compatibility: F403 (unable to detect undefined names) flake8 warning. +from _UIAHandler import * # noqa: F403 # Make the _UIAHandler._isDebug function available to this module, # ignoring the fact that it is not used here directly. from _UIAHandler import _isDebug # noqa: F401 handler=None -isUIAAvailable=False - -if config.conf and config.conf["UIA"]["enabled"]: - # Because Windows 7 SP1 (NT 6.1) or later is supported, just assume UIA can be used unless told otherwise. - try: - from _UIAHandler import * - isUIAAvailable=True - except ImportError: - log.debugWarning("Unable to import _UIAHandler",exc_info=True) - pass def initialize(): global handler - if not isUIAAvailable: - raise NotImplementedError + if not config.conf["UIA"]["enabled"]: + raise RuntimeError("UIA forcefully disabled in configuration") try: handler=UIAHandler() except COMError: handler=None - raise RuntimeError("UIA not available") + raise def terminate(): global handler diff --git a/source/appModules/logonui.py b/source/appModules/logonui.py index 6bda268785d..1092f8d94a2 100644 --- a/source/appModules/logonui.py +++ b/source/appModules/logonui.py @@ -13,8 +13,7 @@ import appModuleHandler import eventHandler import UIAHandler -if UIAHandler.isUIAAvailable: - from NVDAObjects.UIA import UIA +from NVDAObjects.UIA import UIA """App module for the Windows Logon screen """ @@ -35,16 +34,17 @@ def event_gainFocus(self): return super(LogonDialog, self).event_gainFocus() -if UIAHandler.isUIAAvailable: - class Win8PasswordField(UIA): - #This UIA object has no invoke pattern, at least set focus. - # #6024: Affects both Windows 8.x and 10. - def doAction(self,index=None): - if not index: - self.setFocus() - else: - super(Win8PasswordField,self).doAction(index) +class Win8PasswordField(UIA): + + # This UIA object has no invoke pattern, at least set focus. + # #6024: Affects both Windows 8.x and 10. + def doAction(self, index=None): + if not index: + self.setFocus() + else: + super().doAction(index) + class XPPasswordField(IAccessible): @@ -82,7 +82,7 @@ def event_NVDAObject_init(self, obj): def chooseNVDAObjectOverlayClasses(self, obj, clsList): windowClass = obj.windowClassName - if UIAHandler.isUIAAvailable: + if UIAHandler.handler: if isinstance(obj,UIA) and obj.UIAElement.cachedClassName in ("TouchEditInner", "PasswordBox") and obj.role==controlTypes.ROLE_EDITABLETEXT: clsList.insert(0,Win8PasswordField) # #6010: Allow Windows 10 version to be recognized as well. diff --git a/source/core.py b/source/core.py index 63ae2b2fcce..c40501a9218 100644 --- a/source/core.py +++ b/source/core.py @@ -435,8 +435,8 @@ def handlePowerStatusChange(self): log.debug("Initializing UIA support") try: UIAHandler.initialize() - except NotImplementedError: - log.warning("UIA not available") + except RuntimeError: + log.warning("UIA disabled in configuration") except: log.error("Error initializing UIA support", exc_info=True) import IAccessibleHandler