Skip to content

Commit

Permalink
Merge 87ffa66 into 8c982cd
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Aug 27, 2022
2 parents 8c982cd + 87ffa66 commit 52a1c6e
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 87 deletions.
4 changes: 3 additions & 1 deletion source/NVDAHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import api
import globalVars
from logHandler import log
import NVDAState


versionedLibPath = os.path.join(globalVars.appDir, 'lib')
if os.environ.get('PROCESSOR_ARCHITEW6432') == 'ARM64':
Expand All @@ -35,7 +37,7 @@
versionedLib64Path = os.path.join(globalVars.appDir, 'lib64')


if not globalVars.runningAsSource:
if not NVDAState.isRunningAsSource():
# When running as a py2exe build, libraries are in a version-specific directory
versionedLibPath=os.path.join(versionedLibPath,versionInfo.version)
versionedLib64Path=os.path.join(versionedLib64Path,versionInfo.version)
Expand Down
5 changes: 3 additions & 2 deletions source/appModuleHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import baseObject
from logHandler import log
import NVDAHelper
import NVDAState
import winKernel
import config
import NVDAObjects #Catches errors before loading default appModule
Expand Down Expand Up @@ -86,7 +87,7 @@ def __getattr__(attrName: str) -> Any:
since add-ons are initialized before `appModuleHandler`
and when `appModuleHandler` was not yet initialized the variable was set to `None`.
"""
if attrName == "NVDAProcessID" and globalVars._allowDeprecatedAPI:
if attrName == "NVDAProcessID" and NVDAState._allowDeprecatedAPI():
log.warning("appModuleHandler.NVDAProcessID is deprecated, use globalVars.appPid instead.")
if initialize._alreadyInitialized:
return globalVars.appPid
Expand Down Expand Up @@ -114,7 +115,7 @@ def _warnDeprecatedAliasAppModule() -> None:
f" instead import appModules.{replacementModName}."
)
log.warning(deprecatedImportWarning)
if not globalVars._allowDeprecatedAPI:
if not NVDAState._allowDeprecatedAPI():
raise ModuleNotFoundError(deprecatedImportWarning)


Expand Down
4 changes: 2 additions & 2 deletions source/appModules/lockapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import config
import controlTypes
import eventHandler
import globalVars
import inputCore
from logHandler import log
from NVDAObjects import NVDAObject
from NVDAObjects.lockscreen import LockScreenObject
from NVDAObjects.UIA import UIA
import NVDAState
from utils.security import getSafeScripts
from winAPI.sessionTracking import isWindowsLocked

Expand All @@ -34,7 +34,7 @@
def __getattr__(attrName: str) -> Any:
"""Module level `__getattr__` used to preserve backward compatibility.
"""
if attrName == "LockAppObject" and globalVars._allowDeprecatedAPI:
if attrName == "LockAppObject" and NVDAState._allowDeprecatedAPI():
log.warning("lockapp.LockAppObject is deprecated, use NVDAObjects.lockscreen.LockScreenObject instead.")
return LockScreenObject
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")
Expand Down
6 changes: 4 additions & 2 deletions source/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
_validateConfig_featureFlag,
)
from typing import Any, Dict, List, Optional, Set
import NVDAState


#: True if NVDA is running as a Windows Store Desktop Bridge application
isAppX=False
Expand Down Expand Up @@ -66,10 +68,10 @@

def __getattr__(attrName: str) -> Any:
"""Module level `__getattr__` used to preserve backward compatibility."""
if attrName == "NVDA_REGKEY" and globalVars._allowDeprecatedAPI:
if attrName == "NVDA_REGKEY" and NVDAState._allowDeprecatedAPI():
log.warning("NVDA_REGKEY is deprecated, use RegistryKey.NVDA instead.")
return RegistryKey.NVDA.value
if attrName == "RUN_REGKEY" and globalVars._allowDeprecatedAPI:
if attrName == "RUN_REGKEY" and NVDAState._allowDeprecatedAPI():
log.warning("RUN_REGKEY is deprecated, use RegistryKey.RUN instead.")
return RegistryKey.RUN.value
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")
Expand Down
19 changes: 11 additions & 8 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import addonHandler
import extensionPoints
import garbageHandler
import NVDAState


# inform those who want to know that NVDA has finished starting up.
Expand Down Expand Up @@ -160,7 +161,7 @@ def restartUnsafely():
except ValueError:
pass
options = []
if globalVars.runningAsSource:
if NVDAState.isRunningAsSource():
options.append(os.path.basename(sys.argv[0]))
_startNewInstance(NewNVDAInstance(
sys.executable,
Expand All @@ -172,7 +173,7 @@ def restartUnsafely():
def restart(disableAddons=False, debugLogging=False):
"""Restarts NVDA by starting a new copy."""
if globalVars.appArgs.launcher:
globalVars.exitCode=3
NVDAState._setExitCode(3)
if not triggerNVDAExit():
log.error("NVDA already in process of exiting, this indicates a logic error.")
return
Expand All @@ -185,7 +186,7 @@ def restart(disableAddons=False, debugLogging=False):
except ValueError:
pass
options = []
if globalVars.runningAsSource:
if NVDAState.isRunningAsSource():
options.append(os.path.basename(sys.argv[0]))
if disableAddons:
options.append('--disable-addons')
Expand Down Expand Up @@ -483,8 +484,9 @@ def main():
import mathPres
log.debug("Initializing MathPlayer")
mathPres.initialize()
if not globalVars.appArgs.minimal and (time.time()-globalVars.startTime)>5:
log.debugWarning("Slow starting core (%.2f sec)" % (time.time()-globalVars.startTime))
timeSinceStart = time.time() - NVDAState.getStartTime()
if not globalVars.appArgs.minimal and timeSinceStart > 5:
log.debugWarning("Slow starting core (%.2f sec)" % timeSinceStart)
# Translators: This is spoken when NVDA is starting.
speech.speakMessage(_("Loading NVDA. Please wait..."))
import wx
Expand Down Expand Up @@ -673,7 +675,7 @@ def handlePowerStatusChange(self):
# initialize wxpython localization support
wxLocaleObj = wx.Locale()
wxLang = getWxLangOrNone()
if not globalVars.runningAsSource:
if not NVDAState.isRunningAsSource():
wxLocaleObj.AddCatalogLookupPathPrefix(os.path.join(globalVars.appDir, "locale"))
if wxLang:
try:
Expand Down Expand Up @@ -835,9 +837,10 @@ def _doPostNvdaStartupAction():
config.saveOnExit()

try:
if globalVars.focusObject and hasattr(globalVars.focusObject,"event_loseFocus"):
focusObject = api.getFocusObject()
if focusObject and hasattr(focusObject, "event_loseFocus"):
log.debug("calling lose focus on object with focus")
globalVars.focusObject.event_loseFocus()
focusObject.event_loseFocus()
except:
log.exception("Lose focus error")
try:
Expand Down
3 changes: 2 additions & 1 deletion source/diffHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from textInfos import TextInfo, UNIT_LINE
from threading import Lock
from typing import List
import NVDAState


class DiffAlgo(AutoPropertyObject):
Expand Down Expand Up @@ -44,7 +45,7 @@ def _initialize(self):
@note: This should be run from within the context of an acquired lock."""
if not DiffMatchPatch._proc:
log.debug("Starting diff-match-patch proxy")
if globalVars.runningAsSource:
if NVDAState.isRunningAsSource():
dmp_path = (sys.executable, os.path.join(
globalVars.appDir, "..", "include", "nvda_dmp", "nvda_dmp.py"
))
Expand Down
6 changes: 4 additions & 2 deletions source/documentationUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

import globalVars
import languageHandler
import NVDAState



def getDocFilePath(fileName, localized=True):
if not getDocFilePath.rootPath:
if globalVars.runningAsSource:
if NVDAState.isRunningAsSource():
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "..", "user_docs")
else:
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "documentation")
Expand Down Expand Up @@ -41,7 +43,7 @@ def getDocFilePath(fileName, localized=True):
return None
else:
# Not localized.
if globalVars.runningAsSource and fileName in ("copying.txt", "contributors.txt"):
if NVDAState.isRunningAsSource() and fileName in ("copying.txt", "contributors.txt"):
# If running from source, these two files are in the root dir.
return os.path.join(globalVars.appDir, "..", fileName)
else:
Expand Down
8 changes: 4 additions & 4 deletions source/easeOfAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from enum import Enum, IntEnum
from typing import Any, List

import globalVars
from logHandler import log
import NVDAState
import winreg
import winUser
import winVersion
Expand All @@ -23,13 +23,13 @@

def __getattr__(attrName: str) -> Any:
"""Module level `__getattr__` used to preserve backward compatibility."""
if attrName == "ROOT_KEY" and globalVars._allowDeprecatedAPI:
if attrName == "ROOT_KEY" and NVDAState._allowDeprecatedAPI():
log.warning("ROOT_KEY is deprecated, use RegistryKey.ROOT instead.")
return RegistryKey.ROOT.value
if attrName == "APP_KEY_PATH" and globalVars._allowDeprecatedAPI:
if attrName == "APP_KEY_PATH" and NVDAState._allowDeprecatedAPI():
log.warning("APP_KEY_PATH is deprecated, use RegistryKey.APP instead.")
return RegistryKey.APP.value
if attrName == "APP_KEY_NAME" and globalVars._allowDeprecatedAPI:
if attrName == "APP_KEY_NAME" and NVDAState._allowDeprecatedAPI():
log.warning("APP_KEY_NAME is deprecated.")
return _APP_KEY_NAME
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")
Expand Down
7 changes: 3 additions & 4 deletions source/eventHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import speech
from speech.commands import _CancellableSpeechCommand
import treeInterceptorHandler
import globalVars
import controlTypes
from logHandler import log
import globalPluginHandler
Expand Down Expand Up @@ -182,7 +181,7 @@ def __init__(self, obj, reportDevInfo: bool):

# Assumption: we only process one focus event at a time, so even if several focus events are queued,
# all focused objects will still gain this tracking attribute. Otherwise, this may need to be set via
# api.setFocusObject when globalVars.focusObject is set.
# api.setFocusObject when api.getFocusObject is set.
setattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME, True)
elif not hasattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME):
setattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME, False)
Expand Down Expand Up @@ -327,7 +326,7 @@ def doPreGainFocus(obj: "NVDAObjects.NVDAObject", sleepMode: bool = False) -> bo
# - api.getFocusAncestors() via api.setFocusObject() called in doPreGainFocus
speech._manager.removeCancelledSpeechCommands()

if globalVars.focusDifferenceLevel<=1:
if api.getFocusDifferenceLevel() <= 1:
newForeground=api.getDesktopObject().objectInForeground()
if not newForeground:
log.debugWarning("Can not get real foreground, resorting to focus ancestors")
Expand All @@ -341,7 +340,7 @@ def doPreGainFocus(obj: "NVDAObjects.NVDAObject", sleepMode: bool = False) -> bo
executeEvent('foreground', newForeground)
if sleepMode: return True
#Fire focus entered events for all new ancestors of the focus if this is a gainFocus event
for parent in globalVars.focusAncestors[globalVars.focusDifferenceLevel:]:
for parent in api.getFocusAncestors()[api.getFocusDifferenceLevel()]:
executeEvent("focusEntered",parent)
if obj.treeInterceptor is not oldTreeInterceptor:
if hasattr(oldTreeInterceptor,"event_treeInterceptor_loseFocus"):
Expand Down
Loading

0 comments on commit 52a1c6e

Please sign in to comment.